Skip to content

Commit 63a684d

Browse files
committed
nepyne-193 Add first version of model validation
1 parent 1119234 commit 63a684d

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

netpyne_ui/netpyne_geppetto.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
os.chdir(constants.NETPYNE_WORKDIR_PATH)
4848

4949

50+
class NepyneValidationError(Exception):
51+
...
52+
53+
5054
class NetPyNEGeppetto:
5155

5256
def __init__(self):
@@ -256,6 +260,24 @@ def simulate_single_model(self, experiment: model.Experiment = None, use_prev_in
256260
response = json.loads(GeppettoModelSerializer.serialize(self.geppetto_model))
257261
return response
258262

263+
def validate_netParams(self):
264+
_, failed = sim.validator.validateNetParams(self.netParams)
265+
if failed:
266+
message = "One or more components in your model have issues, see details below:\n"
267+
components_error = {}
268+
for entry in failed:
269+
components_error.setdefault(entry.component, []).append((entry.keyPath, entry.summary))
270+
for component, details in components_error.items():
271+
message = message + f" * Error validating {component}\n"
272+
for (keyPath, summary) in details:
273+
path = ' -> '.join(f"{key!r}" for key in keyPath)
274+
message = message + f" Error in {path}\n"
275+
for line in summary:
276+
message = message + f" {line}\n"
277+
message = message + "\n"
278+
raise NepyneValidationError(message)
279+
280+
259281
def simulateNetPyNEModelInGeppetto(self, args):
260282
""" Starts simulation of the currently loaded NetPyNe model.
261283
@@ -270,8 +292,9 @@ def simulateNetPyNEModelInGeppetto(self, args):
270292
allTrials = args.get('allTrials', True)
271293
use_prev_inst = args.get('usePrevInst', False)
272294
sim_id = args.get('simId', 0)
273-
274295
try:
296+
self.validate_netParams()
297+
275298
experiment = experiments.get_current()
276299
if experiment:
277300
if self.experiments.any_in_state([model.ExperimentState.PENDING, model.ExperimentState.SIMULATING]):

0 commit comments

Comments
 (0)