dc_generator#
- class brainpy.state.dc_generator(in_size=1, amplitude=Quantity(0., 'pA'), start=Quantity(0., 'ms'), stop=None, origin=Quantity(0., 'ms'), name=None)#
DC current generator – NEST-compatible stimulation device.
Generate a constant current pulse and gate it with a half-open activity window using NEST-compatible parameter semantics.
1. Model equations
For each output channel, the generated current is
\[\begin{split}I(t) = \begin{cases} A & \text{if } t_{\mathrm{start}} \le t < t_{\mathrm{stop}}, \\ 0 & \text{otherwise}, \end{cases}\end{split}\]where \(A\) is
amplitudeand\[t_{\mathrm{start}} = t_0 + t_{\mathrm{start,rel}}, \qquad t_{\mathrm{stop}} = t_0 + t_{\mathrm{stop,rel}}.\]If
stop is None, then \(t_{\mathrm{stop}} = +\infty\) and the generator runs indefinitely from \(t_{\mathrm{start}}\) onward.2. Timing semantics, assumptions, and constraints
The active interval is the half-open set \([t_{\mathrm{start}},\, t_{\mathrm{stop}})\). Since neuron states are advanced from
ttot + dtin each step, a current enabled at \(t_{\mathrm{start}}\) first affects the membrane trajectory after that update (observable at \(t_{\mathrm{start}} + dt\)); the last active update starts at \(t_{\mathrm{stop}} - dt\).This implementation is stateless:
update()recomputes a boolean mask at each call using the environment time, then appliesu.math.where(). Assumptions and constraints:If
stop <= start(after addingorigin), the active set is empty and the output is identically zero for allt.amplitude,start,stop, andoriginmust each be broadcastable toself.varshape; the shape check is performed bybraintools.init.param()during__init__().Unitless numerics in
start,stop, andoriginare treated as milliseconds; unitless numerics inamplitudeare treated as pA.
3. Computational implications
Per-call complexity is \(O(\prod \mathrm{varshape})\), dominated by one broadcast allocation
amplitude * ones(varshape)and one masked selection. No recurrent state is maintained, so the model is fully replayable given the same environment time sequence.- Parameters:
in_size (
Size, optional) – Output size/shape specification understood bybrainstate.nn.Dynamics. The emitted current shape isself.varshapederived fromin_size. Default is1.amplitude (
ArrayLike, optional) – Constant current amplitude \(A\) (typically pA). Scalars or arrays are accepted and broadcast toself.varshapeviabraintools.init.param(). Default is0. * u.pA.start (
ArrayLike, optional) – Relative start time \(t_{\mathrm{start,rel}}\) (typically ms), broadcast toself.varshape. Effective start isorigin + start(inclusive). Default is0. * u.ms.stop (
ArrayLikeorNone, optional) – Relative stop time \(t_{\mathrm{stop,rel}}\) (typically ms), broadcast toself.varshapewhen provided. Effective stop isorigin + stop(exclusive).Nonemeans the pulse never deactivates. Default isNone.origin (
ArrayLike, optional) – Time origin \(t_0\) (typically ms) added tostartandstop, broadcast toself.varshape. Default is0. * u.ms.name (
strorNone, optional) – Optional node name passed tobrainstate.nn.Dynamics.
Parameter Mapping
Table 23 Parameter mapping to model symbols# Parameter
Default
Math symbol
Semantics
amplitude0. * u.pA\(A\)
Constant current value emitted during the active window.
start0. * u.ms\(t_{\mathrm{start,rel}}\)
Relative start time; effective inclusive lower bound is
origin + start.stopNone\(t_{\mathrm{stop,rel}}\)
Relative stop time; effective exclusive upper bound is
origin + stop.origin0. * u.ms\(t_0\)
Global offset applied to both window boundaries.
- Raises:
ValueError – If
in_sizeis invalid or if any array-like parameter cannot be broadcast toself.varshapebybraintools.init.param().TypeError – If invalid unitful/unitless arithmetic is provided (for example, values with incompatible units in current or time comparisons).
Notes
NEST recommends using neuron parameter
I_ewhen a constant bias current is needed throughout the full simulation. Usedc_generatorwhen the current must be switched on/off at specific simulation times.See also
ac_generatorSinusoidal current stimulation device.
step_current_generatorPiecewise-constant current stimulation.
noise_generatorGaussian white-noise current stimulation.
References
Examples
>>> import brainpy >>> import brainstate >>> import saiunit as u >>> with brainstate.environ.context(dt=0.1 * u.ms): ... gen = brainpy.state.dc_generator( ... in_size=1, ... amplitude=500.0 * u.pA, ... start=10.0 * u.ms, ... stop=50.0 * u.ms, ... ) ... with brainstate.environ.context(t=10.0 * u.ms): ... current = gen.update() ... _ = current.shape
>>> import brainpy >>> import saiunit as u >>> dc1 = brainpy.state.dc_generator( ... amplitude=300.0 * u.pA, ... start=0.0 * u.ms, ... stop=100.0 * u.ms, ... ) >>> dc2 = brainpy.state.dc_generator( ... amplitude=-200.0 * u.pA, ... start=50.0 * u.ms, ... stop=150.0 * u.ms, ... )
- update()[source]#
Compute the window-gated constant current at environment time
t.- Returns:
current – Current-like quantity with shape
self.varshapeand units inherited fromamplitude. Values equalamplitudeon channels whereorigin + start <= t < origin + stop(ort >= origin + startwhenstop is None), and zero elsewhere.- Return type:
jax.Array- Raises:
Notes
Start is inclusive and stop is exclusive, matching NEST semantics. If
stop <= start(after addingorigin), the active set is empty and the output is identically zero for allt. The model carries no internal state, so repeated calls with the same environment time produce identical results.See also
dc_generatorClass-level parameter definitions and model equations.
ac_generator.updateWindowed sinusoidal-current update rule.