Skip to content

Commit

Permalink
Merge pull request #194 from Neurosim-lab/development
Browse files Browse the repository at this point in the history
PR from development to master - VERSION 0.6.7
  • Loading branch information
salvadord authored Feb 13, 2017
2 parents 79bc716 + 543a018 commit 8354304
Show file tree
Hide file tree
Showing 31 changed files with 1,223 additions and 290 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ umac
/examples/NeuroMLImport/LEMS_SimpleNet_pynn.py
/examples/NeuroMLImport/LEMS_SimpleNet_pynn.py_main.json
/nb-configuration.xml
/examples/sandbox/Sim_sandbox.PYR1.v.dat
/examples/sandbox/Sim_sandbox.PYR2.v.dat
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ script:
- cd ../M1
- $NEURON_HOME/bin/nrnivmodl
- python M1_run.py -nogui

# - cd ../RL_arm
# - $NEURON_HOME/bin/nrnivmodl
# - python main.py

- cd ../..
# Run all OMV tests...
- omv all -V


notifications:
Expand Down
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Version 0.6.7

- Added gridSpacing option to create populations with cells placed in grid with fixed spacing

- Added netParams functions: addCellParamsWeightNorm(), saveCellParamsRule() and loadCellParamsRule()

- Added option to importCell based on instantiated cell (not just template or class)

- Modified importCellParams to store mod mechanism global variables in cellRule['globs']

- Added support to export gap junctions to NeuroML

- Fixed bug during import that set section name to 'soma' if only 1 section


# Version 0.6.6

- Batch parameters can now include list or dict items
Expand Down
6 changes: 3 additions & 3 deletions doc/source/code/mod/ElectSyn.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ NEURON {
RANGE g, i
RANGE weight

RANGE vgap : Using a RANGE variable as opposed to POINTER for parallel mode
RANGE vpeer : Using a RANGE variable as opposed to POINTER for parallel mode


}

PARAMETER {
v (millivolt)
vgap (millivolt)
vpeer (millivolt)
g = 0.000049999999999999996 (microsiemens)
weight = 1

Expand All @@ -73,5 +73,5 @@ ASSIGNED {
}

BREAKPOINT {
i = weight * g * (v - vgap)
i = weight * g * (v - vpeer)
}
6 changes: 4 additions & 2 deletions doc/source/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,13 @@ The value consists in turn of a dictionary with the parameters of the population
* **cellType** - Arbitrary cell type attribute/tag assigned to all cells in this population; can be used as condition to apply specific cell properties.
e.g. 'Pyr' (for pyramidal neurons) or 'FS' (for fast-spiking interneurons)

* **numCells** or **density** - The total number of cells in this population or the density in neurons/mm3 (one or the other is required).
* **numCells**, **density** or **gridSpacing** - The total number of cells in this population, the density in neurons/mm3, or the fixed grid spacing (only one of the three is required).
The volume occupied by each population can be customized (see ``xRange``, ``yRange`` and ``zRange``); otherwise the full network volume will be used (defined in ``netParams``: ``sizeX``, ``sizeY``, ``sizeZ``).

``density`` can be expressed as a function of normalized location (``xnorm``, ``ynorm`` or ``znorm``), by providing a string with the variable and any common Python mathematical operators/functions. e.g. ``'1e5 * exp(-ynorm/2)'``.

``gridSpacing`` is the spacing between cells (in um). The total number of cells will be determined based on spacing and ``sizeX``, ``sizeY``, ``sizeZ``. e.g. ``10``.

* **cellModel** - Arbitrary cell model attribute/tag assigned to all cells in this population; can be used as condition to apply specific cell properties.
e.g. 'HH' (standard Hodkgin-Huxley type cell model) or 'Izhi2007' (Izhikevich 2007 point neuron model).

Expand Down Expand Up @@ -1026,7 +1028,7 @@ Population class methods
* **pop.createCellsList()**
Population class methods
Cell class methods
^^^^^^^^^^^^^^^^^^^^^^^^^^^
* **cell.create()**
Expand Down
2 changes: 1 addition & 1 deletion examples/HHTut/HHTut_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

np = HHTut.netParams
print("********************\n*\n* Note: setting noise to 1, since noise can only be 0 or 1 in NeuroML export currently!\n*\n********************")
np.popParams['background']['noise'] = 1
np.stimSourceParams['bkg']['noise'] = 1

sim.createExportNeuroML2(netParams = np,
simConfig = HHTut.simConfig,
Expand Down
2 changes: 1 addition & 1 deletion examples/HybridTut/HybridTut_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

np = HybridTut.netParams
print("********************\n*\n* Note: setting noise to 1, since noise can only be 0 or 1 in NeuroML export currently!\n*\n********************")
np.popParams['background']['noise'] = 1
np.stimSourceParams['bkg']['noise'] = 1

sim.createExportNeuroML2(netParams = np,
simConfig = HybridTut.simConfig,
Expand Down
4 changes: 2 additions & 2 deletions examples/M1/M1_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

np = M1.netParams
print("********************\n*\n* Note: setting noise to 1, since noise can only be 0 or 1 in NeuroML export currently!\n*\n********************")
np.popParams['background_E']['noise'] = 1
np.popParams['background_I']['noise'] = 1
np.stimSourceParams['background_E']['noise'] = 1
np.stimSourceParams['background_I']['noise'] = 1

sim.createExportNeuroML2(netParams = np,
simConfig = M1.simConfig,
Expand Down
57 changes: 57 additions & 0 deletions examples/batchCell/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Running batch simulations using NetPyNE

Includes two toy examples using the 6-compartment M1 Corticospinal cell.
1) f-I curve as a function of the amplitude of an IClamp and dendritic Na conductance.
2) EPSP amplitude as a function of the weight of aNetStim and the rise time of an NMDA synapse.

The code runs the required batch simulations in parallel using MPI and plots the corresponding figures.

## Requirements
- NEURON with MPI support
- NetPyNE

## Quick steps to run batch sims and plot results

1) Compile mod files:
cd mod
mkmod

2) Run batch simulations:
./runbatch [num_cores]

