Numerical integrators#

Integrator factories return a configured integrator class. Pass that class to model construction, for example dn.Cable(..., integrator=dn.rk4()). Choose an integrator compatible with the model’s spatial topology and extracellular layers. Functional lowering validates the same numerical family; unsupported combinations raise a functionalization error.

Explicit methods#

euler(**kwargs)#

Explicit forward Euler integrator for membrane voltage PDEs.

Uses a single-stage explicit update

\[v^{n+1} = v^{n} + \Delta t \, f(v^{n}, t^{n})\]

where \(f\) combines ionic currents and axial diffusion terms. The operator relies on a symmetric convolution stencil to approximate the spatial second derivative of the cable equation.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

eulerv1(**kwargs)#

Single-stage forward Euler integrator for scalar cable models.

Uses the same voltage update, cylindrical coefficients, and symmetric spatial stencil as _euler.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

rk1(**kwargs)#

Explicit forward Euler integrator for membrane voltage PDEs.

Uses a single-stage explicit update

\[v^{n+1} = v^{n} + \Delta t \, f(v^{n}, t^{n})\]

where \(f\) combines ionic currents and axial diffusion terms. The operator relies on a symmetric convolution stencil to approximate the spatial second derivative of the cable equation.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

rk2(**kwargs)#

Two-stage explicit Runge-Kutta (midpoint) integrator.

Computes

\[\begin{split}k_1 = f(v^n, t^n), \quad k_2 = f\!\left(v^n + \tfrac{\Delta t}{2} k_1, t^n + \tfrac{\Delta t}{2}\right), \\ v^{n+1} = v^n + \Delta t \, k_2\end{split}\]

providing second-order accuracy for the cable equation with explicit spatial diffusion and ionic currents.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

rk4(**kwargs)#

Classical four-stage Runge-Kutta integrator.

Evaluates four slopes (\(k_1..k_4\)) at staged voltage predictions and combines them with the standard RK4 weights to yield fourth-order accuracy for the explicit cable equation update.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

dufort_frankel(**kwargs)#

Dufort-Frankel explicit integrator for heterogeneous morphologies.

Extends the Dufort-Frankel scheme to non-uniform cable geometries by computing compartment-specific axial conductances. The method maintains unconditional stability for the linear diffusion term. Currents proven or declared affine in voltage are centered exactly between the stored time levels; other currents are evaluated explicitly with zero Dufort conductance. A one-dt forward-Euler step constructs the missing history level after initialization or a timestep change. Voltage smoothing remains optional.

Parameters:
  • beta (float, optional) – Exponential smoothing factor (1.0 disables smoothing). Default 1.0.

  • smooth_every (int, optional) – Retained configuration metadata. Spatial smoothing is applied each timestep when beta < 1. Default 100.

  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

dufort_frankel_homogeneous(**kwargs)#

Dufort-Frankel explicit integrator for homogeneous morphologies.

Uses the Dufort-Frankel scheme on the cable diffusion term to achieve unconditional stability for the linear part. Currents proven or declared affine in voltage are centered exactly between the stored time levels; other currents are evaluated explicitly with zero Dufort conductance. A one-dt forward-Euler step constructs the missing history level after initialization or a timestep change. Optionally applies spatial smoothing after each voltage update. Can compute with either convolution-based or direct finite-difference stencils.

Parameters:
  • beta (float, optional) – Exponential smoothing factor (1.0 disables smoothing). Default 1.0.

  • smooth_every (int, optional) – Retained configuration metadata. Spatial smoothing is applied each timestep when beta < 1. Default 100.

  • conv (bool, optional) – If True, use a fixed convolution kernel for the spatial stencil; otherwise use direct finite differences. Default False.

  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

dendra.models.integrators.df(**kwargs)#

Alias of dendra.models.integrators.dufort_frankel().

dendra.models.integrators.dfh(**kwargs)#

Alias of dendra.models.integrators.dufort_frankel_homogeneous().

Implicit methods#

bwd_euler_sc(**kwargs)#

Single-compartment implicit (backward) Euler integrator.

Advances the membrane voltage with a fully implicit Euler step on the ionic current term:

\[v^{n+1} = v^{n} - \frac{\Delta t}{C_m} I_\mathrm{ion}(v^{n+1})\]

which is linearized through the mechanism’s i call (returning total current and conductance), yielding a closed-form update per compartment without solving a spatial system.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

bwd_euler_sc_multi(**kwargs)#

Packed independent-compartment variant of implicit Euler.

The numerical workspace and tensor transition are intentionally inherited from _bwd_euler_sc: concatenation changes ownership/writeback, not the per-compartment equation. A distinct operator kind lets functional lowering admit the packed runtime without mistaking it for an ordinary SingleCompartment topology.

bwd_euler_ub(**kwargs)#

Implicit Euler for a single-layer, unbranched cable morphology.

Builds a tridiagonal system from the cable diffusion operator and ionic linearization, then solves it each step with a selectable solver backend.

