diff --git a/examples/sonatatest/SimSonataExample.json b/examples/sonatatest/SimSonataExample.json index ecac3c6..844b2a3 100644 --- a/examples/sonatatest/SimSonataExample.json +++ b/examples/sonatatest/SimSonataExample.json @@ -1,13 +1,13 @@ { "SimSonataExample": { - "version": "NeuroMLlite v0.1.9", - "network": "SonataExample.json", - "duration": 1000.0, - "dt": 0.01, - "recordTraces": { + "version": "NeuroMLlite v0.5.8", + "network": "SonataExample.json", + "duration": 1000.0, + "dt": 0.01, + "record_traces": { "all": "*" - }, - "recordSpikes": { + }, + "record_spikes": { "pop0": "*" } } diff --git a/examples/sonatatest/SonataExample.json b/examples/sonatatest/SonataExample.json index fdffef3..4e877db 100644 --- a/examples/sonatatest/SonataExample.json +++ b/examples/sonatatest/SonataExample.json @@ -1,74 +1,64 @@ { "SonataExample": { - "version": "NeuroMLlite v0.1.9", + "version": "NeuroMLlite v0.5.8", + "notes": "Example for testing Sonata", "parameters": { - "input_del": 100, - "input_dur": 800, - "input_amp": 0.19 - }, - "notes": "Example for testing Sonata", - "cells": [ - { - "testcell": { - "pynn_cell": "IF_cond_alpha", - "parameters": { - "tau_refrac": 3, - "tau_m": 22.1, - "i_offset": 0, - "cm": 0.117, - "v_thresh": -47, - "v_rest": -78, - "v_reset": -50 - } - } + "input_amp": 0.19, + "input_del": 100, + "input_dur": 800 + }, + "cells": { + "testcell": { + "parameters": { + "i_offset": 0, + "cm": 0.117, + "tau_m": 22.1, + "tau_refrac": 3, + "v_reset": -50, + "v_rest": -78, + "v_thresh": -47 + }, + "pynn_cell": "IF_cond_alpha" } - ], - "input_sources": [ - { - "i_clamp": { - "pynn_input": "DCSource", - "parameters": { - "start": "input_del", - "stop": "input_del+input_dur", - "amplitude": "input_amp" - } - } + }, + "input_sources": { + "i_clamp": { + "parameters": { + "amplitude": "input_amp", + "start": "input_del", + "stop": "input_del+input_dur" + }, + "pynn_input": "DCSource" } - ], - "regions": [ - { - "region1": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - "width": 1000.0, - "height": 100.0, - "depth": 1000.0 - } + }, + "regions": { + "region1": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "width": 1000.0, + "height": 100.0, + "depth": 1000.0 } - ], - "populations": [ - { - "pop0": { - "size": 2, - "component": "testcell", - "properties": { - "color": "1 0 0" - }, - "random_layout": { - "region": "region1" - } + }, + "populations": { + "pop0": { + "size": 2, + "component": "testcell", + "properties": { + "color": "1 0 0" + }, + "random_layout": { + "region": "region1" } } - ], - "inputs": [ - { - "stim": { - "input_source": "i_clamp", - "population": "pop0", - "percentage": 50.0 - } + }, + "inputs": { + "stim": { + "input_source": "i_clamp", + "population": "pop0", + "percentage": 50 } - ] + } } } \ No newline at end of file diff --git a/examples/sonatatest/SonataExample.py b/examples/sonatatest/SonataExample.py index 7c74bae..cd42d3d 100644 --- a/examples/sonatatest/SonataExample.py +++ b/examples/sonatatest/SonataExample.py @@ -106,8 +106,8 @@ network=new_file, duration="1000", dt="0.01", - recordTraces={"all": "*"}, - recordSpikes={"pop0": "*"}, + record_traces={"all": "*"}, + record_spikes={"pop0": "*"}, ) sim.to_json_file() diff --git a/examples/sonatatest/circuit_config.json b/examples/sonatatest/circuit_config.json index 787cd75..1731543 100644 --- a/examples/sonatatest/circuit_config.json +++ b/examples/sonatatest/circuit_config.json @@ -1,18 +1,18 @@ { + "manifest": { + "$NETWORK_DIR": "./network", + "$COMPONENT_DIR": "./components" + }, + "components": { + "synaptic_models_dir": "$COMPONENT_DIR/synaptic_models", + "point_neuron_models_dir": "$COMPONENT_DIR/point_neuron_models_dir" + }, "networks": { "nodes": [ { - "node_types_file": "$NETWORK_DIR/SonataExample_node_types.csv", - "nodes_file": "$NETWORK_DIR/SonataExample_nodes.sonata.h5" + "nodes_file": "$NETWORK_DIR/SonataExample_nodes.sonata.h5", + "node_types_file": "$NETWORK_DIR/SonataExample_node_types.csv" } ] - }, - "components": { - "point_neuron_models_dir": "$COMPONENT_DIR/point_neuron_models_dir", - "synaptic_models_dir": "$COMPONENT_DIR/synaptic_models" - }, - "manifest": { - "$NETWORK_DIR": "./network", - "$COMPONENT_DIR": "./components" } } \ No newline at end of file diff --git a/examples/sonatatest/components/point_neuron_models_dir/testcell.json b/examples/sonatatest/components/point_neuron_models_dir/testcell.json index 894d196..c9ffe0b 100644 --- a/examples/sonatatest/components/point_neuron_models_dir/testcell.json +++ b/examples/sonatatest/components/point_neuron_models_dir/testcell.json @@ -1,9 +1,9 @@ { - "tau_m": 22.1, - "V_th": -47.0, - "I_e": 0.0, - "C_m": 117.0, - "V_reset": -50.0, - "t_ref": 3.0, - "E_L": -78.0 + "E_L": -78.0, + "C_m": 117.0, + "tau_m": 22.1, + "t_ref": 3.0, + "V_th": -47.0, + "V_reset": -50.0, + "I_e": 0.0 } \ No newline at end of file diff --git a/examples/sonatatest/config.json b/examples/sonatatest/config.json index 0a8af5b..9591b8f 100644 --- a/examples/sonatatest/config.json +++ b/examples/sonatatest/config.json @@ -1,4 +1,4 @@ { - "network": "./circuit_config.json", + "network": "./circuit_config.json", "simulation": "./simulation_config.json" } \ No newline at end of file diff --git a/examples/sonatatest/network/SonataExample_node_types.csv b/examples/sonatatest/network/SonataExample_node_types.csv index 8d048ed..7e6a49c 100644 --- a/examples/sonatatest/network/SonataExample_node_types.csv +++ b/examples/sonatatest/network/SonataExample_node_types.csv @@ -1,2 +1,2 @@ -node_type_id dynamics_params pop_name model_template model_type model_name -100 testcell.json pop0 nest:iaf_psc_alpha point_process testcell +node_type_id pop_name model_name model_template model_type dynamics_params +100 pop0 testcell nest:iaf_psc_alpha point_process testcell.json diff --git a/examples/sonatatest/network/SonataExample_nodes.sonata.h5 b/examples/sonatatest/network/SonataExample_nodes.sonata.h5 index 5851662..6a720e3 100644 Binary files a/examples/sonatatest/network/SonataExample_nodes.sonata.h5 and b/examples/sonatatest/network/SonataExample_nodes.sonata.h5 differ diff --git a/examples/sonatatest/regenerateAndTest.sh b/examples/sonatatest/regenerateAndTest.sh new file mode 100755 index 0000000..46aee6f --- /dev/null +++ b/examples/sonatatest/regenerateAndTest.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -ex + +python SonataExample.py -sonata + +python run_bmtk.py + +./run_pynml.jnml.sh diff --git a/examples/sonatatest/run_bmtk.py b/examples/sonatatest/run_bmtk.py index 193efbc..17006e5 100644 --- a/examples/sonatatest/run_bmtk.py +++ b/examples/sonatatest/run_bmtk.py @@ -14,7 +14,6 @@ def run(config_file, simulator): elif simulator == "NEST": from bmtk.simulator import pointnet - conf = pointnet.Config.from_json(config_file) conf.build_env() net = pointnet.PointNetwork.from_config(conf) @@ -24,4 +23,4 @@ def run(config_file, simulator): if __name__ == "__main__": - run("config.json", "NEST") + run("config.json", "NEST") \ No newline at end of file diff --git a/examples/sonatatest/run_pynml.jnml.sh b/examples/sonatatest/run_pynml.jnml.sh index 107ec4d..11f2c71 100755 --- a/examples/sonatatest/run_pynml.jnml.sh +++ b/examples/sonatatest/run_pynml.jnml.sh @@ -1,5 +1,4 @@ #!/bin/bash - -set -e +set -ex pynml-sonata Back2NML config.json -jnml diff --git a/examples/sonatatest/simulation_config.json b/examples/sonatatest/simulation_config.json index 152701c..60a2295 100644 --- a/examples/sonatatest/simulation_config.json +++ b/examples/sonatatest/simulation_config.json @@ -1,45 +1,45 @@ { - "inputs": { - "stim": { - "input_type": "current_clamp", - "node_set": "inputset_stim_i_clamp", - "module": "IClamp", - "delay": 100.0, - "duration": 800.0, - "amp": 190.00000000000003 - } - }, - "target_simulator": "NEST", - "reports": { - "membrane_potential": { - "enabled": true, - "cells": "point_nodes", - "sections": "soma", - "module": "multimeter_report", - "variable_name": "V_m" - } - }, - "manifest": { - "$OUTPUT_DIR": "./output", - "$INPUT_DIR": "./" - }, "run": { - "tstop": 1000.0, + "tstop": 1000.0, "dt": 0.01 - }, + }, + "target_simulator": "NEST", + "manifest": { + "$OUTPUT_DIR": "./output", + "$INPUT_DIR": "./" + }, + "output": { + "output_dir": "$OUTPUT_DIR", + "log_file": "log.txt", + "spikes_file": "spikes.h5", + "spikes_sort_order": "time" + }, "node_sets": { "point_nodes": { "model_type": "point_process" - }, + }, "inputset_stim_i_clamp": { - "model_type": "point_process", + "model_type": "point_process", "population": "pop0" } - }, - "output": { - "spikes_sort_order": "time", - "spikes_file": "spikes.h5", - "log_file": "log.txt", - "output_dir": "$OUTPUT_DIR" + }, + "reports": { + "membrane_potential": { + "cells": "point_nodes", + "variable_name": "V_m", + "module": "multimeter_report", + "sections": "soma", + "enabled": true + } + }, + "inputs": { + "stim": { + "input_type": "current_clamp", + "module": "IClamp", + "amp": 190.00000000000003, + "delay": 100.0, + "duration": 800.0, + "node_set": "inputset_stim_i_clamp" + } } } \ No newline at end of file diff --git a/neuromllite/MDFHandler.py b/neuromllite/MDFHandler.py index b6bb48e..84295e5 100644 --- a/neuromllite/MDFHandler.py +++ b/neuromllite/MDFHandler.py @@ -409,7 +409,7 @@ def _comp_to_mdf_node(self, nmllite_comp, lems_comp_id, size=1, properties=None) # node["parameters"][sv.name]["value"] = [0]*size node["output_ports"][sv.name] = {"value": sv.name} - print_v("Adding %s as an output port"%sv.name) + print_v("Adding %s as an output port" % sv.name) if sv.exposure: node["output_ports"][sv.exposure] = {"value": sv.name} diff --git a/neuromllite/NetworkGenerator.py b/neuromllite/NetworkGenerator.py index f057388..0e2182c 100644 --- a/neuromllite/NetworkGenerator.py +++ b/neuromllite/NetworkGenerator.py @@ -410,7 +410,9 @@ def generate_network( if input.weight else 1 ) - if flip * 100.0 < evaluate(input.percentage, nl_model.parameters, rng): + if flip * 100.0 < evaluate( + input.percentage, nl_model.parameters, rng + ): if input.number_per_cell and input.segment_ids: raise Exception( "On input: %s, only one of number_per_cell or segment_ids is allowed" @@ -1282,33 +1284,30 @@ def generate_value_array(node, index, context='{0}', param='value'): run_bmtk_template = """#!/bin/env python - import sys - - def run(config_file, simulator): +import sys - if simulator=='NEURON': - from bmtk.simulator import bionet - conf = bionet.Config.from_json(config_file, validate=True) - conf.build_env() - net = bionet.BioNetwork.from_config(conf) - sim = bionet.BioSimulator.from_config(conf, network=net) +def run(config_file, simulator): + if simulator == "NEURON": + from bmtk.simulator import bionet - elif simulator=='NEST': - from bmtk.simulator import pointnet - conf = pointnet.Config.from_json(config_file) - conf.build_env() - net = pointnet.PointNetwork.from_config(conf) - sim = pointnet.PointSimulator.from_config(conf, net) + conf = bionet.Config.from_json(config_file, validate=True) + conf.build_env() + net = bionet.BioNetwork.from_config(conf) + sim = bionet.BioSimulator.from_config(conf, network=net) - sim.run() + elif simulator == "NEST": + from bmtk.simulator import pointnet + conf = pointnet.Config.from_json(config_file) + conf.build_env() + net = pointnet.PointNetwork.from_config(conf) + sim = pointnet.PointSimulator.from_config(conf, net) + sim.run() - if __name__ == '__main__': - run('config.json', '%s') - - """ +if __name__ == "__main__": + run("config.json", "%s")""" run_bmtk_file = open("run_bmtk.py", "w") run_bmtk_file.write(run_bmtk_template % (target_simulator)) diff --git a/neuromllite/utils.py b/neuromllite/utils.py index 86c67e6..a5d030d 100644 --- a/neuromllite/utils.py +++ b/neuromllite/utils.py @@ -80,6 +80,7 @@ def load_network_yaml(filename): return net + def load_simulation(filename): """ Load a NeuroMLlite simulation JSON/YAML file @@ -89,6 +90,7 @@ def load_simulation(filename): else: return load_simulation_json(filename) + def load_simulation_json(filename: str) -> Optional[dict]: """ Load a NeuroMLlite simulation JSON file