11import numpy as np
22import pytest
33
4- from tests .conftest import RINGTEST_DIR
5-
6- from neurodamus .core .configuration import ConfigurationError , SimConfig
4+ from neurodamus .core .configuration import ConfigurationError
75from neurodamus .modification_manager import ModificationManager
86from neurodamus .node import Neurodamus , Node
7+ from types import SimpleNamespace
98
10- SIMULATION_CONFIG_FILE = RINGTEST_DIR / "simulation_config.json"
9+ from tests . conftest import RINGTEST_DIR
1110
11+ SIMULATION_CONFIG_FILE = RINGTEST_DIR / "simulation_config.json"
1212
13- def test_applyTTX ():
13+ @pytest .mark .parametrize (
14+ "create_tmp_simulation_config_file" ,
15+ [
16+ {
17+ "simconfig_fixture" : "ringtest_baseconfig" ,
18+ "extra_config" : {
19+ "conditions" : {
20+ "modifications" : [
21+ {
22+ "name" : "applyTTX" ,
23+ "type" : "TTX" ,
24+ "node_set" : "RingA"
25+ }
26+ ]
27+ },
28+ },
29+ }
30+ ],
31+ indirect = True ,
32+ )
33+ def test_applyTTX (create_tmp_simulation_config_file ):
1434 """
1535 A test of enabling TTX with a short simulation.
1636 As Ringtest cells don't contain mechanisms that use the TTX concentration
@@ -21,7 +41,7 @@ def test_applyTTX():
2141 # NeuronWrapper needs to be imported at function level
2242 from neurodamus .core import NeuronWrapper as Nd
2343
24- n = Node (str ( SIMULATION_CONFIG_FILE ) )
44+ n = Node (create_tmp_simulation_config_file )
2545
2646 # setup sim
2747 n .load_targets ()
@@ -33,24 +53,29 @@ def test_applyTTX():
3353 for sec in cell .all :
3454 assert not Nd .ismembrane ("TTXDynamicsSwitch" , sec = sec )
3555
36- # append modification to config directly
37- TTX_mod = {"Type" : "TTX" , "Target" : "RingA" }
38- SimConfig .modifications ["applyTTX" ] = TTX_mod
39-
4056 n .enable_modifications ()
4157
4258 # check TTXDynamicsSwitch is inserted after modifications
4359 for sec in cell .all :
4460 assert Nd .ismembrane ("TTXDynamicsSwitch" , sec = sec )
4561
46-
4762@pytest .mark .parametrize (
4863 "create_tmp_simulation_config_file" ,
4964 [
5065 {
5166 "simconfig_fixture" : "ringtest_baseconfig" ,
5267 "extra_config" : {
5368 "target_simulator" : "NEURON" ,
69+ "conditions" : {
70+ "modifications" : [
71+ {
72+ "name" : "no_SK_E2" ,
73+ "node_set" : "Mosaic" ,
74+ "type" : "ConfigureAllSections" ,
75+ "section_configure" : "%s.gnabar_hh = 0" ,
76+ }
77+ ]
78+ },
5479 "inputs" : {
5580 "pulse" : {
5681 "module" : "pulse" ,
@@ -95,14 +120,6 @@ def test_ConfigureAllSections(create_tmp_simulation_config_file):
95120 for sec in cell .all :
96121 assert getattr (sec , sec_variable ) > 0
97122
98- # append modification to config directly
99- ConfigureAllSections_mod = {
100- "Type" : "ConfigureAllSections" ,
101- "Target" : "Mosaic" ,
102- "SectionConfigure" : f"%s.{ sec_variable } = 0" ,
103- }
104- SimConfig .modifications ["no_SK_E2" ] = ConfigureAllSections_mod
105-
106123 n .enable_modifications ()
107124
108125 # check section variable value after modifications
@@ -158,6 +175,55 @@ def test_ConfigureAllSections_AugAssign(create_tmp_simulation_config_file):
158175 assert np .isclose (soma2 .e_pas , - 7 )
159176
160177
178+ @pytest .mark .parametrize (
179+ "create_tmp_simulation_config_file" ,
180+ [
181+ {
182+ "simconfig_fixture" : "ringtest_baseconfig" ,
183+ "extra_config" : {
184+ "target_simulator" : "NEURON" ,
185+ "conditions" : {
186+ "modifications" : [
187+ {
188+ "name" : "no_SK_E2" ,
189+ "node_set" : "RingA:oneCell" ,
190+ "type" : "ConfigureAllSections" ,
191+ "section_configure" : "%s.e_pas *= 0.1" ,
192+ },
193+ {
194+ "name" : "no_SK_E2" ,
195+ "node_set" : "RingA:oneCell" ,
196+ "type" : "ConfigureAllSections" ,
197+ "section_configure" : "%s.gnabar_hh *= 11" ,
198+ }
199+
200+ ]
201+ },
202+ },
203+ }
204+ ],
205+ indirect = True ,
206+ )
207+ def test_ConfigureAllSections_AugAssign_name_clash (create_tmp_simulation_config_file ):
208+ """This should produce the same results as test_ConfigureAllSections_AugAssign
209+
210+ However, here we apply the same modification in 2 steps with modifications
211+ that have the same name. Their combined effect should be equivalent
212+ to the modification in test_ConfigureAllSections_AugAssign.
213+ """
214+
215+ # NeuronWrapper needs to be imported at function level
216+ from neurodamus .core import NeuronWrapper as Nd
217+
218+ Neurodamus (create_tmp_simulation_config_file )
219+ soma1 = Nd ._pc .gid2cell (0 ).soma [0 ]
220+ soma2 = Nd ._pc .gid2cell (1 ).soma [0 ]
221+
222+ assert np .isclose (soma1 .gnabar_hh , 0.12 )
223+ assert np .isclose (soma1 .e_pas , - 70 )
224+ assert np .isclose (soma2 .gnabar_hh , 1.32 )
225+ assert np .isclose (soma2 .e_pas , - 7 )
226+
161227@pytest .mark .parametrize (
162228 "create_tmp_simulation_config_file" ,
163229 [
@@ -193,6 +259,17 @@ def test_error_unknown_modification():
193259 with pytest .raises (ConfigurationError , match = "Unknown Modification mod_blabla" ):
194260 mod_manager .interpret (target_spec = "dummy" , mod_info = {"Type" : "mod_blabla" })
195261
262+ def test_error_unknown_modification ():
263+ mod_manager = ModificationManager (target_manager = "dummy" )
264+ unknown_type = object ()
265+ mod_info = SimpleNamespace (type = unknown_type )
266+
267+ with pytest .raises (
268+ ConfigurationError ,
269+ match = "Unknown Modification" ,
270+ ):
271+ mod_manager .interpret (target_spec = "dummy" , mod_info = mod_info )
272+
196273
197274@pytest .mark .parametrize (
198275 "create_tmp_simulation_config_file" ,
0 commit comments