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

Commit 02a00fb

Browse files
committed
Anil's review for ACC exporter, fixing create_acc tests
1 parent 93c0685 commit 02a00fb

File tree

4 files changed

+33
-81
lines changed

4 files changed

+33
-81
lines changed

bluepyopt/ephys/create_acc.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, name, conv=None):
3131
self.conv = conv
3232

3333

34-
class Nrn2ArbParamFormatter:
34+
class Nrn2ArbParamAdapter:
3535
"""Converts a Neuron parameter to Arbor format (name and value)"""
3636

3737
_mapping = dict(
@@ -202,7 +202,7 @@ def _format_params_and_group_by_mech(params, channels):
202202
Mapping of Arbor mechanism name to list of parameters in Arbor
203203
format
204204
"""
205-
mech_params = [Nrn2ArbParamFormatter.format(
205+
mech_params = [Nrn2ArbParamAdapter.format(
206206
param, channels) for param in params]
207207
mechs = {mech: [] for mech, _ in mech_params}
208208
for mech in channels:
@@ -214,7 +214,8 @@ def _format_params_and_group_by_mech(params, channels):
214214

215215
@classmethod
216216
def process_global(cls, params):
217-
"""Group global params by mechanism, convert them to Arbor format
217+
"""Group global BluePyOpt params by mech, convert them to Arbor format
218+
218219
Args:
219220
params (): List of global parameters in Neuron format
220221
@@ -231,7 +232,7 @@ def process_global(cls, params):
231232

232233
@classmethod
233234
def process_local(cls, params, channels):
234-
"""Group local params by mechanism, convert them to Arbor format
235+
"""Group local BluePyOpt params by mech, convert them to Arbor format
235236
236237
Args:
237238
params (): List of Arbor label/local parameters pairs in Neuron

bluepyopt/ephys/create_hoc.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ def _loc_desc(location, param_or_mech):
112112
elif isinstance(param_or_mech, NrnMODPointProcessMechanism):
113113
raise CreateHocException("%s is currently not supported." %
114114
type(param_or_mech).__name__)
115-
elif not (isinstance(location, NrnSeclistCompLocation) or
116-
isinstance(location, NrnSectionCompLocation) or
117-
isinstance(location, NrnSomaDistanceCompLocation) or
118-
isinstance(location, NrnSecSomaDistanceCompLocation) or
119-
isinstance(location, NrnTrunkSomaDistanceCompLocation)) and \
120-
not isinstance(location, ArbLocation) and \
115+
elif not isinstance(location, (NrnSeclistCompLocation,
116+
NrnSectionCompLocation,
117+
NrnSomaDistanceCompLocation,
118+
NrnSecSomaDistanceCompLocation,
119+
NrnTrunkSomaDistanceCompLocation,
120+
ArbLocation)) and \
121121
not isinstance(param_or_mech, NrnPointProcessParameter):
122122
return location.seclist_name
123123
else:

bluepyopt/ephys/locations.py

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,14 @@ def acc_label(self):
541541
class ArbLocation(Location):
542542
"""Arbor Location"""
543543

544-
pass
544+
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
545+
"""Find the instantiate compartment (default implementation)"""
546+
raise EPhysLocInstantiateException(
547+
'%s not supported in NEURON.' % type(self).__name__)
548+
549+
def __str__(self):
550+
"""String representation"""
551+
return '%s \'%s\'' % (type(self).__name__, self.acc_label().defn)
545552

546553

547554
class ArbSegmentLocation(ArbLocation):
@@ -552,19 +559,10 @@ def __init__(self, name, segment, comment=''):
552559
super().__init__(name, comment)
553560
self.segment = segment
554561

555-
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
556-
"""Find the instantiate compartment"""
557-
raise EPhysLocInstantiateException(
558-
'%s not supported in NEURON.' % type(self).__name__)
559-
560562
def acc_label(self):
561563
"""Arbor label"""
562564
return ArbLabel('region', self.name, '(segment %s)' % (self.segment))
563565

564-
def __str__(self):
565-
"""String representation"""
566-
return '%s \'%s\'' % (type(self).__name__, self.acc_label().defn)
567-
568566

569567
class ArbBranchLocation(ArbLocation):
570568
"""Branch in an Arbor morphology.
@@ -576,19 +574,10 @@ def __init__(self, name, branch, comment=''):
576574
super().__init__(name, comment)
577575
self.branch = branch
578576

579-
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
580-
"""Find the instantiate compartment"""
581-
raise EPhysLocInstantiateException(
582-
'%s not supported in NEURON.' % type(self).__name__)
583-
584577
def acc_label(self):
585578
"""Arbor label"""
586579
return ArbLabel('region', self.name, '(branch %s)' % (self.branch))
587580

588-
def __str__(self):
589-
"""String representation"""
590-
return '%s \'%s\'' % (type(self).__name__, self.acc_label().defn)
591-
592581

593582
class ArbSegmentRelLocation(ArbLocation):
594583
"""Relative position on a segment in an Arbor morphology.
@@ -599,21 +588,12 @@ def __init__(self, name, segment, pos, comment=''):
599588
self.segment = segment
600589
self.pos = pos
601590

602-
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
603-
"""Find the instantiate compartment"""
604-
raise EPhysLocInstantiateException(
605-
'%s not supported in NEURON.' % type(self).__name__)
606-
607591
def acc_label(self):
608592
"""Arbor label"""
609593
return ArbLabel('locset', self.name,
610594
'(on-components %s (segment %s))' %
611595
(format_float(self.pos), self.segment))
612596

613-
def __str__(self):
614-
"""String representation"""
615-
return '%s \'%s\'' % (type(self).__name__, self.acc_label().defn)
616-
617597

618598
class ArbBranchRelLocation(ArbLocation):
619599
"""Relative position on a branch in an Arbor morphology.
@@ -626,21 +606,12 @@ def __init__(self, name, branch, pos, comment=''):
626606
self.branch = branch
627607
self.pos = pos
628608

629-
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
630-
"""Find the instantiate compartment"""
631-
raise EPhysLocInstantiateException(
632-
'%s not supported in NEURON.' % type(self).__name__)
633-
634609
def acc_label(self):
635610
"""Arbor label"""
636611
return ArbLabel('locset', self.name,
637612
'(location %s %s)' %
638613
(self.branch, format_float(self.pos)))
639614

640-
def __str__(self):
641-
"""String representation"""
642-
return '%s \'%s\'' % (type(self).__name__, self.acc_label().defn)
643-
644615

645616
class ArbLocsetLocation(ArbLocation):
646617
"""Arbor location set defined by a user-supplied string (S-expression).
@@ -650,19 +621,10 @@ def __init__(self, name, locset, comment=''):
650621
super().__init__(name, comment)
651622
self.locset = locset
652623

653-
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
654-
"""Find the instantiate compartment"""
655-
raise EPhysLocInstantiateException(
656-
'%s not supported in NEURON.' % type(self).__name__)
657-
658624
def acc_label(self):
659625
"""Arbor label"""
660626
return ArbLabel('locset', self.name, self.locset)
661627

662-
def __str__(self):
663-
"""String representation"""
664-
return '%s %s' % (type(self).__name__, self.acc_label().defn)
665-
666628

667629
class ArbRegionLocation(ArbLocation):
668630
"""Arbor region defined by a user-supplied string (S-expression).
@@ -672,19 +634,10 @@ def __init__(self, name, region, comment=''):
672634
super().__init__(name, comment)
673635
self.region = region
674636

675-
def instantiate(self, sim=None, icell=None): # pylint: disable=W0613
676-
"""Find the instantiate compartment"""
677-
raise EPhysLocInstantiateException(
678-
'%s not supported in NEURON.' % type(self).__name__)
679-
680637
def acc_label(self):
681638
"""Arbor label"""
682639
return ArbLabel('region', self.name, self.region)
683640

684-
def __str__(self):
685-
"""String representation"""
686-
return '%s %s' % (type(self).__name__, self.acc_label().defn)
687-
688641

689642
class EPhysLocInstantiateException(Exception):
690643

bluepyopt/tests/test_ephys/test_create_acc.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
from bluepyopt import ephys
1919
from bluepyopt.ephys import create_acc
20-
from bluepyopt.ephys.create_acc import (Nrn2ArbParamFormatter,
20+
from bluepyopt.ephys.create_acc import (Nrn2ArbParamAdapter,
2121
Nrn2ArbMechGrouper,
2222
ArbNmodlMechFormatter)
2323

@@ -48,52 +48,52 @@ def test_read_templates():
4848

4949

5050
@pytest.mark.unit
51-
def test_Nrn2ArbParamFormatter_param_name():
51+
def test_Nrn2ArbParamAdapter_param_name():
5252
"""Test Neuron to Arbor parameter mapping."""
5353
# Identity
5454
mech_param_name = "gSKv3_1bar_SKv3_1"
55-
assert Nrn2ArbParamFormatter._param_name(mech_param_name) \
55+
assert Nrn2ArbParamAdapter._param_name(mech_param_name) \
5656
== mech_param_name
5757

5858
# Non-trivial transformation
5959
global_property_name = "v_init"
60-
assert Nrn2ArbParamFormatter._param_name(global_property_name) \
60+
assert Nrn2ArbParamAdapter._param_name(global_property_name) \
6161
== "membrane-potential"
6262

6363

6464
@pytest.mark.unit
65-
def test_Nrn2ArbParamFormatter_param_value():
65+
def test_Nrn2ArbParamAdapter_param_value():
6666
"""Test Neuron to Arbor parameter units conversion."""
6767
# Identity for region parameter
6868
mech_param = create_acc.Location(name="gSKv3_1bar_SKv3_1", value="1.025")
69-
assert Nrn2ArbParamFormatter._param_value(mech_param) == "1.025"
69+
assert Nrn2ArbParamAdapter._param_value(mech_param) == "1.025"
7070

7171
# Non-trivial name transformation, but identical value/units
7272
global_property = create_acc.Location(name="v_init", value=-65)
73-
assert Nrn2ArbParamFormatter._param_value(global_property) == "-65"
73+
assert Nrn2ArbParamAdapter._param_value(global_property) == "-65"
7474

7575
# Non-trivial name and value/units transformation
7676
global_property = create_acc.Location(name="celsius", value=34)
77-
assert Nrn2ArbParamFormatter._param_value(global_property) == (
77+
assert Nrn2ArbParamAdapter._param_value(global_property) == (
7878
"307.14999999999998")
7979

8080

8181
@pytest.mark.unit
82-
def test_Nrn2ArbParamFormatter_format():
82+
def test_Nrn2ArbParamAdapter_format():
8383
"""Test Neuron to Arbor parameter reformatting."""
8484
# Constant mechanism parameter
8585
mech_param = create_acc.Location(name="gSKv3_1bar_SKv3_1", value="1.025")
8686
mech = "SKv3_1"
8787
arb_mech_param = create_acc.Location(name="gSKv3_1bar", value="1.025")
8888
assert (
89-
Nrn2ArbParamFormatter.format(
89+
Nrn2ArbParamAdapter.format(
9090
mech_param, mechs=[mech])
9191
== (mech, arb_mech_param)
9292
)
9393

9494
# Non-unique mapping to mechanisms
9595
with pytest.raises(create_acc.CreateAccException):
96-
Nrn2ArbParamFormatter.format(
96+
Nrn2ArbParamAdapter.format(
9797
mech_param, mechs=["SKv3_1", "1"])
9898

9999
# Global property with non-trivial transformation
@@ -102,7 +102,7 @@ def test_Nrn2ArbParamFormatter_format():
102102
arb_global_property = create_acc.Location(
103103
name="temperature-kelvin", value="273.14999999999998")
104104
# Non-trivial name and value/units transformation
105-
assert Nrn2ArbParamFormatter.format(global_property, []) == \
105+
assert Nrn2ArbParamAdapter.format(global_property, []) == \
106106
(mech, arb_global_property)
107107

108108
# Inhomogeneuos mechanism parameter
@@ -126,7 +126,7 @@ def test_Nrn2ArbParamFormatter_format():
126126
value_scaler=param_scaler,
127127
)
128128
assert (
129-
Nrn2ArbParamFormatter.format(
129+
Nrn2ArbParamAdapter.format(
130130
iexpr_param, mechs=[mech])
131131
== (mech, arb_iexpr_param)
132132
)
@@ -151,7 +151,7 @@ def test_Nrn2ArbParamFormatter_format():
151151
arb_point_expr_param = create_acc.PointExpr(
152152
name="tau", value="10", point_loc=[mech_loc])
153153
assert (
154-
Nrn2ArbParamFormatter.format(
154+
Nrn2ArbParamAdapter.format(
155155
point_expr_param, mechs=[mech])
156156
== (mech, arb_point_expr_param)
157157
)
@@ -540,8 +540,6 @@ def test_cell_model_write_and_read_acc_replace_axon():
540540
assert len(e.args) == 1 and e.args[0] == \
541541
"Need a newer version of Arbor for axon replacement."
542542
return
543-
finally:
544-
cell.destroy(nrn_sim)
545543

546544
# Axon replacement implemented in installed Arbor version
547545
cell_json, arb_morph, arb_decor, arb_labels = \

0 commit comments

Comments
 (0)