Skip to content

Commit

Permalink
First version of sim test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
wvangeit committed Nov 20, 2018
1 parent 59042d0 commit 4c75c50
Show file tree
Hide file tree
Showing 33 changed files with 416 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/env python

# Sonata Simulator Test Suite
# 1-cell circuit, single soma, only cm, 1 step current

# Authors: Werner Van Geit @ BBP

import bmtk.builder

cell_models = [
{'model_name': 'soma_cm', 'x': [0.0],
'y': [0.0],
'z': [0.0],
'morphology': 'soma1',
'model_template': 'nml:soma_cm2.nml'}]

bio_cells = bmtk.builder.NetworkBuilder("biophysical")
for model_props in cell_models:
bio_cells.add_nodes(
model_type='biophysical',
**model_props)

bio_cells.build()
bio_cells.save_nodes(output_dir='../input/network')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/output
10 changes: 10 additions & 0 deletions examples/sim_tests/biophysical/one_cell/soma_cm2/bmtk_test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

rm -rf output
rm -rf __pycache__
# python -m trace --trace ../shared_components/scripts/run_bionet.py ../input/config.json
python ../shared_components/scripts/run_bionet.py ../input/config.json

pytest -vvs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os

import numpy
import h5py
import pytest

output_path = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'output'))

dt = 0.025
tstop = 60.0
stim_start = 20.0
stim_end = 50.0

start_voltage = -80.0
end_voltage = -20.0

# Using as 'raw' code as possible here, so as not to depend on other code
# that could contain errors


def test_soma_voltage():
"""Check soma voltages"""

soma_voltage_path = os.path.join(output_path, 'membrane_potential.h5')

assert os.path.exists(soma_voltage_path)

voltage = h5py.File(soma_voltage_path)['data'].value

assert len(voltage) == tstop / dt

time = numpy.arange(0, len(voltage)) * dt

soma_voltage_path = os.path.join(output_path, 'membrane_potential.h5')

assert os.path.exists(soma_voltage_path)
assert voltage[0] == pytest.approx(start_voltage)
assert numpy.mean(
voltage[
numpy.where(time < stim_start)]) == pytest.approx(start_voltage)
assert start_voltage < numpy.mean(voltage[numpy.where(
(time >= stim_start) & (time <= stim_end))]) < end_voltage
assert voltage[-1] == pytest.approx(end_voltage)


def test_spikes():
"""Check spike times"""

spikes_path = os.path.join(output_path, 'spikes.h5')

assert os.path.exists(spikes_path)

spikes = h5py.File(spikes_path)['spikes']['timestamps'].value

assert len(spikes) == 0
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"manifest": {
"$NETWORK_DIR": "../input/network",
"$COMPONENT_DIR": "../shared_components"
},

"components": {
"morphologies_dir": "$COMPONENT_DIR/morphologies",
"biophysical_neuron_models_dir": "$COMPONENT_DIR/templates/nml"
},