Parameters:
  • method ({"thomas", "inv", "spd", "pcr"}, optional) – Solver backend: Thomas (default; "inv" maps to "thomas"), SPD tridiagonal (CPU only), or PCR (CPU/CUDA fallback).

  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

bwd_euler_bt(**kwargs)#

Implicit Euler for block tridiagonal systems (multi-layer extracellular).

Solves a block-tridiagonal linear system per step that couples the intracellular voltage and extracellular shell variables. The current block solver path is specialized to 3 unknowns per compartment. The SPD backend uses consuming workspace solvers: the per-step block matrix and RHS buffers constructed in _step are disposable and may be overwritten by the solver.

Parameters:
  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

  • method ({"spd", "inv"}, optional) – Block solver backend. "inv" selects a Thomas-like block solver, "spd" uses an SPD block solver where available. Default “inv”.

  • **kwargs – Forwarded to base integrator; reserved for future solver options.

Notes

When imem is enabled, public model.i_membrane is the absolute transmembrane current in mA: compartment area times the outward-current convention Cm * (v_new - v_old) / dt + I_ion(v_new) (with the same per-step current linearization used by the voltage solve). It excludes axial cable currents and applied intracellular stimulus as explicit terms; those drives affect i_membrane only through the solved voltage.

dhs(**kwargs)#

Dendritic Hierarchical Scheduling (DHS) integrator for tree morphologies.

Preprocesses a rooted tree into elimination layers and solves the resulting Hines tridiagonal system with a warp-friendly DHS ordering. CUDA uses Triton; CPU and Apple MPS use dendra_solvers. Extracellular coupling is included by accumulating edge currents into the RHS when ve is provided.

Parameters:
  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

  • threads (int, optional) – Threads per warp lane for DHS elimination (must divide 32). Default 16.

Notes

Based on Zhang et al., Nat. Commun. 14, 5798 (2023).

dhs_multi(**kwargs)#

Multi-model DHS integrator for heterogeneous scalar cable systems.

Packs ordinary independent populations as one-node trees, branched Tree morphologies, and Cable paths into padded flat buffers (shared stride K_stride = max K_g). Per-group offsets allow one CUDA/CPU kernel to process every scalar group in one launch. Optional extracellular coupling is applied through the same child/parent edge representation.

Parameters:
  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

  • threads (int, optional) – Threads per warp lane for DHS elimination (must divide 32). Default 16.

  • write_back (bool, optional) – If True, write updated voltages back into each group’s population after stepping. Default True.

dhs_bt(**kwargs)#

DHS integrator for block-tridiagonal (3x3 per node) tree systems.

Extends DHS to models with intracellular voltage and two extracellular shells (vi, ve0, ve1) per node, assembling block diagonals and axial conductances, then solving in DHS order with CUDA, CPU, or Apple MPS backends.

Parameters:
  • imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

  • threads (int, optional) – Threads per warp lane for DHS elimination (must divide 32). Default 16.

dhs_bt_multi(**kwargs)#

Packed block-DHS for independent two-layer extracellular populations.

ExtCellAxon paths and ExtCellTree morphologies, including different core replica counts, share one disconnected forest solve. No padding, synthetic connecting edges, or per-component solver calls are required. write_back publishes both membrane voltage v and absolute circuit potentials vc to component populations; mechanism states remain composite-owned.

Imposed voltage#

scnv(**kwargs)#

Single-compartment implicit Euler that skips solving the voltage. Updates to voltage by VoltageProcesses are still applied.

Applies the same implicit Euler step as _bwd_euler_sc but only evaluates ionic currents when stepping. Useful when the voltage is updated externally (e.g., via a closed-form solution within a Mechanism) but ionic currents still need to be advanced and evaluated. Consequently, intra is not a voltage-solve input for this integrator. When imem is enabled, the imposed voltage transition is still included in the capacitive part of the shared membrane-current contract.

Parameters:

imem (bool or None, optional) – If truthy, accumulate membrane currents each step. Default None.

Membrane-current output#

With imem=True (or IMEM=1), stable integrators report model.i_membrane as absolute outward-positive transmembrane current in mA: the capacitive current plus mechanism current under that integrator’s per-step discretization. Intracellular stimulus and axial currents influence the voltage solution; they are not separately added to the reported current. LFP callbacks consume this output.

scnv evaluates mechanism currents without a voltage solve. Its reported membrane current includes the capacitive contribution from the imposed voltage change. Solver-level intra and ve do not drive voltage through this integrator; a VoltageProcess supplies voltage instead.

Current assembly#

Implicit solvers can assemble affine currents as I = G*v - J. Custom mechanisms may declare this contract and provide affine terms; see Mechanisms, state equations and materials. dn.ctx(MEMBRANE_ASSEMBLY="off") disables this optimization, "auto" selects eligible currents, and "validate" adds diagnostics. The policy is read when evaluating currents. Validation inside torch.vmap is currently unsupported.

Experimental solvers#

dendra.models.integrators.imex is an explicit opt-in experimental module, not part of the integrator exports above. Its private implementations may change without stable-API guarantees; membrane-current output is currently unsupported.