diff --git a/doc/whats_new.rst b/doc/whats_new.rst index efe2486c54..8c4d938eb4 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -68,6 +68,9 @@ Changelog - Add function :func:`~hnn_core/params/convert_to_json` to convert legacy param and json files to new json format, by `George Dang`_ in :gh:`772` +- Add :class:`~hnn_core.BatchSimulate` for batch simulation capability, + by `Abdul Samad Siddiqui`_ in :gh:`782`. + Bug ~~~ - Fix inconsistent connection mapping from drive gids to cell gids, by diff --git a/hnn_core/batch_simulate.py b/hnn_core/batch_simulate.py index 824b81e1ae..6cb6f1f2b7 100644 --- a/hnn_core/batch_simulate.py +++ b/hnn_core/batch_simulate.py @@ -13,7 +13,8 @@ class BatchSimulate: def __init__(self, set_params, net_name='jones', tstop=170, - dt=0.025, n_trials=1): + dt=0.025, n_trials=1, record_vsec=False, + record_isec=False, postproc=False): """ Initialize the BatchSimulate class. @@ -30,12 +31,32 @@ def __init__(self, set_params, net_name='jones', tstop=170, The time step for the simulation. Default is 0.025 ms. n_trials : int, optional The number of trials for the simulation. Default is 1. + record_vsec : 'all' | 'soma' | False + Option to record voltages from all sections ('all'), or just + the soma ('soma'). Default: False. + record_isec : 'all' | 'soma' | False + Option to record voltages from all sections ('all'), or just + the soma ('soma'). Default: False. + postproc : bool + 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. + Note that this setting + only affects the dipole waveforms, and not somatic voltages, + possible extracellular recordings etc. + The preferred way is to use the + :meth:`~hnn_core.dipole.Dipole.smooth` and + :meth:`~hnn_core.dipole.Dipole.scale` methods instead. + Default: False. """ self.set_params = set_params self.net_name = net_name self.tstop = tstop self.dt = dt self.n_trials = n_trials + self.record_vsec = record_vsec + self.record_isec = record_isec + self.postproc = postproc def run(self, param_grid, return_output=True, combinations=True, n_jobs=1): """ @@ -122,8 +143,13 @@ def _run_single_sim(self, param_values): net = calcium_model() print(param_values) self.set_params(param_values, net) - dpl = simulate_dipole(net, tstop=self.tstop, dt=self.dt, - n_trials=self.n_trials) + dpl = simulate_dipole(net, + tstop=self.tstop, + dt=self.dt, + n_trials=self.n_trials, + record_vsec=self.record_vsec, + record_isec=self.record_isec, + postproc=self.postproc) return {'net': net, 'dpl': dpl, 'param_values': param_values} diff --git a/hnn_core/tests/test_batch_simulate.py b/hnn_core/tests/test_batch_simulate.py index 775e12aa9e..c120dbbda1 100644 --- a/hnn_core/tests/test_batch_simulate.py +++ b/hnn_core/tests/test_batch_simulate.py @@ -36,7 +36,7 @@ def set_params(param_values, net): @pytest.fixture def param_grid(): - """Returns a dictionary representing a parameter grid for + """Returns a dictionary representing a parameter grid for batch simulation.""" return { 'weight_basket': np.logspace(-4 - 1, 2),