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

Commit 04ce614

Browse files
committed
Integrating more feedback from Anil, fixed L5PC ACC test
1 parent 02a00fb commit 04ce614

File tree

5 files changed

+97
-37
lines changed

5 files changed

+97
-37
lines changed

bluepyopt/ephys/create_acc.py

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import io
66
import logging
77
import pathlib
8-
from collections import namedtuple, OrderedDict
8+
from collections import ChainMap, namedtuple, OrderedDict
99
import re
1010

1111
import jinja2
@@ -24,12 +24,23 @@
2424
RangeIExpr = namedtuple('RangeIExpr', 'name, value, scale')
2525

2626

27-
# Define Neuron to Arbor parameter conversions (conv defaults to identity)
2827
class ArbVar:
28+
"""Definition of a Neuron to Arbor parameter conversion"""
29+
2930
def __init__(self, name, conv=None):
31+
"""Constructor
32+
33+
Args:
34+
name (str): Arbor parameter name
35+
conv (): Conversion of parameter value from Neuron units
36+
to Arbor (defaults to identity)
37+
"""
3038
self.name = name
3139
self.conv = conv
3240

41+
def __repr__(self):
42+
return 'ArbVar(%s, %s)' % (self.name, self.conv)
43+
3344

3445
class Nrn2ArbParamAdapter:
3546
"""Converts a Neuron parameter to Arbor format (name and value)"""
@@ -220,9 +231,9 @@ def process_global(cls, params):
220231
params (): List of global parameters in Neuron format
221232
222233
Returns:
223-
A mapping of mechanism to parameters. The mechanism parameters are
224-
in Arbor format (mechanism name is None for non-mechanism
225-
parameters).
234+
A mapping of mechanism to parameters representing Arbor global
235+
properties. The mechanism parameters are in Arbor format
236+
(mechanism name is None for non-mechanism parameters).
226237
"""
227238
return cls._format_params_and_group_by_mech(
228239
[Location(name=name, value=value)
@@ -240,10 +251,11 @@ def process_local(cls, params, channels):
240251
channels (): Mapping of Arbor label to co-located NMODL mechanisms
241252
242253
Returns:
243-
In the first component, a two-level mapping of Arbor label to
244-
mechanism to parameters. The mechanism parameters are in Arbor
245-
format (mechanism name is None for non-mechanism parameters).
246-
In the second component, the global properties found are returned.
254+
The return value is a tuple. In the first component, a two-level
255+
mapping of Arbor label to mechanism to parameters. The mechanism
256+
parameters are in Arbor format (mechanism name is None for
257+
non-mechanism parameters). In the second component, the
258+
Arbor global properties found are returned.
247259
"""
248260
local_mechs = dict()
249261
global_properties = dict()
@@ -253,9 +265,12 @@ def process_local(cls, params, channels):
253265

254266
# move Arbor global properties to global_params
255267
mechs, global_props = cls._separate_global_properties(loc, mechs)
256-
for mech, props in global_props.items():
257-
global_properties[mech] = \
258-
global_properties.get(mech, []) + props
268+
if global_props.keys() != {None}:
269+
raise CreateAccException(
270+
'Support for Arbor default mechanisms not implemented.')
271+
# iterate over global_props items if above exception triggers
272+
global_properties[None] = \
273+
global_properties.get(None, []) + global_props[None]
259274
local_mechs[loc] = mechs
260275
return local_mechs, global_properties
261276

@@ -509,19 +524,18 @@ def _arb_populate_label_dict(local_mechs, local_scaled_mechs, pprocess_mechs):
509524

510525
label_dict = dict()
511526

512-
for acc_labels in [local_mechs.keys(),
513-
local_scaled_mechs.keys(),
514-
pprocess_mechs.keys()]:
515-
for acc_label in acc_labels:
516-
if acc_label.name in label_dict and \
517-
acc_label != label_dict[acc_label.name]:
518-
raise CreateAccException(
519-
'Label %s already exists in' % acc_label.name +
520-
' label_dict with different s-expression: '
521-
' %s != %s.' % (label_dict[acc_label.name].loc,
522-
acc_label.loc))
523-
elif acc_label.name not in label_dict:
524-
label_dict[acc_label.name] = acc_label
527+
acc_labels = ChainMap(local_mechs, local_scaled_mechs, pprocess_mechs)
528+
529+
for acc_label in acc_labels:
530+
if acc_label.name in label_dict and \
531+
acc_label != label_dict[acc_label.name]:
532+
raise CreateAccException(
533+
'Label %s already exists in' % acc_label.name +
534+
' label_dict with different s-expression: '
535+
' %s != %s.' % (label_dict[acc_label.name].loc,
536+
acc_label.loc))
537+
elif acc_label.name not in label_dict:
538+
label_dict[acc_label.name] = acc_label
525539

