Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test suite & minor updates to examples & updates to 300_pointneuron example #100

Merged
merged 18 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,27 @@ examples/**/output/config.json
.cache
**/mechanisms/x86_64
.ipynb_checkpoints/
/examples/sim_tests/intfire/*/test/x86_64
/examples/sim_tests/intfire/*/test/LEMS*.xml
/examples/sim_tests/intfire/*/test/*.dat
/examples/sim_tests/intfire/*/test/report*txt
/examples/sim_tests/intfire/*/test/*spikes
/examples/sim_tests/intfire/*/test/*.net.nml
/examples/sim_tests/intfire/*/test/*_nrn.py
/examples/sim_tests/intfire/*/test/*.mod
/examples/sim_tests/intfire/*/test/output/*h5
/examples/sim_tests/intfire/*/test/output/log.txt
/examples/sim_tests/intfire/*/test/output/*dat
/examples/checkouth5.sh
/examples/300_pointneurons/*.mod
/examples/300_pointneurons/LEMS_Sim_sim.xml
/examples/300_pointneurons/*_nrn.py
/examples/300_pointneurons/*spikes
/examples/300_pointneurons/output/*.dat
/examples/300_pointneurons/report.txt
/examples/300_pointneurons/*.dat
/examples/300_pointneurons/x86_64
/examples/300_pointneurons/comparison_V_m.png
/examples/300_pointneurons/sim.net.nml
/examples/300_pointneurons/output/membrane_potential.h5
/examples/300_pointneurons/output/spikes.h5
12 changes: 12 additions & 0 deletions examples/300_cells/analyze_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import sys
from bmtk.analyzer.visualization.spikes import plot_spikes


sys.path.append("../sim_tests/shared_components/scripts")

from analyze_output_utils import plot_data

if __name__ == '__main__':

plot_data('output/membrane_potential.h5', 'mV', 'Membrane Potential', show_already=True, max_num_traces=12)
plot_spikes('network/internal_nodes.h5', 'network/internal_node_types.csv', 'output/spikes.h5', group_key='model_name')
15 changes: 15 additions & 0 deletions examples/300_cells/plot_spikes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from bmtk.analyzer.visualization.spikes import plot_spikes
import sys

title = None
if len(sys.argv)>1:
title = 'Simulator: %s'%sys.argv[1]

# Note: depends on https://github.com/AllenInstitute/bmtk/pull/73
plot_spikes('network/internal_nodes.h5',
'network/internal_node_types.csv',
'output/spikes.h5',
group_key='model_name',
legend=False,
title=title,
font_size=13)
2 changes: 1 addition & 1 deletion examples/300_cells/simulation_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"v_init": -80
},

"node_sets_file": "node_sets.json",
"node_sets_file": "$BASE_DIR/node_sets.json",

"inputs": {
"external_spike_trains": {
Expand Down
2 changes: 1 addition & 1 deletion examples/300_intfire/network/tw_node_types.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_type_id model_type ei location model_name
node_type_id model_type ei model_name location
100 virtual e TW TW
6 changes: 3 additions & 3 deletions examples/300_intfire/network/v1_node_types.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_type_id ei model_name location model_template model_type dynamics_params
100 e LIF_exc VisL4 nrn:IntFire1 point_process IntFire1_exc_1.json
101 i LIF_inh VisL4 nrn:IntFire1 point_process IntFire1_inh_1.json
node_type_id ei location model_template model_type dynamics_params model_name
100 e VisL4 nrn:IntFire1 point_process IntFire1_exc_1.json LIF_exc
101 i VisL4 nrn:IntFire1 point_process IntFire1_inh_1.json LIF_inh
7 changes: 4 additions & 3 deletions examples/300_intfire/simulation_config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"manifest": {
"$OUTPUT_DIR": "./output",
"$INPUT_DIR": "./inputs",
"$BASE_DIR": ".",
"$OUTPUT_DIR": "$BASE_DIR/output",
"$INPUT_DIR": "$BASE_DIR/inputs",
"$COMPONENT_DIR": "../shared_components"
},

Expand All @@ -16,7 +17,7 @@

"target_simulator":"NEURON",

"node_sets_file": "node_sets.json",
"node_sets_file": "$BASE_DIR/node_sets.json",

"conditions": {
"celsius": 34.0,
Expand Down
7 changes: 7 additions & 0 deletions examples/300_intfire/test_pynn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pyNN.serialization import import_from_sonata, load_sonata_simulation_plan
import pyNN.neuron as sim

simulation_plan = load_sonata_simulation_plan("simulation_config.json")
simulation_plan.setup(sim)
net = import_from_sonata("circuit_config.json", sim)
simulation_plan.execute(net)
8 changes: 2 additions & 6 deletions examples/300_pointneurons/build_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,14 @@ def n_connections(src, trg, prob=0.5, min_syns=2, max_syns=7):
cm = external.add_edges(target=internal.nodes(ei='e'), source=external.nodes(),
connection_rule=lambda *_: np.random.binomial(1, .7),
dynamics_params='ExcToExc.json',
model_template='static_synapse',
# syn_weight=50.0,
delay=2.0)
model_template='static_synapse')
cm.add_properties('syn_weight', rule=50.0, dtypes=np.float)


cm = external.add_edges(target=internal.nodes(ei='i'), source=external.nodes(),
connection_rule=lambda *_: np.random.binomial(1, .7),
dynamics_params='ExcToInh.json',
model_template='static_synapse',
# syn_weight=75.0,
delay=2.0)
model_template='static_synapse')
cm.add_properties('syn_weight', rule=65.0, dtypes=np.float)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
edge_type_id target_query source_query delay dynamics_params model_template
100 ei=='e' * 2.0 ExcToExc.json nest:static_synapse
101 ei=='i' * 2.0 ExcToInh.json nest:static_synapse
edge_type_id target_query source_query dynamics_params model_template
100 ei=='e' * ExcToExc.json static_synapse
101 ei=='i' * ExcToInh.json static_synapse
Binary file modified examples/300_pointneurons/network/external_internal_edges.h5
Binary file not shown.
Binary file modified examples/300_pointneurons/network/external_nodes.h5
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
edge_type_id target_query source_query delay dynamics_params model_template
100 ei=='e' ei=='e' 2.0 ExcToExc.json nest:static_synapse
101 ei=='i' ei=='e' 2.0 ExcToInh.json nest:static_synapse
102 ei=='e' ei=='i' 2.0 InhToExc.json nest:static_synapse
103 ei=='i' ei=='i' 2.0 InhToInh.json nest:static_synapse
100 ei=='e' ei=='e' 2.0 ExcToExc.json static_synapse
101 ei=='i' ei=='e' 2.0 ExcToInh.json static_synapse
102 ei=='e' ei=='i' 2.0 InhToExc.json static_synapse
103 ei=='i' ei=='i' 2.0 InhToInh.json static_synapse
Binary file modified examples/300_pointneurons/network/internal_internal_edges.h5
Binary file not shown.
Binary file modified examples/300_pointneurons/network/internal_nodes.h5
Binary file not shown.
Binary file not shown.
Binary file removed examples/300_pointneurons/output/spikes.h5
Binary file not shown.
15 changes: 14 additions & 1 deletion examples/300_pointneurons/plot_potential.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def plot_vars(file_names, cell_var='v', gid_list=[], t_min=None, t_max=None):
for fn in file_names:
try:
cell_var_files.append(CellVarsFile(fn, h5_root="/report/internal"))
except KeyError:
except KeyError as e:
print('Exception: %s'%e)
cell_var_files.append(CellVarsFile(fn))

# get first spike file and properties
Expand All @@ -47,6 +48,14 @@ def plot_vars(file_names, cell_var='v', gid_list=[], t_min=None, t_max=None):
for i, cvf in enumerate(cell_var_files):
# plot all traces
ax[subplot].plot(cvf.time_trace, cvf.data(gid, cell_var), label=file_names[i])
time_steps = cvf.time_trace
data = cvf.data(gid, cell_var)
fn = 'output/gid_%s.dat'%gid
f = open(fn,'w')
print('Writing %i points to %s'%(len(time_steps), fn))
for ti in range(len(time_steps)):
f.write('%s\t%s\n'%(time_steps[ti]/1000,data[ti]/1000))
f.close()

ax[subplot].yaxis.set_label_position("right")
ax[subplot].set_ylabel('gid {}'.format(gid), fontsize='xx-small')
Expand All @@ -58,6 +67,10 @@ def plot_vars(file_names, cell_var='v', gid_list=[], t_min=None, t_max=None):
# Use the last plot to get the legend
handles, labels = ax[subplot].get_legend_handles_labels()
fig.legend(handles, labels, loc='upper right')

for cvf in cell_var_files:
# Note: depends on: https://github.com/AllenInstitute/bmtk/pull/73
cvf.close()

plt.show()

Expand Down
14 changes: 13 additions & 1 deletion examples/300_pointneurons/plot_spikes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
from bmtk.analyzer.visualization.spikes import plot_spikes
import sys

plot_spikes('network/internal_nodes.h5', 'network/internal_node_types.csv', 'output/spikes.h5', group_key='model_name')
title = None
if len(sys.argv)>1:
title = 'Simulator: %s'%sys.argv[1]

# Note: depends on https://github.com/AllenInstitute/bmtk/pull/73
plot_spikes('network/internal_nodes.h5',
'network/internal_node_types.csv',
'output/spikes.h5',
group_key='model_name',
legend=False,
title=title,
font_size=13)
2 changes: 1 addition & 1 deletion examples/300_pointneurons/run_PyNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
simulation_plan = load_sonata_simulation_plan("simulation_config.json")
simulation_plan.setup(sim)
net = import_from_sonata("circuit_config.json", sim)
simulation_plan.execute(net)
simulation_plan.execute(net)
5 changes: 5 additions & 0 deletions examples/300_pointneurons/run_pynml.jnmlnrn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

pynml-sonata sim config.json -neuron
4 changes: 2 additions & 2 deletions examples/300_pointneurons/simulation_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"run": {
"tstop": 1500.0,
"dt": 0.001,
"dt": 0.01,
"nsteps_block": 5000
},

Expand All @@ -20,7 +20,7 @@
"v_init": -80
},

"node_sets_file": "node_sets.json",
"node_sets_file": "$BASE_DIR/node_sets.json",

"inputs": {
"external_spike_trains": {
Expand Down
12 changes: 6 additions & 6 deletions examples/5_cells_iclamp/network/biophysical_node_types.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node_type_id model_processing model_type model_template morphology ei model_name
104 aibs_perisomatic biophysical nml:Cell_473862421.cell.nml Pvalb_469628681_m i PV2
100 aibs_perisomatic biophysical nml:Cell_472363762.cell.nml Scnn1a_473845048_m e Scnn1a
101 aibs_perisomatic biophysical nml:Cell_473863510.cell.nml Rorb_325404214_m e Rorb
102 aibs_perisomatic biophysical nml:Cell_473863035.cell.nml Nr5a1_471087815_m e Nr5a1
103 aibs_perisomatic biophysical nml:Cell_472912177.cell.nml Pvalb_470522102_m i PV1
node_type_id ei model_processing morphology model_template model_type model_name
104 i aibs_perisomatic Pvalb_469628681_m nml:Cell_473862421.cell.nml biophysical PV2
100 e aibs_perisomatic Scnn1a_473845048_m nml:Cell_472363762.cell.nml biophysical Scnn1a
101 e aibs_perisomatic Rorb_325404214_m nml:Cell_473863510.cell.nml biophysical Rorb
102 e aibs_perisomatic Nr5a1_471087815_m nml:Cell_473863035.cell.nml biophysical Nr5a1
103 i aibs_perisomatic Pvalb_470522102_m nml:Cell_472912177.cell.nml biophysical PV1
2 changes: 1 addition & 1 deletion examples/5_cells_iclamp/simulation_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"v_init": -80
},

"node_sets_file": "node_sets.json",
"node_sets_file": "$BASE_DIR/node_sets.json",

"inputs": {
"current_clamp_1": {
Expand Down
8 changes: 4 additions & 4 deletions examples/9_cells/network/cortex_node_types.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_type_id ei model_processing model_type model_template morphology dynamics_params model_name
100 e aibs_perisomatic biophysical nml:nml/Cell_472363762.cell.nml Scnn1a_473845048_m NONE Scnn1a
101 e aibs_perisomatic biophysical nml:nml/Cell_473863510.cell.nml Rorb_325404214_m NONE Rorb
102 e aibs_perisomatic biophysical nml:nml/Cell_473863035.cell.nml Nr5a1_471087815_m NONE Nr5a1
node_type_id ei model_processing model_type model_template morphology dynamics_params model_name
100 e aibs_perisomatic biophysical nml:nml/Cell_472363762.cell.nml Scnn1a_473845048_m NONE Scnn1a
101 e aibs_perisomatic biophysical nml:nml/Cell_473863510.cell.nml Rorb_325404214_m NONE Rorb
102 e aibs_perisomatic biophysical nml:nml/Cell_473863035.cell.nml Nr5a1_471087815_m NONE Nr5a1
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/env python

# Sonata Simulator Test Suite
# 1-cell circuit, integrate and fire cell, current clamp input

# Authors: Padraig Gleeson @ UCL

from bmtk.builder import NetworkBuilder

net = NetworkBuilder("one_cell_iclamp")

pos_x, pos_y = [0,0]

template = 'nest:iaf_psc_alpha'

net.add_nodes(N=1, pop_name='LIF_exc', location='VisL4', ei='e',
model_type='point_process', # use point_process to indicate we are using point model cells
model_template=template,
x=pos_x, y=pos_y,
dynamics_params='473863035_point.json')


net.build()
net.save(output_dir='../input/network')

print 'Built: %s'%net.name
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"manifest": {
"$NETWORK_DIR": "../input/network",
"$COMPONENT_DIR": "../../../shared_components"
},

"components": {
"synaptic_models_dir": "$COMPONENT_DIR/synaptic_models",
"mechanisms_dir":"$COMPONENT_DIR/mechanisms",
"point_neuron_models_dir": "$COMPONENT_DIR/point_neuron_models_dir"
},

"networks": {
"nodes": [
{
"nodes_file": "$NETWORK_DIR/one_cell_iclamp_nodes.h5",
"node_types_file": "$NETWORK_DIR/one_cell_iclamp_node_types.csv"
}
]
},


"target_simulator": "NEST"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"network": "./circuit_config.json",
"simulation": "./simulation_config.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_type_id ei model_type pop_name location model_template x y dynamics_params
100 e point_process LIF_exc VisL4 nest:iaf_psc_alpha 0 0 473863035_point.json
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"point_nodes": {
"model_type": "point_process"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"manifest": {
"$OUTPUT_DIR": "../test/output",
"$INPUT_DIR": "../input"
},

"run": {
"tstop": 1000.0,
"dt": 0.01,
"spike_threshold": -15,
"nsteps_block": 10000
},

"target_simulator":"NEST",

"network": "$INPUT_DIR/circuit_config.json",

"conditions": {
"celsius": 34.0,
"v_init": -80
},

"node_sets_file": "$INPUT_DIR/node_sets.json",

"mechanisms_dir": "../shared_components_mechanisms",


"inputs": {
"current_clamp_1": {
"input_type": "current_clamp",
"module": "IClamp",
"node_set": "point_nodes",
"amp": 190.0,
"delay": 100.0,
"duration": 800.0
}
},

"output":{
"output_dir": "$OUTPUT_DIR",
"log_file": "log.txt",
"spikes_file": "spikes.h5",
"spikes_sort_order": "time"
},

"reports": {

"membrane_potential": {
"cells": "point_nodes",
"variable_name": "V_m",
"module": "multimeter_report",
"sections": "soma",
"enabled": true
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys

sys.path.append("../../../shared_components/scripts")

from analyze_output_utils import plot_data

if __name__ == '__main__':

plot_data('output/membrane_potential.h5', 'mV', 'Membrane Potential')
Loading