Built-in mechanisms#

Use dendra.mod or import from dendra.models.mod.

Distributed hh and pas use conductance density in S/cm² and return current density in mA/cm². Point-process alphasynapse, alphasynapse_d, expsyn, and exp2syn use conductance in µS and return lumped current in nA before Dendra’s area normalization. For the event-driven point processes, a bare connection weight=0.05 means 0.05 µS; do not multiply it by dendra.units.uS. See Units used in Dendra for the complete contract.

class alphasynapse(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A synaptic mechanism that uses the alpha function to model synaptic conductance. The conductance g is calculated using the alpha function based on the time since the synapse was activated.

Parameters:
  • onset (float) – The time (in ms) when the synapse is activated. Default is 0.0 ms.

  • tau (float) – The time constant (in ms) of the alpha function. Default is 0.1 ms.

  • gmax (float) – The maximum conductance (in µS) of the synapse. Default is 0.0 µS.

  • e (float) – The reversal potential (in mV) of the synapse. Default is 0.0 mV.

Notes

This is a PointProcess: gmax and g are numerical values in µS, while i(v) returns lumped, outward-positive current in nA. Dendra converts the current to mA/cm² using target compartment area during current assembly.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

alpha_d(x, smooth_eps=1e-06)[source]#

Smooth non-negative alpha function.

Parameters:
  • x (torch.Tensor) – Dimensionless time (t - onset) / tau.

  • smooth_eps (float or torch.Tensor) – Positive smoothing width for the smooth approximation to max(x, 0).

Returns:

x_pos * exp(1 - x_pos), where x_pos is a smooth approximation to the positive part of x.

Return type:

torch.Tensor

class alphasynapse_d(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

Differentiable analog of alphasynapse.

The original alphasynapse.alpha uses hard support checks x < 0 and x > 10. This analog removes those boolean cutoffs by replacing x with a smooth non-negative approximation before evaluating the alpha waveform:

\[x_+ \approx \max(x, 0), \qquad \alpha_d(x) = x_+ \exp(1 - x_+).\]

The result is smooth at onset and naturally decays to zero for large positive x without a hard upper cutoff.

Parameters:
  • onset (float) – Activation onset time in ms. Default is 0.0 ms.

  • tau (float) – Alpha-function time constant in ms. Default is 0.1 ms.

  • gmax (float) – Maximum conductance scale in µS. Default is 0.0 µS.

  • e (float) – Reversal potential in mV. Default is 0.0 mV.

  • smooth_eps (float) – Width of the smooth non-negative approximation in dimensionless alpha time units. Smaller values more closely approximate max(x, 0). Default is 1e-6.

Notes

This is a PointProcess: gmax and g are numerical values in µS, while i(v) returns lumped, outward-positive current in nA. Dendra converts the current to mA/cm² using target compartment area during current assembly.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class apcount(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A mechanism that counts the number of action potentials (spikes). The spike is detected when the membrane potential v crosses a specified threshold from below.

Parameters:

threshold (float) – The membrane potential threshold for spike detection. Default is 0.0 mV.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class apcount_d(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

Differentiable analog of apcount with hard-forward, surrogate-backward spike counting.

The forward pass preserves event/count semantics:

  • spikes is exactly a 0/1 upward-threshold-crossing indicator.

  • n is exactly the accumulated number of upward crossings, represented as a floating tensor so it can carry an autograd graph.

The backward pass uses a straight-through estimator (STE), following the same pattern as spikedetect: the emitted hard event has the forward value of the boolean crossing, but gradients are supplied by a smooth onset surrogate.

Let

\[g_t = \sigma((v_t - \theta) / \tau_g)\]

and let h_prev store the previous gate. The hard crossing is

\[s_t^\mathrm{hard} = \mathbf{1}[v_t > \theta] \;\mathbf{1}[v_{t-1} \le \theta],\]

implemented using the hard boolean state active. The surrogate used for gradients is

\[s_t^\mathrm{soft} = \max(g_t - g_{t-1}, 0).\]

The buffer-backed spike variable is

\[s_t = s_t^\mathrm{hard} + \alpha (s_t^\mathrm{soft} - \operatorname{stopgrad}(s_t^\mathrm{soft})),\]

so its forward value is exactly hard while its backward gradient is shaped by the smooth gate. The count is then n <- n + spikes.

Parameters:
  • threshold (float) – Membrane-potential threshold in mV. Default is 0.0 mV.

  • tau_gate (float) – Smoothness/steepness of the voltage threshold gate in mV. Smaller values make the surrogate sharper but increase gradient magnitude near threshold. Default is 0.5 mV.

  • ste_scale (float) – Multiplicative scale applied to the surrogate-gradient contribution. Default is 1.0.

  • variables (Buffer)

  • ------------------

  • n (torch.Tensor) – Accumulated hard-forward spike count with surrogate gradients.

  • spikes (torch.Tensor) – Current-step hard-forward upward-crossing indicator with surrogate gradients.

  • active (torch.Tensor) – Boolean hard state indicating whether the previous voltage was above threshold.

  • h_prev (torch.Tensor) – Previous smooth threshold gate used only for the surrogate gradient.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class exp2syn(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A synaptic mechanism that uses a double-exponential function to model synaptic conductance. The conductance is modeled using two state variables A and B, each following an exponential decay with different time constants.

Parameters:
  • e (float) – The reversal potential (in mV) of the synapse. Default is 0.0 mV.

  • tau1 (float) – The rise time constant (in ms) of the synapse. Default is 0.1 ms.

  • tau2 (float) – The decay time constant (in ms) of the synapse. Default is 10.0 ms.

Notes

The synaptic conductance \(g\) is calculated as the difference between the two state variables, \(g = B - A\). The lumped current is \(i = g(V-e)\); the reversal potential does not scale the conductance.

This is a PointProcess. Event weights, \(A\), \(B\), and \(g\) are numerical values in µS; for example, weight=0.05 means 0.05 µS. Do not multiply such a weight by dendra.units.uS. The normalized event weight is added to both state variables. i(v) returns lumped, outward-positive current in nA, which Dendra converts to mA/cm² using compartment area during current assembly.

The factor for scaling the weights is calculated based on the time constants of the two states, following the formula

\[\text{factor} = \frac{1}{-\exp\left(-\frac{t_p}{\tau_1}\right) + \exp\left(-\frac{t_p}{\tau_2}\right)}\]

where \(t_p\) is the time point at which the two exponentials are equal:

\[t_p = \frac{\tau_1 \tau_2}{\tau_2 - \tau_1} \log\left(\frac{\tau_2}{\tau_1}\right)\]

This ensures that the synaptic response is properly normalized based on the time constants.

As in NEURON’s Exp2Syn, the effective ratio tau1 / tau2 is limited to [1e-9, 0.9999] during initialization. Equal, nearly equal, or reversed time constants therefore approach a normalized alpha-synapse response instead of producing a division by zero. Both time constants must be positive and finite; invalid values raise ValueError in eager execution or a tensor assertion RuntimeError in compiled execution. For low precision dtypes, the bounds are tightened to the nearest representable values strictly between zero and one.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class expsyn(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A synaptic mechanism that uses a single-exponential function to model synaptic conductance.

Parameters:
  • e (float) – The reversal potential (in mV) of the synapse. Default is 0.0 mV.

  • tau (float) – The time constant (in ms) of the synapse. Default is 0.1 ms.

Notes

This is a PointProcess. Synaptic event weights and the state variable \(g\) are numerical values in µS; for example, weight=0.05 means 0.05 µS. Do not multiply such a weight by dendra.units.uS. Each received weight is added to \(g\), which then decays exponentially with time constant \(\tau\).

i(v) returns lumped, outward-positive current in nA. Dendra converts it to mA/cm² using the target compartment’s membrane area during current assembly.

Optionally, the decay of \(g\) can be written as

\[g(t) = g_0 \exp\left(-\frac{t}{\tau}\right)\]

where \(g_0\) is the conductance immediately after synaptic activation.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class fire_r(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A VoltageProcess that implements a leaky integrate-and-fire neuron model with refractory period. When the membrane potential v crosses the specified threshold, it is reset to the resting potential and enters a refractory period during which it cannot spike again.

Parameters:
  • threshold (float) – The membrane potential threshold for spike detection. Default is -50.0 mV.

  • rest (float) – The resting membrane potential (in mV) to reset to after a spike. Default is -65.0 mV.

  • refractory (float) – The duration (in ms) of the refractory period during which the neuron cannot spike again. Default is 5.0 ms.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class fire_r_d(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

Differentiable analog of fire_r with hard-forward, surrogate-backward refractory-reset semantics.

The forward pass preserves the original hard refractory logic:

  • is_refractory is a boolean refractory state.

  • time_refractory is the hard refractory countdown.

  • a new spike is emitted only when the cell is not refractory and v > threshold.

  • the returned voltage is exactly rest while refractory and exactly v otherwise.

The backward pass uses a smooth sigmoid threshold surrogate for the new-spike and reset decisions when the cell is available to spike. During an already active refractory period, the smooth reset gate is one, so the voltage is clamped to rest in both the forward and surrogate backward paths.

Parameters:
  • threshold (float) – Voltage threshold in mV. Default is -50.0 mV.

  • rest (float) – Reset/resting voltage in mV. Default is -65.0 mV.

  • refractory (float) – Hard refractory duration in ms. Default is 5.0 ms.

  • tau_gate (float) – Smoothness/steepness of the voltage threshold gate in mV. Default is 0.5 mV.

  • ste_scale (float) – Multiplicative scale applied to the surrogate-gradient contribution. Default is 1.0.

  • variables (Buffer)

  • ------------------

  • is_refractory (torch.Tensor) – Boolean hard refractory state used by the forward pass.

  • time_refractory (torch.Tensor) – Hard refractory countdown in ms.

  • spike_gate (torch.Tensor) – Hard-forward 0/1 new-spike indicator with a smooth surrogate gradient.

  • reset_gate (torch.Tensor) – Hard-forward 0/1 reset/refractory indicator with a smooth surrogate gradient.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class fire(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A VoltageProcess that implements a leaky integrate-and-fire neuron model. When the membrane potential v crosses the specified threshold, it is reset to the resting potential.

Parameters:
  • threshold (float) – The membrane potential threshold for spike detection. Default is -50.0 mV.

  • rest (float) – The resting membrane potential (in mV) to reset to after a spike. Default is -65.0 mV.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class fire_d(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

Differentiable analog of fire with hard-forward, surrogate-backward reset semantics.

The forward pass is exactly the original hard reset:

\[\begin{split}v_\mathrm{hard} = \begin{cases} V_\mathrm{rest}, & v > \theta \\ v, & v \le \theta. \end{cases}\end{split}\]

The backward pass is supplied by a smooth reset surrogate

\[r(v) = \sigma((v - \theta) / \tau_g), \qquad v_\mathrm{soft} = v + r(v)(V_\mathrm{rest} - v).\]

The returned voltage uses a straight-through estimator:

\[v_\mathrm{out} = \operatorname{stopgrad}(v_\mathrm{hard}) + \alpha (v_\mathrm{soft} - \operatorname{stopgrad}(v_\mathrm{soft})).\]

Therefore the forward voltage is identical to fire, while gradients are available near the threshold through the sigmoid reset gate.

Parameters:
  • threshold (float) – Voltage threshold in mV. Default is -50.0 mV.

  • rest (float) – Reset/resting voltage in mV. Default is -65.0 mV.

  • tau_gate (float) – Smoothness/steepness of the reset gate in mV. Default is 0.5 mV.

  • ste_scale (float) – Multiplicative scale applied to the surrogate-gradient contribution. Default is 1.0.

  • variables (Buffer)

  • ------------------

  • reset_gate (torch.Tensor) – Hard-forward 0/1 reset indicator with a smooth surrogate gradient.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class hh(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

The Hodgkin-Huxley neuron model with sodium, potassium, and leak channels. This model includes the dynamics of the gating variables m, h, and n which represent the activation and inactivation of sodium and potassium channels.

Parameters:
  • gnabar (float) – Maximum sodium conductance density in S/cm². Default is 0.12 S/cm² (equivalently 120 mS/cm²).

  • gkbar (float) – Maximum potassium conductance density in S/cm². Default is 0.036 S/cm² (equivalently 36 mS/cm²).

  • gl (float) – Leak conductance density in S/cm². Default is 0.0003 S/cm² (equivalently 0.3 mS/cm²).

  • ena (float) – Sodium reversal potential (in mV). Default is 50.0.

  • ek (float) – Potassium reversal potential (in mV). Default is -77.0.

  • el (float) – Leak reversal potential (in mV). Default is -54.3.

Notes

The single registered nonspecific current i(v) is the sum of sodium, potassium, and leak currents. i_affine_terms(v) supplies conductance density G in S/cm² and source density J in mA/cm², with the outward-positive convention i(v) = G*v - J. Dendra generates the ordinary current and conductance methods from these same coefficients.

There are no separate ina, ik, or il methods. Subclasses changing membrane physics should override i_affine_terms and redeclare AFFINE("i"), or provide their own current declaration.

Gates use rate coefficients m_a, m_b, h_a, h_b, n_a, n_b in x' = x_a - x_b*x.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class pas(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

A passive membrane mechanism that models a leak conductance.

Parameters:
  • g (float) – Leak conductance density in S/cm². Default is 0.001 S/cm² (equivalently 1 mS/cm²).

  • e (float) – The leak reversal potential (in mV). Default is -70.0.

Notes

i(v) returns outward-positive current density in mA/cm².

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class spikedetect(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

Upward threshold-crossing spike detector with straight-through (STE) gradients.

This mechanism detects a spike when the membrane potential crosses a threshold from below between two discrete simulation steps, and exposes the result as a buffer variable spikes.

The key design goal is:

  • Forward pass semantics are discrete and event-like (0/1 upward crossing).

  • Backward pass provides gradients w.r.t. `v` using a smooth surrogate.

Parameters:
  • threshold (float) – Voltage threshold \(\theta\) for spike detection, in mV. Default is 0.0 mV.

  • tau_gate (float) – Smoothness/steepness parameter \(\tau_g\) used to construct a differentiable gate from the voltage. Smaller values make the transition sharper (but may produce larger gradients). This is a voltage scale in mV; default is 0.5 mV.

  • ste_scale (float) – Dimensionless scalar \(\alpha\) multiplying the surrogate-gradient contribution. Default is 1.0.

Notes

Buffer variables

  • spikes: Spike indicator per compartment for the current step. Forward semantics are approximately 0/1 (hard), but it is differentiable w.r.t. v due to the STE construction.

  • h_prev: Memory of the previous step’s gate value (continuous in [0,1]).

Mathematics

Let \(v_t\) be the membrane potential at the current step and \(v_{t-1}\) the previous step. Define a continuous “gate”:

\[g_t = \sigma\left(\frac{v_t - \theta}{\tau_g}\right) \in (0,1),\]

where \(\sigma(\cdot)\) is the logistic sigmoid.

A hard upward crossing event is defined in terms of gate thresholding at 0.5:

\[s_t^{\text{hard}} = \mathbb{1}[g_t > 0.5]\;\mathbb{1}[g_{t-1} \le 0.5].\]

Since \(g_t > 0.5 \iff v_t > \theta\), this corresponds to “crossing the voltage threshold upward” in discrete time.

A soft surrogate onset (used only for gradients) is:

\[s_t^{\text{soft}} = \max(g_t - g_{t-1}, 0).\]

Finally, the emitted variable uses a straight-through estimator:

\[\text{spikes}_t = s_t^{\text{hard}} + \alpha\left(s_t^{\text{soft}} - \operatorname{stopgrad}(s_t^{\text{soft}})\right),\]

where \(\operatorname{stopgrad}(\cdot)\) denotes the detach/stop-gradient operator. This makes the forward value equal to \(s_t^{\text{hard}}\), while the backward gradient is shaped by \(s_t^{\text{soft}}\).

Differentiability and graph growth

  • spikes is differentiable w.r.t. v through the surrogate term.

  • The state h_prev stores the previous gate. If you do not want the autograd graph to backpropagate through time across many steps, you can optionally detach the memory update in advance.

Efficient usage in a Network

A common pattern is to compute threshold crossings once per presynaptic compartment and reuse them as the presynaptic driver for all synapses that originate from that presynaptic population.

  1. Insert this mechanism into all presynaptic compartments (population pre_pop), so that each compartment exposes mech.spikedetect.spikes.

  2. Connect synapses using pre_var=’mech.spikedetect.spikes’, e.g.:

net.connect_one_to_one(
    pre_pop,
    post_pop,
    post_pop.mech.synapse,
    threshold=None,                 # thresholding already done in spikedetect
    delay=delay,
    weight=weight,
    pre_var='mech.spikedetect.spikes'
)

Why this is efficient:

  • The threshold crossing computation is performed once for each presynaptic compartment in the accepted-step transition.

  • All outgoing synapses from that presynaptic population can read the already- computed spikes tensor, avoiding redundant per-synapse threshold checks.

In other words, spike detection becomes an O(#compartments) operation per step, rather than O(#synapses), which can be a significant speedup in dense networks.

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

Spike detector usage#

Use spikedetect when many outgoing connections share one voltage threshold. Connect from pre_var="mech.spikedetect.spikes" with threshold=None to avoid duplicate thresholding inside every NetCon.

Graded / continuous synapses#

Voltage-gated graded / continuous chemical synapses for Dendra.

This module implements a simple kinetic conductance synapse for graded or non-spiking chemical transmission. The formulation follows the kinetic-synapse modeling tradition of Destexhe, Mainen, and Sejnowski, in which synaptic conductance is derived from receptor or release-gate dynamics rather than from a prescribed spike-triggered waveform [1] [2].

The presynaptic release gate obeys

\[\dot{s} = \alpha T(V_\mathrm{pre})(1-s) - \beta s,\]

where the voltage-dependent release activation is

\[T(V_\mathrm{pre}) = \frac{1}{1 + \exp[-(V_\mathrm{pre}-\theta)/\sigma]}.\]

The postsynaptic current is conductance-based, using Dendra’s outward-current convention,

\[I_\mathrm{syn} = g_\mathrm{scale}\,g_\mathrm{pre}(V_\mathrm{post}-E_\mathrm{syn}).\]

Here g_pre is the weighted, summed analog presynaptic drive delivered by Network.connect_continuous(...).

Components#

graded_release_gate

Presynaptic mechanism that computes a dynamic voltage-dependent release gate s. Use pre_var="mech.graded_release_gate.s" when connecting.

graded_syn

Postsynaptic ContinuousSynapse that receives the analog input g_pre and contributes a conductance-based current.

sigmoid_release

Stateless voltage-to-release transform for instantaneous graded projections. Use this with connect_continuous(..., pre_var="v", transform=...) when an explicit presynaptic gate state is not needed.

Use cases#

This mechanism is useful for graded chemical synapses, voltage-dependent transmitter release, analog rate-like projections, and models in which the presynaptic cell exposes a continuous synaptic state rather than discrete spike events.

References

Examples

Example 1: explicit presynaptic gate state#

import dendra as dn
from dendra.models.networks import Network
from dendra.models.mod import graded_release_gate, graded_syn

pre = dn.Population(N=10, C=1, v_init=-60.0)
post = dn.Population(N=10, C=1, v_init=-65.0)

# Presynaptic graded transmitter/release gate.
pre.insert(
    graded_release_gate,
    theta=-20.0,   # mV, half-activation voltage
    sigma=2.0,     # mV, release steepness
    alpha=1.0,     # ms^-1, opening / activation rate scale
    beta=0.2,      # ms^-1, closing / deactivation rate
)

# Postsynaptic conductance-based continuous synapse.
post.insert(graded_syn, e=-80.0)  # inhibitory; use e=0 for excitatory

net = Network(dict(pre=pre, post=post))
net.connect_continuous(
    source=pre,
    target=post,
    synapse=post.mech.graded_syn,
    conn_spec={"rule": "one_to_one"},
    pre_var="mech.graded_release_gate.s",
    input="g_pre",
    weight=0.05,
    delay=0.0,
    reduce="sum",
)

net.initialize(dt=0.025)
net.run(tstop=100.0, progressbar=False)

Example 2: instantaneous voltage-to-release transform#

from dendra.models.mod import graded_syn, sigmoid_release

post.insert(graded_syn, e=0.0)

net.connect_continuous(
    source=pre,
    target=post,
    synapse=post.mech.graded_syn,
    conn_spec={"rule": "all_to_all"},
    pre_var="v",
    transform=sigmoid_release(theta=-20.0, sigma=2.0),
    input="g_pre",
    weight=0.001,
)

Notes on units#

graded_syn is a density-style ContinuousSynapse mechanism, not a PointProcess. That means its current is interpreted in the same density convention as ordinary Dendra mechanisms: current in mA/cm² and conductance in S/cm². With the dimensionless release gate s used in these examples, the connection weight and resulting g_pre are conductance densities in S/cm², while g_scale is dimensionless.

For lumped nA/µS point-process semantics, define a separate class that combines Dendra’s PointProcess with ContinuousSynapse.

class graded_release_gate(name, celsius, diameters, shape, shape_f, key=None, is_composable=False, support_spec=None, preserves_multiplicity=False, force_packed_support=False, additional_parameters=None, ic=None, **kwargs)[source]#

Bases: Mechanism

Presynaptic voltage-dependent graded transmitter-release gate.

This mechanism exposes the state variable s for use as a continuous presynaptic variable in Network.connect_continuous.

Parameters:
  • theta (float, default -20.0) – Presynaptic voltage in mV at which release activation T(V) is 0.5.

  • sigma (float, default 2.0) – Sigmoid slope factor in mV. Positive values make the gate activate with depolarization.

  • alpha (float, default 1.0) – Opening/activation rate scale in ms^-1.

  • beta (float, default 0.2) – Closing/deactivation rate in ms^-1.

Notes

graded_release_gate exposes the continuous release state s. This is the variable that should usually be used as pre_var in Network.connect_continuous.

Exposed variables

Variable

Type

Description

s

torch.Tensor

Dimensionless continuous release / gating variable in [0, 1]. Use this as the pre_var for graded_syn.

T

torch.Tensor

Dimensionless instantaneous voltage-dependent release activation.

sinf

torch.Tensor

Dimensionless steady-state value of the release gate.

tau

torch.Tensor

Voltage-dependent release-gate time constant in ms.

Examples

Use s as the continuous presynaptic variable:

net.connect_continuous(
    pre,
    post,
    post.mech.graded_syn,
    pre_var="mech.graded_release_gate.s",
    input="g_pre",
    weight=0.05,
)

Initialize a mechanism instance and register declared buffers.

Parameters:
  • name (str) – Mechanism alias. If None, falls back to the class name.

  • celsius (Tensor or float) – Temperature in °C, broadcastable to the mechanism shape.

  • diameters (Tensor) – Compartment diameters in µm, shared with sub-components.

  • shape (tuple of int) – Base shape for parameter tensors (without batch dimensions).

  • shape_f (tuple of int) – Full shape including batch dimensions.

  • key (Any, optional) – Index selector identifying the attached compartments.

  • is_composable (bool, optional) – Whether key represents a tuple of slices instead of flat indices.

  • support_spec (SupportSpec, optional) – Precomputed structural support metadata. Population compilation supplies this so support identity remains available after device moves without changing the legacy key storage ABI.

  • preserves_multiplicity (bool, optional) – Whether local slots deliberately preserve repeated physical locations, as for copied point processes.

  • force_packed_support (bool, optional) – Keep an otherwise classifiable support in its packed one-axis ABI.

  • additional_parameters (dict, optional) – Additional parameter declarations injected by the parent population.

  • ic (dict, optional) – Initial condition overrides for state buffers.

  • **kwargs – Extra keyword arguments forwarded to dendra.models.parametric.Parameterized.

class graded_syn(*args, **kwargs)[source]#

Bases: ContinuousSynapse

Postsynaptic continuous conductance-based chemical synapse.

graded_syn receives an analog presynaptic input named g_pre through Dendra’s Network.connect_continuous path. The default continuous receive behavior sums all incoming projections into g_pre once per timestep.

The current is

\[I_\mathrm{syn} = g_\mathrm{scale}\,g_\mathrm{pre}(V-E_\mathrm{syn}).\]
Parameters:
  • e (float, default 0.0) – Reversal potential in mV. Use e=0 for a typical excitatory graded synapse, or e=-80 for a typical inhibitory graded synapse.

  • g_scale (float, default 1.0) – Optional dimensionless scale applied after continuous projection delivery. Usually leave this at 1 and use the connection weight as the synaptic conductance-density scale.

Notes

graded_syn declares a continuous input buffer named g_pre. The network resets this buffer once per timestep and then sums weighted presynaptic analog gates into it through Network.connect_continuous. When the presynaptic value is the dimensionless release gate s, the connection weight and g_pre are in S/cm². i(v) returns outward-positive current density in mA/cm².

Continuous inputs

Input

Type

Description

g_pre

torch.Tensor

Weighted, summed presynaptic conductance-density drive delivered by ContinuousCon; in S/cm² for the documented dimensionless-gate examples.

g_pre_old

torch.Tensor

Previous-step value retained by ContinuousSynapse.reset_continuous_inputs.

Examples

One-to-one inhibitory graded synapses:

pre.insert(graded_release_gate)
post.insert(graded_syn, e=-80.0)

net.connect_continuous(
    pre,
    post,
    post.mech.graded_syn,
    conn_spec={"rule": "one_to_one"},
    pre_var="mech.graded_release_gate.s",
    input="g_pre",
    weight=0.05,
)

All-to-all excitatory graded synapses using a stateless transform:

post.insert(graded_syn, e=0.0)
net.connect_continuous(
    pre,
    post,
    post.mech.graded_syn,
    conn_spec={"rule": "all_to_all"},
    pre_var="v",
    transform=sigmoid_release(theta=-20.0, sigma=2.0),
    input="g_pre",
    weight=0.001,
)
class sigmoid_release(theta=-20.0, sigma=2.0)[source]#

Bases: Module

Memoryless sigmoid transform from presynaptic voltage to release gate.

Parameters:
  • theta (float, default -20.0) – Half-activation voltage in mV.

  • sigma (float, default 2.0) – Slope factor in mV. Positive values make release increase with depolarization. Smaller values produce steeper activation.

Notes

Input voltage is in mV and the returned release gate is dimensionless.

This transform is intended for use with Network.connect_continuous:

net.connect_continuous(
    pre, post, post.mech.graded_syn,
    pre_var="v",
    transform=sigmoid_release(theta=-20.0, sigma=2.0),
    input="g_pre",
    weight=0.01,
)

For a dynamic release gate with its own state, use graded_release_gate instead.

Loading external mechanisms#

load_mechanisms(*paths)[source]#

Load mechanism definitions from Python files in the supplied directories.

Parameters:

*paths (str or path-like) – Directories to scan for *.py files, excluding __init__.py.

Returns:

Definitions accessible by attribute or string key. Each file must export a mechanism whose name is the lower-case file stem; MyChannel.py must therefore export mychannel. Later directories replace earlier definitions with the same lower-case name.

Return type:

MechanismContainer

Notes

Loading executes the Python modules. Import or definition errors propagate to the caller. Only load trusted mechanism code.

class MechanismContainer(**kwargs)[source]#

Mechanism definitions returned by load_mechanisms().

Access definitions as container.name or container["name"]. Use available() to list the stored names.

__getitem__(key)[source]#
available()[source]#

Return the loaded definition names in insertion order.