@@ -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