Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 08179dd

Browse files
Merge branch 'BlueBrain:master' into master
2 parents 38dc89a + 660aa3a commit 08179dd

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

bluepyopt/ephys/mechanisms.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,19 @@ def instantiate_determinism(self, deterministic, icell, isec, sim):
123123
(self.suffix),
124124
1 if deterministic else 0)
125125

126-
if not deterministic:
127-
# Set the seeds
128-
short_secname = sim.neuron.h.secname(sec=isec).split('.')[-1]
129-
for iseg in isec:
130-
seg_name = '%s.%.19g' % (short_secname, iseg.x)
131-
getattr(sim.neuron.h,
132-
"setdata_%s" % self.suffix)(iseg.x, sec=isec)
133-
seed_id1 = icell.gid
134-
seed_id2 = self.hash_py(seg_name)
135-
getattr(
136-
sim.neuron.h,
137-
"setRNG_%s" % self.suffix)(seed_id1, seed_id2)
126+
# Set the seeds even when deterministic,
127+
# that way neuron's psection does not crash
128+
# when encountering a stoch mech var that is not set (e.g. rng)
129+
short_secname = sim.neuron.h.secname(sec=isec).split('.')[-1]
130+
for iseg in isec:
131+
seg_name = '%s.%.19g' % (short_secname, iseg.x)
132+
getattr(sim.neuron.h,
133+
"setdata_%s" % self.suffix)(iseg.x, sec=isec)
134+
seed_id1 = icell.gid
135+
seed_id2 = self.hash_py(seg_name)
136+
getattr(
137+
sim.neuron.h,
138+
"setRNG_%s" % self.suffix)(seed_id1, seed_id2)
138139
else:
139140
if not deterministic:
140141
# can't do this for non-Stoch channels

bluepyopt/ephys/protocols.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ def __init__(
134134
name=None,
135135
stimuli=None,
136136
recordings=None,
137-
cvode_active=None):
137+
cvode_active=None,
138+
deterministic=False):
138139
"""Constructor
139140
140141
Args:
@@ -143,12 +144,15 @@ def __init__(
143144
recordings (list of Recordings): Recording objects used in the
144145
protocol
145146
cvode_active (bool): whether to use variable time step
147+
deterministic (bool): whether to force all mechanism
148+
to be deterministic
146149
"""
147150

148151
super(SweepProtocol, self).__init__(name)
149152
self.stimuli = stimuli
150153
self.recordings = recordings
151154
self.cvode_active = cvode_active
155+
self.deterministic = deterministic
152156

153157
@property
154158
def total_duration(self):
@@ -161,6 +165,26 @@ def subprotocols(self):
161165

162166
return collections.OrderedDict({self.name: self})
163167

168+
def adjust_stochasticity(func):
169+
"""Decorator method to adjust the stochasticity of the mechanisms"""
170+
def inner(self, cell_model, param_values, **kwargs):
171+
"""Inner function"""
172+
previous_stoch_state = []
173+
if self.deterministic:
174+
for mech in cell_model.mechanisms:
175+
previous_stoch_state.append(mech.deterministic)
176+
mech.deterministic = True
177+
178+
responses = func(self, cell_model, param_values, **kwargs)
179+
180+
if self.deterministic:
181+
for i, mech in enumerate(cell_model.mechanisms):
182+
mech.deterministic = previous_stoch_state[i]
183+
184+
return responses
185+
186+
return inner
187+
164188
def _run_func(self, cell_model, param_values, sim=None):
165189
"""Run protocols"""
166190

@@ -198,6 +222,7 @@ def _run_func(self, cell_model, param_values, sim=None):
198222
"".join(
199223
traceback.format_exception(*sys.exc_info())))
200224

225+
@adjust_stochasticity
201226
def run(
202227
self,
203228
cell_model,
@@ -295,7 +320,8 @@ def __init__(
295320
step_stimulus=None,
296321
holding_stimulus=None,
297322
recordings=None,
298-
cvode_active=None):
323+
cvode_active=None,
324+
deterministic=False):
299325
"""Constructor
300326
301327
Args:
@@ -304,6 +330,8 @@ def __init__(
304330
recordings (list of Recordings): Recording objects used in the
305331
protocol
306332
cvode_active (bool): whether to use variable time step
333+
deterministic (bool): whether to force all mechanism
334+
to be deterministic
307335
"""
308336

309337
super(StepProtocol, self).__init__(

0 commit comments

Comments
 (0)