hnn_core.batch_simulate.BatchSimulate#
- class hnn_core.batch_simulate.BatchSimulate(set_params, net=<Network | 35 L2_basket cells 100 L2_pyramidal cells 35 L5_basket cells 100 L5_pyramidal cells>, tstop=170, dt=0.025, n_trials=1, save_folder='./sim_results', batch_size=100, overwrite=True, save_outputs=False, save_dpl=True, save_spiking=False, save_lfp=False, save_voltages=False, save_currents=False, save_calcium=False, record_vsec=False, record_isec=False, postproc=False, clear_cache=False, summary_func=None)[source]#
The BatchSimulate class.
- Parameters:
- set_paramsfunc
User-defined function that sets parameters in network drives.
set_params(net, params) -> Nonewhere
netis a Network object andparamsis a dictionary of the parameters that will be set inside the function.- netNetwork object, optional
The network model to use for simulations. Examples include the returned value of the following functions:
jones_2009_model: A network model based on Jones et al. (2009).law_2021_model: A network model based on Law et al. (2021).
calcium_model: A network model incorporating calcium dynamics.
Default is
jones_2009_model().- tstopfloat, optional
The stop time for the simulation. Default is 170 ms.
- dtfloat, optional
The time step for the simulation. Default is 0.025 ms.
- n_trialsint, optional
The number of trials for the simulation. Default is 1.
- save_folderstr, optional
The path to save the simulation outputs. Default is ‘./sim_results’.
- batch_sizeint, optional
The maximum number of simulations saved in a single file. Default is 100.
- overwritebool, optional
Whether to overwrite existing files and create file paths if they do not exist. Default is True.
- save_outputsbool, optional
Whether to save the simulation outputs to files. Default is False.
- save_dplbool, optional
If True, save dipole results. Note, save_outputs must be True. Default: True.
- save_spikingbool, optional
If True, save spiking results. Note, save_outputs must be True. Default: False.
- save_lfpbool, optional
If True, save local field potential (lfp) results. Note, save_outputs must be True. Default: False.
- save_voltagesbool, optional
If True, save voltages results. Note, save_outputs must be True. Default: False.
- save_currentsbool, optional
If True, save currents results. Note, save_outputs must be True. Default: False.
- save_calciumbool, optional
If True, save calcium concentrations. Note, save_outputs must be True. Default: False.
- record_vsec{False, ‘all’, ‘soma’}
Option to record voltages from all sections (‘all’), or just the soma (‘soma’). Default: False.
- record_isec{False, ‘all’, ‘soma’}
Option to record voltages from all sections (‘all’), or just the soma (‘soma’). Default: False.
- postprocbool, optional
If True, smoothing (
dipole_smooth_win) and scaling (dipole_scalefctr) values are read from the parameter file, and applied to the dipole objects before returning. Default: False.- clear_cachebool, optional
Whether to clear the results cache after saving each batch. Default is False.
- summary_funcfunc, optional
A function to calculate summary statistics from the simulation results. Default is None.
Methods
Load all simulation results from the files in self.save_folder.
load_results(file_path[, return_data])Load simulation results from a file.
run(param_grid[, return_output, ...])Run batch simulations.
simulate_batch(param_combinations[, n_jobs, ...])Simulate a batch of parameter sets in parallel.
Notes
When
save_output=True, the saved files will appear assim_run_{start_idx}-{end_idx}.npzin the specified save_folder directory. The start_idx and end_idx indicate the range of simulation indices contained in each file. Each file will contain a maximum of batch_size simulations, split evenly among the available files. Ifoverwrite=True, existing files with the same name will be overwritten.- load_all_results()[source]#
Load all simulation results from the files in self.save_folder.
- Returns:
- all_resultslist
List of dictionaries containing all loaded simulation results.
- load_results(file_path, return_data=None)[source]#
Load simulation results from a file.
- Parameters:
- file_pathstr
The path to the file containing the simulation results.
- return_datalist of str, optional
List of data types to return. If None, returns the types specified during initialization. Defaults to None.
- Returns:
- resultsdict
Dictionary containing the loaded results and parameter values.
- run(param_grid, return_output=True, combinations=True, n_jobs=1, backend='loky', verbose=50)[source]#
Run batch simulations.
- Parameters:
- param_griddict
Dictionary with parameter names and ranges.
- return_outputbool, optional
Whether to return the simulation outputs. Default is True.
- combinationsbool, optional
Whether to generate the Cartesian product of the parameter ranges. If False, generate combinations based on corresponding indices. Default is True.
- n_jobsint, optional
Number of parallel jobs. Default is 1.
- backendstr or joblib.parallel.ParallelBackendBase instance, optional
The parallel backend to use. Can be one of loky,
threading,multiprocessing, or dask. WARNING: currently only loky is completely operationable; all other backends are in development. Default is loky.- verboseint, optional
The verbosity level for parallel execution. Default is 50.
- Returns:
- resultsdict
Dictionary containing ‘summary_statistics’ and optionally ‘simulated_data’. ‘simulated_data’ may include keys: ‘dpl’, ‘lfp’, ‘spikes’, ‘voltages’, ‘param_values’, ‘net’, ‘times’.
Notes
Return content depends on summary_func, return_output, and clear_cache settings.
- simulate_batch(param_combinations, n_jobs=1, backend='loky', verbose=50)[source]#
Simulate a batch of parameter sets in parallel.
- Parameters:
- param_combinationslist
List of parameter combinations.
- n_jobsint, optional
Number of parallel jobs. Default is 1.
- backendstr or joblib.parallel.ParallelBackendBase instance, optional
The parallel backend to use. Can be one of loky,
threading,multiprocessing, or dask. WARNING: currently only loky is completely operationable; all other backends are in development. Default is loky.- verboseint, optional
The verbosity level for parallel execution. Default is 50.
- Returns:
- res: list
List of dictionaries containing simulation results. Each dictionary contains the following keys along with their associated values:
net: The network model used for the simulation.
dpl: The simulated dipole.
param_values: The parameter values used for the simulation.