"networks": {
"nodes": [
{
"nodes_file": "$NETWORK_DIR/biophysical_nodes.h5",
"node_types_file": "$NETWORK_DIR/biophysical_node_types.csv"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_type_id model_type model_template morphology model_name
100 biophysical nml:soma_cm2.nml soma1 soma_cm
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"soma_cm2": {
"model_type": "biophysical"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"manifest": {
"$OUTPUT_DIR": "./output",
"$INPUT_DIR": "../input"
},

"run": {
"tstop": 60.0,
"dt": 0.025,
"dL": 20.0,
"spike_threshold": -15,
"nsteps_block": 5000
},

"target_simulator":"NEURON",

"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": "soma_cm2",
"amp": 0.0001256637,
"delay": 20.0,
"duration": 30.0
}
},

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

"reports": {
"membrane_potential": {
"cells": "soma_cm2",
"variable_name": "v",
"module": "membrane_report",
"sections": "soma"
}
}
}
3 changes: 3 additions & 0 deletions examples/sim_tests/biophysical/one_cell/soma_cm2/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::FutureWarning
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/env python

# Sonata Simulator Test Suite
# 1-cell circuit, single soma, only cm, 1 step current

# Authors: Werner Van Geit @ BBP

import bmtk.builder

cell_models = [
{'model_name': 'soma_cm', 'x': [0.0],
'y': [0.0],
'z': [0.0],
'morphology': 'soma1',
'model_template': 'nml:soma_cm2_hh.nml'}]

bio_cells = bmtk.builder.NetworkBuilder("biophysical")
for model_props in cell_models:
bio_cells.add_nodes(
model_type='biophysical',
**model_props)

bio_cells.build()
bio_cells.save_nodes(output_dir='../input/network')
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

rm -rf output
rm -rf __pycache__
# python -m trace --trace ../shared_components/scripts/run_bionet.py ../input/config.json
python ../shared_components/scripts/run_bionet.py ../input/config.json

pytest -vvs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os

import numpy
import h5py
import pytest

output_path = os.path.abspath(
os.path.join(
os.path.dirname(__file__),
'output'))

# TBD

'''
dt = 0.025
tstop = 60.0
stim_start = 20.0
stim_end = 50.0
start_voltage = -80.0
end_voltage = -20.0
# Using as 'raw' code as possible here, so as not to depend on other code
# that could contain errors
def test_soma_voltage():
"""Check soma voltages"""
soma_voltage_path = os.path.join(output_path, 'membrane_potential.h5')
assert os.path.exists(soma_voltage_path)
voltage = h5py.File(soma_voltage_path)['data'].value
assert len(voltage) == tstop / dt
time = numpy.arange(0, len(voltage)) * dt
soma_voltage_path = os.path.join(output_path, 'membrane_potential.h5')
import matplotlib.pyplot as plt
plt.plot(voltage)
plt.show()
assert os.path.exists(soma_voltage_path)
assert voltage[0] == pytest.approx(start_voltage)
assert numpy.mean(
voltage[
numpy.where(time < stim_start)]) == pytest.approx(start_voltage)
assert start_voltage < numpy.mean(voltage[numpy.where(
(time >= stim_start) & (time <= stim_end))]) < end_voltage
assert voltage[-1] == pytest.approx(end_voltage)
def test_spikes():
"""Check spike times"""
spikes_path = os.path.join(output_path, 'spikes.h5')
assert os.path.exists(spikes_path)
spikes = h5py.File(spikes_path)['spikes']['timestamps'].value
assert len(spikes) == 0
'''
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"manifest": {
"$NETWORK_DIR": "../input/network",
"$COMPONENT_DIR": "../shared_components"
},

"components": {
"morphologies_dir": "$COMPONENT_DIR/morphologies",
"biophysical_neuron_models_dir": "$COMPONENT_DIR/templates/nml"
},

"networks": {
"nodes": [
{
"nodes_file": "$NETWORK_DIR/biophysical_nodes.h5",
"node_types_file": "$NETWORK_DIR/biophysical_node_types.csv"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_type_id model_type model_template morphology model_name
100 biophysical nml:soma_cm2_hh.nml soma1 soma_cm
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"soma_cm2": {
"model_type": "biophysical"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"manifest": {
"$OUTPUT_DIR": "./output",
"$INPUT_DIR": "../input"
},

"run": {
"tstop": 60.0,
"dt": 0.025,
"dL": 20.0,
"spike_threshold": -15,
"nsteps_block": 5000
},

"target_simulator":"NEURON",

"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": "soma_cm2",
"amp": 0.002,
"delay": 20.0,
"duration": 30.0
}
},

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

"reports": {
"membrane_potential": {
"cells": "soma_cm2",
"variable_name": "v",
"module": "membrane_report",
"sections": "soma"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
filterwarnings =
ignore::FutureWarning
4 changes: 4 additions & 0 deletions examples/sim_tests/shared_components/configs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"network": "./circuit_config.json",
"simulation": "./simulation_config.json"
}
Loading

0 comments on commit 4c75c50

Please sign in to comment.