3) Plot results:
ipython -i analysis.py


## Code structure:

* netParams.py: Defines the network model. Includes "fixed" parameter values of cells, synapses, connections, stimulation, etc. Changes to this file should only be made for relatively stable improvements of the model. Parameter values that will be varied systematically to explore or tune the model should be included here by referencing the appropiate variable in the simulation configuration (cfg) module. Only a single netParams file is required for each batch of simulations.

* cfg.py: Simulation configuration module. Includes parameter values for each simulation run such as duration, dt, recording parameters etc. Also includes the model parameters that are being varied to explore or tune the network. When running a batch, NetPyNE will create one cfg file for each parameter configuration.

* init.py: Sequence of commands to run a single simulation. Can be executed via 'ipython init.py'. When running a batch, NetPyNE will call init.py multiple times, pass a different cfg file for each of the parameter configurations explored.

* batch.py: Defines the parameters and parameter values explored in the batch, as well as the run configuration (e.g. using MPI in a multicore machine or PBS Torque for HPCs). Includes examples of how to create 2 different batch simulations:
1) batchNa(): explore the effect of changing the amplitude of an IClamp and the dendritic Na conductance.
2) batchNMDA(): explore the effect of changing the weight of NetStim and the rise time of an NMDA synapse.

To run, add a call to either of these functions in __main__(), or import the batch module and run interactively.

To add new batch explorations, follow the format of the above example, making sure that the parameters being explored are included in cfg.py and referenced appropiately in netParams.py

* runbatch: Shell script to run the batch simulation using mpi. Alternatively, can run "manually" using:
mpiexec -np [num_cores] nrniv -python -mpi batch.py

* analysis.py: Functions to read and plot figures from the batch simulation results. Can call readPlotNa() or readPlotNMDA() from __main__() or import analysis and call interactively.

* utils.py: Support functions to read output data from batch simulations, and others. Eventually, some of these functions will be moved to NetPyNE.

* /cells: Folder containing cell model. In this case only includes SPI6.py. NetPyNE will import the cell specifications from this file.

* /data: Folder to store output of simulations.

* /mod: Folder containing mod files (need to clean up to keep just mod files required for this model)


For further information please contact: [email protected]

