DiffEqModule#

class braincell.quad.DiffEqModule#

Mixin marking a module as integrable by braincell.quad.

Any class that mixes in DiffEqModule exposes the small interface that every numerical integrator in braincell.quad relies on:

  • pre_integral() — invoked once at the start of each step, before any derivative is computed. Use it to refresh voltage-dependent rate constants, recompute synaptic input, or perform other one-time-per-step bookkeeping.

  • compute_derivative() — required override that writes state.derivative (and optionally state.diffusion) for every DiffEqState owned by the module.

  • post_integral() — invoked once at the end of each step, after the integrated values have been written back. Use it to clamp states, project onto manifolds, or fire post-step events.

Concrete subclasses include braincell.SingleCompartment and braincell.Cell. Solvers receive a DiffEqModule as their target argument and read t/dt from the active brainstate.environ context.

See also

DiffEqState

Per-variable state container the solvers update.

IndependentIntegration

Excludes a submodule from the main solver.

compute_derivative(*args, **kwargs)[source]#

Compute the derivative of the differential equation.

This method must be implemented by subclasses to define the specific differential equation for the system.

Parameters:
  • *args (tuple) – Variable length argument list.

  • **kwargs (dict) – Arbitrary keyword arguments.

Returns:

This method should be overridden in subclasses.

Return type:

NotImplemented

Raises:

NotImplementedError – If this method is not overridden in a subclass.

post_integral(*args, **kwargs)[source]#

Perform any necessary operations after the integration step.

This method can be overridden to implement custom post-integration logic.

Parameters:
  • *args (tuple) – Variable length argument list.

  • **kwargs (dict) – Arbitrary keyword arguments.

pre_integral(*args, **kwargs)[source]#

Perform any necessary operations before the integration step.

This method can be overridden to implement custom pre-integration logic.

Parameters:
  • *args (tuple) – Variable length argument list.

  • **kwargs (dict) – Arbitrary keyword arguments.