Skip to content

Commit

Permalink
Made updates based on running examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Patrick committed Oct 29, 2021
1 parent 1dd834f commit e7a1a3f
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 2 deletions.
8 changes: 6 additions & 2 deletions netpyne/sim/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from neuron import h # Import NEURON
from .. import specs
from ..specs import Dict, ODict
from . import utils
from . import utils, validator
try:
from datetime import datetime
except:
Expand Down Expand Up @@ -51,7 +51,6 @@ def initialize(netParams = None, simConfig = None, net = None):
"""


from .. import sim

if netParams is None: netParams = {} # If not specified, initialize as empty dict
Expand All @@ -60,6 +59,11 @@ def initialize(netParams = None, simConfig = None, net = None):
print('Error: seems like the sim.initialize() arguments are in the wrong order, try initialize(netParams, simConfig)')
sys.exit()

if validator.validate_netparams(netParams):
print('Good to go')
else:
print('Bad parameters')

# for testing validation
# if simConfig.exitOnError:
#sys.exit()
Expand Down
166 changes: 166 additions & 0 deletions netpyne/sim/validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
from schema import Schema, Optional, And, Or, Use
from collections import ChainMap

cell_spec = {
str: {
'secs': {
# Optional(And(str, Use(str.lower), lambda s: s in ['soma', 'dend'])): {
Optional(str): {
Optional('geom'): {
Optional('L'): Or(int, float),
Optional('Ra'): Or(int, float),
Optional('diam'): Or(int, float),
Optional('cm'): Or(int, float),
Optional('pt3d'): And([(float, float, float, float)],
lambda t: len(list(filter(lambda x: len(x) != 4, t))) == 0),
Optional('nseg'): Or(int, float)
},
Optional('mechs'): {
And(str, Use(str.lower), lambda s: s in ['hh', 'pas']): {
Optional('el'): int,
Optional('gkbar'): float,
Optional('gl'): float,
Optional('gnabar'): float,
Optional('g'): float,
Optional('e'): Or(int, float),
},
Optional('Nafbwb'): {},
Optional('Kdrbwb'): {},
Optional('Caolmw'): {},
Optional('Iholmw'): {},
Optional('ICaolmw'): {},
Optional('KCaolmw'): {},
Optional('nacurrent'): {
Optional('ki'): Or(int,float)
},
Optional('kacurrent'): {},
Optional('kdrcurrent'): {},
Optional('hcurrent'): {}
},
Optional('topol'): {
Optional('parentSec'): And(str, Use(str.lower), lambda s: s in ['soma', 'dend']),
Optional('childX'): Or(int, float),
Optional('parentX'): Or(int, float)
},
Optional('pointps'): {
str: {
'mod': str,
'C': Or(int, float),
'k': Or(int, float),
'vr': Or(int, float),
'vt': Or(int, float),
'vpeak': Or(int, float),
'a': Or(int, float),
'b': Or(int, float),
'c': Or(int, float),
'd': Or(int, float),
'celltype': int
}
},
Optional('vinit'): Or(int, float)
}
}
}
}

population_spec = {
str: {
'cellType': str,
'numCells': int,
Optional('yRange'): [int],
Optional('ynormRange'): [float],
Optional('cellModel'): str
}
}


synaptic_spec = {
str: {
'mod': And(str, Use(str.lower), lambda s: s in ['exp2syn']),
'tau1': Or(int, float),
'tau2': Or(int, float),
'e': Or(int, float)
}
}


stimulation_source_spec = {
str: {
Optional('type'): And(str, Use(str.lower), lambda s: s in ['iclamp', 'vclamp', 'alphasynapse', 'netstim']),
Optional('rate'): int,
Optional('noise'): float,
Optional('del'): int,
Optional('dur'): Or(int, [int]),
Optional('amp'): Or(str, [int]),
Optional('gain'): float,
Optional('tau1'): Or(int, float),
Optional('tau2'): Or(int, float),
Optional('rstim'): Or(int, float),
Optional('e'): Or(int, float),
Optional('gmax'): str,
Optional('onset'): str,
Optional('tau'): Or(int, float),
Optional('interval'): str,
Optional('start'): Or(int, float)
}
}


stimulation_target_spec = {
str: {
Optional('source'): str,
Optional('conds'): {
Optional('cellType'): Or(str, [str]),
Optional('cellList'): [Or(int, float)],
Optional('pop'): str,
Optional('ynorm'): [Or(int, float)]
},
Optional('weight'): Or(float, str), # The string is for capturing functions. May want to validate it's valid python
Optional('delay'): Or(int, str), # The string is for capturing functions. May want to validate it's valid python
Optional('synMech'): str,
Optional('loc'): float,
Optional('sec'): str
}
}


connection_spec = {
str: {
Optional('preConds'): {
Optional('pop'): Or(str, [str]),
Optional('y'): [Or(int, float)],
Optional('cellType'): str
},
Optional('postConds'): {
Optional('pop'): Or(str, [str]),
Optional('y'): [Or(int, float)],
Optional('cellType'): str
},
Optional(And(str, Use(str.lower), lambda s: s in ['probability', 'convergence', 'divergence'])): Or(float, str),
Optional('weight'): Or(float, str), # The string is for capturing functions. May want to validate it's valid python
Optional('delay'): Or(int, str), # The string is for capturing functions. May want to validate it's valid python
Optional('synMech'): str,
Optional('loc'): float,
Optional('sec'): And(str, Use(str.lower), lambda s: s in ['dend'])
}
}


cell_schema = Schema(cell_spec)
population_schema = Schema(population_spec)
synaptic_schema = Schema(synaptic_spec)
stimulation_source_schema = Schema(stimulation_source_spec)
stimulation_target_schema = Schema(stimulation_target_spec)
connection_schema = Schema(connection_spec)

# Attempt to merge schemas -- This doesn't work yet so we'll check the pieces one by one
net_param_schema = Schema(dict(ChainMap(*[cell_spec, population_spec, synaptic_spec, stimulation_source_spec,
stimulation_target_spec, connection_spec])))


def validate_netparams(net_params):
return cell_schema.validate(net_params.cellParams) and \
population_schema.validate(net_params.popParams) and \
synaptic_schema.validate(net_params.synMechParams) and \
stimulation_source_schema.validate(net_params.stimSourceParams) and \
stimulation_target_schema.validate(net_params.stimTargetParams)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ bokeh
pyneuroml
neuron
pytest
schema

0 comments on commit e7a1a3f

Please sign in to comment.