102 changes: 102 additions & 0 deletions examples/batchCell/analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""
analysis.py
Functions to read and plot figures from the batch simulation results.
Can call readPlotNa() or readPlotNMDA() from __main__() or import analysis and call interactively.
Contributors: [email protected]
"""

import utils
import json
import matplotlib.pyplot as plt


def plotfINa(dataFolder, batchLabel, params, data):
utils.setPlotFormat(numColors = 8)

Pvals = params[0]['values']
Ivals = params[1]['values']
Pvalsdic = {val: i for i,val in enumerate(Pvals)}
Ivalsdic = {val: i for i,val in enumerate(Ivals)}

rates = [[0 for x in range(len(Pvals))] for y in range(len(Ivals))]
for key, d in data.iteritems():
rate = len(d['simData']['spkt'])
Pindex = Pvalsdic[d['paramValues'][0]]
Iindex = Ivalsdic[d['paramValues'][1]]
rates[Iindex][Pindex] = rate
print d['paramValues']
print rate

filename = '%s/%s/%s_fIcurve.json' % (dataFolder, batchLabel, batchLabel)
with open(filename, 'w') as fileObj:
json.dump(rates, fileObj)

plt.figure()

handles = plt.plot(rates, marker='o', markersize=10)
plt.xlabel('Somatic current injection (nA)')
plt.xticks(range(len(Ivals))[::2], Ivals[::2])
plt.ylabel('Frequency (Hz)')
plt.legend(handles, params[0]['values'], title = 'dend Na', loc=2)
plt.savefig('%s/%s/%s_fIcurve.png' % (dataFolder, batchLabel, batchLabel))
plt.show()


def plotNMDA(dataFolder, batchLabel, params, data, somaLabel='soma', stimRange=[5000,10000]):
utils.setPlotFormat(numColors = 8)

Pvals = params[0]['values']
Wvals = params[1]['values']
Pvalsdic = {val: i for i,val in enumerate(Pvals)}
Wvalsdic = {val: i for i,val in enumerate(Wvals)}

epsps = [[0 for x in range(len(Pvals))] for y in range(len(Wvals))]
for key, d in data.iteritems():
cellLabel = d['simData']['V_soma'].keys()[0]
vsoma = d['simData']['V_'+somaLabel][cellLabel]
epsp = max(vsoma[stimRange[0]:stimRange[1]]) - vsoma[stimRange[0]-1]

Pindex = Pvalsdic[d['paramValues'][0]]
Windex = Wvalsdic[d['paramValues'][1]]
epsps[Windex][Pindex] = epsp
print d['paramValues']
print epsp

filename = '%s/%s/%s_epsp.json' % (dataFolder, batchLabel, batchLabel)
with open(filename, 'w') as fileObj:
json.dump(epsps, fileObj)

plt.figure()

handles = plt.plot(epsps, marker='o', markersize=10)
plt.xlabel('Weight (of NetStim connection)')
plt.ylabel('Somatic EPSP amplitude (mV) in response to 1 NetStim spike')
plt.xticks(range(len(Wvals))[::2], Wvals[::2])
plt.legend(handles, params[0]['values'], title = 'NMDA tau1 (ms)', loc=2)
plt.savefig('%s/%s/%s_epsp.png' % (dataFolder, batchLabel, batchLabel))
plt.show()


def readPlotNa():
dataFolder = 'data/'
batchLabel = 'batchNa'

params, data = utils.readBatchData(dataFolder, batchLabel, loadAll=0, saveAll=1, vars=None, maxCombs=None)
plotfINa(dataFolder, batchLabel, params, data)


def readPlotNMDA():
dataFolder = 'data/'
batchLabel = 'batchNMDA'

params, data = utils.readBatchData(dataFolder, batchLabel, loadAll=0, saveAll=1, vars=None, maxCombs=None)
plotNMDA(dataFolder, batchLabel, params, data)


# Main code
if __name__ == '__main__':
readPlotNa()
# readPlotNMDA()

50 changes: 50 additions & 0 deletions examples/batchCell/batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
batch.py
Batch simulation for M1 model using NetPyNE
Contributors: [email protected]
"""

from netpyne.batch import Batch
import numpy as np


def createBatch(params):
# Create Batch object
b = Batch()
for k,v in params.iteritems():
b.params.append({'label': k, 'values': v})
return b


def runBatch(b, label):
b.batchLabel = label
b.saveFolder = 'data/'+b.batchLabel
b.method = 'grid'
b.runCfg = {'type': 'mpi',
'script': 'init.py',
'skip': True}

b.run() # run batch


def batchNa():
b = createBatch({'dendNa': [0.025, 0.03, 0.035, 0.4],
('IClamp1', 'amp'): list(np.arange(-2.0, 8.0, 0.5)/10.0)})
runBatch(b, 'batchNa')


def batchNMDA():
b = createBatch({'tau1NMDA': [10, 15, 20, 25],
('NetStim1', 'weight'): list(np.arange(1.0, 10.0, 1.0)/1e4)})
runBatch(b, 'batchNMDA')


# Main code
if __name__ == '__main__':
batchNa()
# batchNMDA()



1 change: 1 addition & 0 deletions examples/batchCell/cells/SPI6.py
Loading

0 comments on commit 8354304

Please sign in to comment.