Skip to content

Controllers#

stochastix.controllers.Timer #

Timer(
    controlled_species: str | list[str] | tuple[str, ...],
    time_triggers: ndarray,
    species_at_triggers: ndarray,
)

A controller that activates at specific time points.

This controller allows for direct manipulation of species counts at predefined time points during a simulation. When a trigger time is reached, the controller updates the counts of the specified species to predefined values.

Attributes:

  • controlled_species

    The species whose counts will be manipulated.

  • time_triggers

    The time points at which the controller activates.

  • species_at_triggers

    The new counts for the controlled species at each trigger time.

Methods:

  • init

    Initialize the controller's state for the simulation.

  • step

    Execute a step of the Timer controller.

Parameters:

  • controlled_species (str | list[str] | tuple[str, ...]) –

    The name of the species or a list/tuple of species names to be controlled.

  • time_triggers (ndarray) –

    A JAX array of time points at which the controller should activate.

  • species_at_triggers (ndarray) –

    A JAX array where each row corresponds to a time trigger and contains the new counts for the controlled species. The order of species counts in each row must match the order of species names in controlled_species.

Raises:

  • ValueError

    If controlled_species is not a string, list, or tuple.

  • ValueError

    If the number of time triggers does not match the number of species count updates.

  • ValueError

    If the number of controlled species does not match the number of species counts in each update.

stochastix.controllers.AbstractController #

AbstractController()

Base class for controllers.

A controller is a module that can be used to modify the simulation behavior during execution.

Methods:

  • init

    Initializes the controller's state.

  • step

    Performs a single control step.

init #

init(
    network: ReactionNetwork,
    t: floating,
    x: ndarray,
    a: ndarray,
    *,
    key: ndarray,
) -> typing.Any

Initialize the controller's state.

This method is called once at the beginning of the simulation to set up the initial state of the controller.

Parameters:

  • network (ReactionNetwork) –

    The reaction network being simulated.

  • t (floating) –

    The initial time of the simulation.

  • x (ndarray) –

    The initial state vector (species counts).

  • a (ndarray) –

    The initial propensity vector.

  • key (ndarray) –

    A JAX random key for any stochastic initialization.

Returns:

  • Any

    The initial state of the controller. Can be any PyTree.

step #

step(
    t: floating,
    step_result: SimulationStep,
    controller_state: Any,
    key: ndarray,
) -> tuple[SimulationStep, typing.Any]

Perform a single control step.

This method is called at each step of the simulation, allowing the controller to inspect the simulation's progress and modify the state if necessary.

Parameters:

  • t (floating) –

    The current time of the simulation.

  • step_result (SimulationStep) –

    The result from the solver's step.

  • controller_state (Any) –

    The current state of the controller.

  • key (ndarray) –

    A JAX random key for any stochastic operations.

Returns:

  • SimulationStep

    A tuple containing the (potentially modified) simulation step result

  • Any

    and the new state of the controller.