526540
return label_dict
527541

@@ -592,6 +606,9 @@ def create_acc(mechs,
592606
of a custom template
593607
'''
594608

609+
if custom_jinja_params is None:
610+
custom_jinja_params = {}
611+
595612
if pathlib.Path(morphology).suffix.lower() not in ['.swc', '.asc']:
596613
raise CreateAccException("Morphology file %s not supported in Arbor "
597614
" (only supported types are .swc and .asc)."
@@ -642,9 +659,6 @@ def create_acc(mechs,
642659
default_location_order,
643660
_arb_loc_desc)
644661

645-
if custom_jinja_params is None:
646-
custom_jinja_params = {}
647-
648662
filenames = {
649663
name: template_name + (name if name.startswith('.') else "_" + name)
650664
for name in templates.keys()}
@@ -825,7 +839,7 @@ def read_acc(cell_json_filename):
825839

826840
class CreateAccException(Exception):
827841

828-
"""All exceptions generated by create_acc module"""
842+
"""Exceptions generated by create_acc module"""
829843

830844
def __init__(self, message):
831845
"""Constructor"""

bluepyopt/tests/test_ephys/test_create_acc.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,19 +583,28 @@ def test_cell_model_create_acc_replace_axon_without_instantiate():
583583
def check_acc_dir(test_dir, ref_dir):
584584
assert os.listdir(ref_dir) == os.listdir(test_dir)
585585

586+
ref_dir_ver_suffix = '_py' + ''.join(sys.version.split('.')[:2])
587+
ref_dir_ver = ref_dir.parent / (ref_dir.name + ref_dir_ver_suffix)
588+
586589
for file in os.listdir(ref_dir):
590+
591+
if (ref_dir_ver / file).exists():
592+
ref_dir_file = ref_dir_ver
593+
else:
594+
ref_dir_file = ref_dir
595+
587596
if file.endswith('.json'):
588597
with open(os.path.join(test_dir, file)) as f:
589598
cell_json_dict = json.load(f)
590-
with open(ref_dir / file) as f:
599+
with open(ref_dir_file / file) as f:
591600
ref_cell_json = json.load(f)
592601
for k in ref_cell_json:
593602
if k != 'produced_by':
594603
assert ref_cell_json[k] == cell_json_dict[k]
595604
else:
596605
with open(os.path.join(test_dir, file)) as f:
597606
test_file = f.read()
598-
with open(ref_dir / file) as f:
607+
with open(ref_dir_file / file) as f:
599608
ref_file = f.read()
600609
assert ref_file == test_file
601610

bluepyopt/tests/test_ephys/testdata/acc/l5pc/C060114A7_axon_replacement.acc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
2)
1010
(segment 1
1111
(point 262.996735 -9.641676 -3.380000 0.690000)
12-
(point 262.745453 -24.639570 -3.380000 0.690000)
12+
(point 262.745453 -24.639572 -3.380000 0.690000)
1313
2)
1414
(segment 2
15-
(point 262.745453 -24.639570 -3.380000 0.460000)
15+
(point 262.745453 -24.639572 -3.380000 0.460000)
1616
(point 262.494171 -39.637466 -3.380000 0.460000)
1717
2)
1818
(segment 3
1919
(point 262.494171 -39.637466 -3.380000 0.460000)
20-
(point 262.242889 -54.635361 -3.380000 0.460000)
20+
(point 262.242889 -54.635365 -3.380000 0.460000)
2121
2))))

bluepyopt/tests/test_ephys/testdata/acc/l5pc/C060114A7_modified.acc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21690,13 +21690,13 @@
2169021690
2)
2169121691
(segment 5372
2169221692
(point 262.996735 -9.641676 -3.380000 0.690000)
21693-
(point 262.745453 -24.639570 -3.380000 0.690000)
21693+
(point 262.745453 -24.639572 -3.380000 0.690000)
2169421694
2)
2169521695
(segment 5373
21696-
(point 262.745453 -24.639570 -3.380000 0.460000)
21696+
(point 262.745453 -24.639572 -3.380000 0.460000)
2169721697
(point 262.494171 -39.637466 -3.380000 0.460000)
2169821698
2)
2169921699
(segment 5374
2170021700
(point 262.494171 -39.637466 -3.380000 0.460000)
21701-
(point 262.242889 -54.635361 -3.380000 0.460000)
21701+
(point 262.242889 -54.635365 -3.380000 0.460000)
2170221702
2))))
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(arbor-component
2+
(meta-data (version "0.1-dev"))
3+
(decor
4+
(default (membrane-potential -65))
5+
(default (temperature-kelvin 307.14999999999998))
6+
(default (membrane-capacitance 0.01))
7+
(default (axial-resistivity 100))
8+
(paint (region "all") (density (mechanism "default::pas/e=-75" ("g" 3.0000000000000001e-05))))
9+
(paint (region "soma") (ion-reversal-potential "na" 50))
10+
(paint (region "soma") (ion-reversal-potential "k" -85))
11+
(paint (region "soma") (density (mechanism "BBP::NaTs2_t" ("gNaTs2_tbar" 0.98395500000000002))))
12+
(paint (region "soma") (density (mechanism "BBP::SKv3_1" ("gSKv3_1bar" 0.30347200000000002))))
13+
(paint (region "soma") (density (mechanism "BBP::SK_E2" ("gSK_E2bar" 0.0084069999999999995))))
14+
(paint (region "soma") (density (mechanism "BBP::Ca_HVA" ("gCa_HVAbar" 0.00099400000000000009))))
15+
(paint (region "soma") (density (mechanism "BBP::Ca_LVAst" ("gCa_LVAstbar" 0.00033300000000000002))))
16+
(paint (region "soma") (density (mechanism "BBP::CaDynamics_E2" ("gamma" 0.00060899999999999995) ("decay" 210.48528400000001))))
17+
(paint (region "soma") (density (mechanism "BBP::Ih" ("gIhbar" 8.0000000000000007e-05))))
18+
(paint (region "axon") (ion-reversal-potential "na" 50))
19+
(paint (region "axon") (ion-reversal-potential "k" -85))
20+
(paint (region "axon") (density (mechanism "BBP::NaTa_t" ("gNaTa_tbar" 3.1379679999999999))))
21+
(paint (region "axon") (density (mechanism "BBP::Nap_Et2" ("gNap_Et2bar" 0.0068269999999999997))))
22+
(paint (region "axon") (density (mechanism "BBP::K_Pst" ("gK_Pstbar" 0.97353800000000001))))
23+
(paint (region "axon") (density (mechanism "BBP::K_Tst" ("gK_Tstbar" 0.089259000000000005))))
24+
(paint (region "axon") (density (mechanism "BBP::SK_E2" ("gSK_E2bar" 0.0071040000000000001))))
25+
(paint (region "axon") (density (mechanism "BBP::SKv3_1" ("gSKv3_1bar" 1.0219450000000001))))
26+
(paint (region "axon") (density (mechanism "BBP::Ca_HVA" ("gCa_HVAbar" 0.00098999999999999999))))
27+
(paint (region "axon") (density (mechanism "BBP::Ca_LVAst" ("gCa_LVAstbar" 0.0087519999999999994))))
28+
(paint (region "axon") (density (mechanism "BBP::CaDynamics_E2" ("gamma" 0.0029099999999999998) ("decay" 287.19873100000001))))
29+
(paint (region "dend") (membrane-capacitance 0.02))
30+
(paint (region "dend") (density (mechanism "BBP::Ih" ("gIhbar" 8.0000000000000007e-05))))
31+
(paint (region "apic") (ion-reversal-potential "na" 50))
32+
(paint (region "apic") (ion-reversal-potential "k" -85))
33+
(paint (region "apic") (membrane-capacitance 0.02))
34+
(paint (region "apic") (density (mechanism "BBP::NaTs2_t" ("gNaTs2_tbar" 0.026145000000000002))))
35+
(paint (region "apic") (density (mechanism "BBP::SKv3_1" ("gSKv3_1bar" 0.0042259999999999997))))
36+
(paint (region "apic") (density (mechanism "BBP::Im" ("gImbar" 0.00014300000000000001))))
37+
(paint (region "apic") (scaled-mechanism (density (mechanism "BBP::Ih" ("gIhbar" 8.0000000000000007e-05))) ("gIhbar" (add (mul (scalar -1) (scalar 0.86960000000000004) ) (mul (scalar 2.0870000000000002) (exp (mul (distance (region "soma")) (scalar 0.0030999999999999999) ) ) ) ))))))

0 commit comments

Comments
 (0)