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, baseline_correction=True)[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:
neymotin_2020_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
neymotin_2020_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, default=False
Deprecated. If True, smoothing (
dipole_smooth_win) and scaling (dipole_scalefctr) values are read from theNetwork’s parameter file, and applied to the dipole objects before returning (the defaultNetworkparameter file, hnn_core/param/default.json, uses a smoothing value of 30 ms and a scaling factor of 3000). Note that this setting only affects the dipole waveforms, and not somatic voltages, possible extracellular recordings etc. The preferred way is to use thesmooth()andscale()methods after the simulation is run instead.- 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.
- baseline_correctionbool, default=True
Whether to apply the
Network’s baseline correction method, which is determined byNetwork._model_variant.
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=True)[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.- verbosebool
If True, print build steps and simulation progress to console. Default: True.
- 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')[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.
- 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.