5
5
6
6
7
7
8
+ import json
8
9
import numpy as np
9
10
import os
10
11
from joblib import Parallel , delayed , parallel_config
13
14
from .externals .mne import _validate_type , _check_option
14
15
from .dipole import simulate_dipole
15
16
from .network_models import jones_2009_model
17
+ from .hnn_io import dict_to_network
16
18
17
19
18
20
class BatchSimulate (object ):
@@ -24,7 +26,7 @@ def __init__(self, set_params, net=jones_2009_model(), tstop=170,
24
26
save_dpl = True , save_spiking = False ,
25
27
save_lfp = False , save_voltages = False ,
26
28
save_currents = False , save_calcium = False ,
27
- clear_cache = False ):
29
+ clear_cache = False , net_json = None ):
28
30
"""Initialize the BatchSimulate class.
29
31
30
32
Parameters
@@ -100,6 +102,9 @@ def __init__(self, set_params, net=jones_2009_model(), tstop=170,
100
102
clear_cache : bool, optional
101
103
Whether to clear the results cache after saving each batch.
102
104
Default is False.
105
+ net_json : str, optional
106
+ The path to a JSON file to create the network model. If provided,
107
+ this will override the `net` parameter. Default is None.
103
108
Notes
104
109
-----
105
110
When `save_output=True`, the saved files will appear as
@@ -127,6 +132,8 @@ def __init__(self, set_params, net=jones_2009_model(), tstop=170,
127
132
_validate_type (save_currents , types = (bool ,), item_name = 'save_currents' )
128
133
_validate_type (save_calcium , types = (bool ,), item_name = 'save_calcium' )
129
134
_validate_type (clear_cache , types = (bool ,), item_name = 'clear_cache' )
135
+ _validate_type (net_json , types = ('path-like' , None ),
136
+ item_name = 'net_json' )
130
137
131
138
if set_params is not None and not callable (set_params ):
132
139
raise TypeError ("set_params must be a callable function" )
@@ -154,6 +161,7 @@ def __init__(self, set_params, net=jones_2009_model(), tstop=170,
154
161
self .save_currents = save_currents
155
162
self .save_calcium = save_calcium
156
163
self .clear_cache = clear_cache
164
+ self .net_json = net_json
157
165
158
166
def run (self , param_grid , return_output = True ,
159
167
combinations = True , n_jobs = 1 , backend = 'loky' ,
@@ -295,7 +303,14 @@ def _run_single_sim(self, param_values):
295
303
- `param_values`: The parameter values used for the simulation.
296
304
"""
297
305
298
- net = self .net .copy ()
306
+ if isinstance (self .net_json , str ):
307
+ with open (self .net_json , 'r' ) as file :
308
+ net_data = json .load (file )
309
+ net = dict_to_network (net_data )
310
+ else :
311
+ net = self .net
312
+ net = net .copy ()
313
+
299
314
self .set_params (param_values , net )
300
315
301
316
results = {'net' : net , 'param_values' : param_values }
0 commit comments