Dynamics#
- class brainstate.nn.Dynamics(in_size, name=None)#
Base class for implementing neural dynamics models in BrainState.
Dynamics classes represent the core computational units in neural simulations, implementing the differential equations or update rules that govern neural activity. This class provides infrastructure for managing neural populations, handling inputs, and coordinating updates within the simulation framework.
The Dynamics class serves several key purposes: 1. Managing neuron population geometry and size information 2. Handling current and delta (instantaneous change) inputs to neurons 3. Supporting before/after update hooks for computational dependencies 4. Providing access to delayed state variables through the prefetch mechanism 5. Establishing the execution order in neural network simulations
- Parameters:
- current_inputs#
Dictionary of registered current input functions or arrays.
- delta_inputs#
Dictionary of registered delta input functions or arrays.
- before_updates#
Dictionary of functions to call before the main update.
- Type:
Optional[Dict[Hashable, Callable]]
- after_updates#
Dictionary of functions to call after the main update.
- Type:
Optional[Dict[Hashable, Callable]]
Notes
In the BrainState execution sequence, Dynamics modules are updated after Projection modules and before other module types, reflecting the natural flow of information in neural systems.
There are several essential attributes:
size: the geometry of the neuron group. For example, (10, ) denotes a line of neurons, (10, 10) denotes a neuron group aligned in a 2D space, (10, 15, 4) denotes a 3-dimensional neuron group.num: the flattened number of neurons in the group. For example, size=(10, ) => num=10, size=(10, 10) => num=100, size=(10, 15, 4) => num=600.
See also
ModuleParent class providing base module functionality
ProjectionClass for handling synaptic projections between neural populations
DynamicsGroupContainer for organizing multiple dynamics modules
- add_after_update(key, fun)[source]#
Register a function to be executed after the module’s update.
- Parameters:
- Raises:
KeyError – If the key is already registered in after_updates.
Notes
Internal method used by the module system to register dependencies.
- add_before_update(key, fun)[source]#
Register a function to be executed before the module’s update.
- Parameters:
- Raises:
KeyError – If the key is already registered in before_updates.
Notes
Internal method used by the module system to register dependencies.
- property after_updates#
Get the dictionary of functions to execute after the module’s update.
- Returns:
Dictionary mapping keys to callable functions that will be executed after the main update, or None if no after updates are registered.
- Return type:
dict or None
Notes
After updates are executed in the order they were registered whenever the module is called via __call__, and may optionally receive the return value from the update method.
- property before_updates#
Get the dictionary of functions to execute before the module’s update.
- Returns:
Dictionary mapping keys to callable functions that will be executed before the main update, or None if no before updates are registered.
- Return type:
dict or None
Notes
Before updates are executed in the order they were registered whenever the module is called via __call__.
- output_delay(*time_and_index, init=None, interpolation=None, **kwargs)[source]#
Create a reference to the delayed output of the module.
This method simplifies the process of accessing a delayed version of the module’s output. It instantiates an OutputDelayAt object, which can be used to retrieve the output value at the specified delay time.
- Parameters:
time_and_index – The amount of time to delay the output access, typically in time units (e.g., milliseconds). Defaults to None.
init (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – Delay initialization function or value. If the delayed output is not yet available, this function or value will be used to provide a default.interpolation (
str|None) – The interpolation method to use.
- Returns:
An object that provides access to the module’s output at the specified delay time.
- Return type:
- prefetch(item)[source]#
Create a reference to a state or variable that may not be initialized yet.
This method allows accessing module attributes or states before they are fully defined, acting as a placeholder that will be resolved when called. Particularly useful for creating references to variables that will be defined during initialization or runtime.
- Parameters:
item (
str) – The name of the attribute or state to reference.- Returns:
A Prefetch object that provides access to the referenced item.
- Return type:
Examples
>>> import brainstate >>> import brainunit as u >>> neuron = brainpy.state.LIF(...) >>> v_ref = neuron.prefetch('V') # Reference to voltage >>> v_value = v_ref() # Get current value >>> delayed_v = v_ref.delay.at(5.0 * u.ms) # Get delayed value
- prefetch_delay(state, *time_and_index, init=None, interpolation=None, **kwargs)[source]#
Create a reference to a delayed state or variable in the module.
This method simplifies the process of accessing a delayed version of a state or variable within the module. It first creates a prefetch reference to the specified state, then specifies the delay time for accessing this state.
- Parameters:
state (
str) – The name of the state or variable to reference.time_and_index – The amount of time to delay the variable access, typically in time units (e.g., milliseconds).
init (
Callable|Array|ndarray|bool|number|bool|int|float|complex|Quantity|None) – An optional initialization function to provide a default value if the delayed state is not yet available.interpolation (
str|None) – The interpolation method to use.
- Returns:
An object that provides access to the variable at the specified delay time.
- Return type:
- property varshape#
Get the shape of variables in the neuron group.
This property provides access to the geometry (shape) of the neuron population, which determines how variables and states are structured.
- Returns:
A tuple representing the dimensional shape of the neuron group, matching the in_size parameter provided during initialization.
- Return type:
See also
in_sizeThe input geometry specification for the neuron group