Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 5bbc88e

Browse files
author
Jaquier Aurélien Tristan
committed
Add slow test for neuroml/LEMS
1 parent a1cbed2 commit 5bbc88e

File tree

7 files changed

+124
-10
lines changed

7 files changed

+124
-10
lines changed

AUTHORS.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Giuseppe Chindemi @ BBP
66
Tanguy Damart @ BBP
77
Elisabetta Iavarone @ BBP
88
Anil Tuncel @ BBP
9+
Aurelien Jaquier @ BBP

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,20 @@ clean:
6767
rm -rf examples/l5pc/L5PC.py
6868
rm -rf examples/l5pc/x86_64
6969
rm -rf examples/stochkv/x86_64
70+
rm -rf x86_64
7071
rm -rf .coverage
7172
rm -rf coverage.xml
73+
rm -rf channels
74+
rm -rf LEMS_l5pc.xml
75+
rm -rf LEMS_l5pc_nrn.py
76+
rm -rf l5pc.Pop_l5pc_0_0.v.dat
77+
rm -rf time.dat
78+
rm -rf l5pc.hoc
79+
rm -rf l5pc.net.nml
80+
rm -rf l5pc_0_0.cell.nml
81+
rm -rf l5pc_0_0.hoc
82+
rm -rf loadcell.hoc
83+
rm -rf *.mod
7284
find . -name "*.pyc" -exec rm -rf {} \;
7385
l5pc_start: install
7486
cd examples/l5pc && \

bluepyopt/neuroml/biophys.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,18 @@
3636
"NaTa_t": "na",
3737
"NaTs2_t": "na",
3838
"Nap_Et2": "na",
39-
# "NaTg": "na",
40-
# "NaTg2": "na",
4139
"K_Tst": "k",
4240
"K_Pst": "k",
4341
"SKv3_1": "k",
4442
"SK_E2": "k",
4543
"StochKv": "k",
46-
# "StochKv2": "k",
47-
# "StochKv3": "k",
4844
"KdShu2007": "k",
4945
"Im": "k",
5046
"Ca": "ca",
5147
"Ca_HVA": "ca",
52-
# "Ca_HVA2": "ca",
5348
"Ca_LVAst": "ca",
5449
"pas": "pas",
5550
"CaDynamics_E2": "ca",
56-
# "CaDynamics_DC0": "ca",
5751
}
5852

5953
ion_erevs = {

bluepyopt/tests/test_neuroml_fcts.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@
33
import os
44
import sys
55

6+
import efel
67
import neuroml
8+
import numpy
79
import pytest
10+
from pyneuroml import pynml
11+
from bluepyopt import ephys
812
from bluepyopt.neuroml import biophys
13+
from bluepyopt.neuroml import cell
914
from bluepyopt.neuroml import morphology
15+
from bluepyopt.neuroml import simulation
1016

1117
L5PC_PATH = os.path.abspath(
1218
os.path.join(os.path.dirname(__file__), "../../examples/l5pc")
1319
)
1420

1521
sys.path.insert(0, L5PC_PATH)
1622

23+
import l5pc_evaluator
1724
import l5pc_model # NOQA
1825

1926
l5pc_cell = l5pc_model.create()
27+
protocols = l5pc_evaluator.define_protocols()
2028

2129
release_params = {
2230
"gNaTs2_tbar_NaTs2_t.apical": 0.026145,
@@ -392,3 +400,91 @@ def test_add_segment_groups():
392400
assert "soma_group" in segment_group_names
393401
assert "axon_group" in segment_group_names
394402
assert "dendrite_group" in segment_group_names
403+
404+
405+
@pytest.mark.slow
406+
@pytest.mark.neuroml
407+
def test_neuroml_run():
408+
"""Test neuroml conversion and simulation"""
409+
# replace axon is not supported yet
410+
l5pc_cell.morphology.do_replace_axon = False
411+
dt = 0.025
412+
protocol_name = "Step3"
413+
bpo_test_protocol = protocols[protocol_name]
414+
415+
# create neuroml cell
416+
cell.create_neuroml_cell(
417+
l5pc_cell, release_params, skip_channels_copy=False
418+
)
419+
420+
# create LEMS simulation
421+
network_filename = f"{l5pc_cell.name}.net.nml"
422+
lems_filename = f"LEMS_{l5pc_cell.name}.xml"
423+
simulation.create_neuroml_simulation(
424+
network_filename, bpo_test_protocol, dt, l5pc_cell.name, lems_filename
425+
)
426+
427+
# remove compiled mechanisms if any before running LEMS simulation
428+
os.system("rm -rf x86_64/")
429+
430+
# run the simulation with the NEURON simulator,
431+
# since the default jNeuroML simulator can only simulate single
432+
# compartment cells
433+
pynml.run_lems_with_jneuroml_neuron(
434+
lems_filename, nogui=True, plot=False)
435+
436+
# re-compile the mechanisms before running with bluepyopt
437+
os.system("rm -rf x86_64/")
438+
os.system("nrnivmodl examples/l5pc/mechanisms/")
439+
440+
lems_output = numpy.loadtxt("l5pc.Pop_l5pc_0_0.v.dat")
441+
lems_voltage = lems_output[:, 1] * 1000 # *1000 -> mV
442+
lems_time = lems_output[:, 0] * 1000 # *1000 -> ms
443+
444+
# remove non uniform parameter to be coherent with LEMS simulation
445+
to_remove = []
446+
for key, param in l5pc_cell.params.items():
447+
if hasattr(param, "value_scaler"):
448+
if isinstance(
449+
param.value_scaler,
450+
ephys.parameterscalers.NrnSegmentSomaDistanceScaler,
451+
):
452+
to_remove.append(key)
453+
454+
for param_name in to_remove:
455+
l5pc_cell.params.pop(param_name)
456+
457+
# run with regular bluepyopt
458+
sim = ephys.simulators.NrnSimulator(dt=dt, cvode_active=False)
459+
bpo_output = bpo_test_protocol.run(
460+
cell_model=l5pc_cell, param_values=release_params, sim=sim
461+
)
462+
463+
response_name = f"{protocol_name}.soma.v"
464+
bpo_voltage = bpo_output[response_name]["voltage"]
465+
bpo_time = bpo_output[response_name]["time"]
466+
467+
# we don't expect the two traces to be exactly the same,
468+
# but to be pretty similar
469+
# we consider it satisfactory if they fire within 3 ms respectively
470+
trace_lems = {
471+
"T": lems_time,
472+
"V": lems_voltage,
473+
"stim_start": [700],
474+
"stim_end": [2700]
475+
}
476+
trace_bpo = {
477+
"T": bpo_time,
478+
"V": bpo_voltage,
479+
"stim_start": [700],
480+
"stim_end": [2700]
481+
}
482+
traces = [trace_lems, trace_bpo]
483+
features = ["peak_time"]
484+
feature_values = efel.getFeatureValues(
485+
traces, features, raise_warnings=False
486+
)
487+
lems_peak_time = feature_values[0]["peak_time"]
488+
bpo_peak_time = feature_values[1]["peak_time"]
489+
490+
numpy.testing.assert_allclose(lems_peak_time, bpo_peak_time, atol=3)

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
markers =
33
unit
44
slow
5+
neuroml
56
filterwarnings =
67
ignore::RuntimeWarning:deap.*
78
ignore::DeprecationWarning

setup.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
EXTRA_SCOOP = [
2828
'scoop>=0.7',
2929
]
30+
EXTRA_NEUROML = [
31+
'pyneuroml>=0.5.20',
32+
'libNeuroML>=0.3.1',
33+
]
3034

3135
setuptools.setup(
3236
name="bluepyopt",
@@ -42,12 +46,11 @@
4246
'Jinja2>=2.8',
4347
'future',
4448
'Pebble>=4.3.10',
45-
'pyneuroml>=0.5.20',
46-
'libNeuroML>=0.3.1'
4749
],
4850
extras_require={
49-
'all': EXTRA_SCOOP,
51+
'all': EXTRA_SCOOP + EXTRA_NEUROML,
5052
'scoop': EXTRA_SCOOP,
53+
'neuroml': EXTRA_NEUROML,
5154
},
5255
packages=setuptools.find_packages(
5356
exclude=(

tox.ini

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ envdir =
1515
py27{-unit,-functional,-style,-syntax}: {toxworkdir}/py27
1616
py3{5,6,7,8,9,10,}{-unit,-functional,-style,-syntax}: {toxworkdir}/py3
1717
docs: {toxworkdir}/docs
18+
extras = neuroml
1819
deps =
1920
coverage
2021
flake8
@@ -30,6 +31,9 @@ whitelist_externals =
3031
pwd
3132
passenv = https_proxy
3233
coverage_options = --cov-append --cov-report=xml --cov-config=.coveragerc
34+
setenv =
35+
; for neuroml tests
36+
NEURON_HOME={envdir}
3337
commands =
3438
make clean
3539

@@ -38,7 +42,10 @@ commands =
3842

3943
unit: pytest --cov=bluepyopt {[testenv]coverage_options} bluepyopt/tests -k unit
4044
functional: make stochkv_prepare l5pc_prepare sc_prepare meta_prepare
41-
functional: pytest --cov=bluepyopt {[testenv]coverage_options} bluepyopt/tests -k 'not unit'
45+
functional: pytest --cov=bluepyopt {[testenv]coverage_options} bluepyopt/tests -k 'not unit and not neuroml'
46+
; separate neuroml test from the other ones
47+
; because it redefines l5pc template which makes neuron crash and tests fail
48+
functional: pytest --cov=bluepyopt {[testenv]coverage_options} bluepyopt/tests -m neuroml
4249

4350
[testenv:docs]
4451
basepython = python3.6

0 commit comments

Comments
 (0)