Skip to content

Commit

Permalink
Add BatchSimulate parameters and docstrings, update changelog
Browse files Browse the repository at this point in the history
Signed-off-by: samadpls <[email protected]>
  • Loading branch information
samadpls committed Jul 2, 2024
1 parent bd579b7 commit 1277c94
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions hnn_core/batch_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion hnn_core/tests/test_batch_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 1277c94

Please sign in to comment.