2
2
import numpy as np
3
3
import numpy .testing as npt
4
4
import unittest .mock
5
- import tempfile
6
5
from pathlib import Path
7
6
8
7
from tests .utils import defaultdict_to_standard_types
9
- from ..conftest import RINGTEST_DIR , NGV_DIR , PLATFORM_SYSTEM
8
+ from ..conftest import NGV_DIR , PLATFORM_SYSTEM
10
9
from neurodamus import Neurodamus
11
10
12
- TMP_FOLDER = tempfile .mkdtemp ()
13
-
14
-
15
- @pytest .fixture (autouse = True )
16
- def change_test_dir (monkeypatch ):
17
- """
18
- All tests in this file are using the same working directory, i.e TMP_FOLDER
19
- Because test_dynamic_distribute requires memory_per_metype.json generated in the previous test
20
- """
21
- monkeypatch .chdir (TMP_FOLDER )
22
-
23
11
12
+ @pytest .mark .parametrize ("create_tmp_simulation_config_file" , [
13
+ {
14
+ "simconfig_fixture" : "ringtest_baseconfig" ,
15
+ },
16
+ ], indirect = True )
24
17
@pytest .mark .forked
25
- def test_dry_run_memory_use ():
26
- nd = Neurodamus (str (RINGTEST_DIR / "simulation_config.json" ), dry_run = True , num_target_ranks = 2 )
27
-
18
+ def test_dry_run_memory_use (create_tmp_simulation_config_file ):
19
+ nd = Neurodamus (create_tmp_simulation_config_file , dry_run = True , num_target_ranks = 2 )
28
20
nd .run ()
29
21
30
22
isMacOS = PLATFORM_SYSTEM == "Darwin"
@@ -40,9 +32,14 @@ def test_dry_run_memory_use():
40
32
assert nd ._dry_run_stats .suggested_nodes > 0
41
33
42
34
35
+ @pytest .mark .parametrize ("create_tmp_simulation_config_file" , [
36
+ {
37
+ "simconfig_fixture" : "ringtest_baseconfig" ,
38
+ },
39
+ ], indirect = True )
43
40
@pytest .mark .forked
44
- def test_dry_run_distribute_cells ():
45
- nd = Neurodamus (str ( RINGTEST_DIR / "simulation_config.json" ) , dry_run = True , num_target_ranks = 2 )
41
+ def test_dry_run_distribute_cells (create_tmp_simulation_config_file ):
42
+ nd = Neurodamus (create_tmp_simulation_config_file , dry_run = True , num_target_ranks = 2 )
46
43
nd .run ()
47
44
48
45
# Test allocation
@@ -89,31 +86,51 @@ def test_dry_run_distribute_cells():
89
86
}
90
87
assert rank_allocation_standard == expected_allocation
91
88
92
- Path (("allocation_r1_c1.pkl.gz" )).unlink (missing_ok = True )
93
- Path (("allocation_r2_c1.pkl.gz" )).unlink (missing_ok = True )
94
-
95
89
96
90
@pytest .mark .parametrize ("create_tmp_simulation_config_file" , [
97
91
{
98
92
"simconfig_fixture" : "ringtest_baseconfig" ,
99
93
},
100
94
], indirect = True )
101
95
@pytest .mark .forked
102
- def test_dry_run_dynamic_distribute (create_tmp_simulation_config_file ):
96
+ def test_dry_run_lb_mode_memory (create_tmp_simulation_config_file , copy_memory_files ):
103
97
nd = Neurodamus (create_tmp_simulation_config_file , dry_run = False , lb_mode = "Memory" ,
104
98
num_target_ranks = 1 )
105
99
106
100
rank_alloc , _ , _ = nd ._dry_run_stats .distribute_cells_with_validation (2 , 1 )
107
101
rank_allocation_standard = defaultdict_to_standard_types (rank_alloc )
108
102
expected_allocation = {
109
103
'RingA' : {
110
- (0 , 0 ): [1 ],
111
- (1 , 0 ): [2 , 3 ]
104
+ (0 , 0 ): [1 , 3 ],
105
+ (1 , 0 ): [2 ]
112
106
}
113
107
}
114
108
assert rank_allocation_standard == expected_allocation
115
109
116
110
111
+ @pytest .mark .parametrize ("create_tmp_simulation_config_file" , [
112
+ {
113
+ "simconfig_fixture" : "ringtest_baseconfig" ,
114
+ },
115
+ ], indirect = True )
116
+ @pytest .mark .forked
117
+ def test_dry_run_lb_mode_memory_fail (create_tmp_simulation_config_file ):
118
+ with pytest .raises (FileNotFoundError ,
119
+ match = "No such file cell_memory_usage.json. "
120
+ "Neurodamus must be run with --dry-run mode before proceeding." ):
121
+ Neurodamus (create_tmp_simulation_config_file , dry_run = False , lb_mode = "Memory" ,
122
+ num_target_ranks = 1 )
123
+
124
+ with Path ("cell_memory_usage.json" ).open ('w' ):
125
+ pass
126
+
127
+ with pytest .raises (FileNotFoundError ,
128
+ match = "No such file memory_per_metype.json. "
129
+ "Neurodamus must be run with --dry-run mode before proceeding." ):
130
+ Neurodamus (create_tmp_simulation_config_file , dry_run = False , lb_mode = "Memory" ,
131
+ num_target_ranks = 1 )
132
+
133
+
117
134
@pytest .mark .forked
118
135
def test_dry_run_ngv_fail ():
119
136
with pytest .raises (Exception , match = "Dry run not available for ngv circuit" ):
0 commit comments