Prefetch#
- class brainstate.nn.Prefetch(module, item)[source]#
Prefetch a state or variable in a module before it is initialized.
This class provides a mechanism to reference a module’s state or attribute that may not have been initialized yet. It acts as a placeholder or reference that will be resolved when called.
Use cases: - Access variables within dynamics modules that will be defined later - Create references to states across module boundaries - Enable access to delayed states through the .delay property
- Parameters:
Examples
>>> import brainstate >>> import brainunit as u >>> neuron = brainpy.state.LIF(...) >>> v_reference = neuron.prefetch('V') # Reference to voltage before initialization >>> v_value = v_reference() # Get the current value >>> delay_ref = v_reference.delay.at(5.0 * u.ms) # Reference voltage delayed by 5ms
Notes
When called, this class retrieves the current value of the referenced item. Use the .delay property to access delayed versions of the state.
- property delay#
Access delayed versions of the prefetched item.
- Returns:
An object that provides access to delayed versions of the prefetched item.
- Return type: