rate_connection_delayed#
- class brainpy.state.rate_connection_delayed(weight=1.0, delay_steps=1, name=None)#
NEST-compatible
rate_connection_delayedconnection model.Implements connection-level semantics for delayed rate connections following NEST’s
rate_connection_delayedmodel. This class represents a synapse that transmits rate signals with a configurable delay, supporting secondary event propagation for rate-based network simulations.Unlike
rate_connection_instantaneous, this model enforces a minimum delay of one simulation step and supports delayed secondary events through coefficient arrays.- Parameters:
weight (
floatorarray-like, optional) – Connection gain/strength applied to transmitted rate signals. Must be scalar. Default:1.0.delay_steps (
intorarray-like, optional) – Transmission delay in discrete simulation steps. Must be integer-valued and>= 1. Default:1.name (
strorNone, optional) – Optional name identifier for this connection instance. Default:None.
Parameter Mapping
The following table maps NEST parameters to this implementation:
NEST Parameter
brainpy.state
Notes
weightweightConnection gain (scalar float)
delaydelay_stepsDelay in steps (integer
>= 1)has_delayHAS_DELAYAlways
True(class attribute)supports_wfrSUPPORTS_WFRAlways
False(class attribute)Mathematical Description
1. Connection Model
A
rate_connection_delayedsynapse transmits a rate signal \(r_\text{pre}(t)\) from a presynaptic neuron to a postsynaptic neuron with delay \(d\) and weight \(w\):\[r_\text{post}(t) = w \cdot r_\text{pre}(t - d)\]In discrete-time simulation with step size \(\Delta t\), the delay is quantized to an integer number of steps:
\[d_\text{steps} = \left\lceil \frac{d}{\Delta t} \right\rceil, \quad d_\text{steps} \geq 1\]2. Secondary Event Handling
NEST rate neurons support secondary events for implicit integration schemes. A secondary event carries a coefficient array \(\{c_0, c_1, \ldots, c_{n-1}\}\) representing contributions at multiple time lags.
The receiver maps each coefficient \(c_i\) to a target buffer slot:
\[\text{target\_slot} = (d_\text{steps} - d_\text{min}) + i\]where \(d_\text{min}\) is the minimum delay in the network. This ensures that coefficients are applied to the correct future time steps.
3. Event Payload Structure
A delayed rate event contains:
rate: Scalar rate value or coefficient arrayweight: Connection weightdelay_steps: Integer delaymultiplicity: Optional scaling factor for probabilistic connections
The method
coeffarray_to_step_events()expands a coefficient array into individual per-step events, each with the appropriate delay offset.Implementation Notes
Delay Validation
This model enforces
delay_steps >= 1to comply with NEST semantics. Attempting to setdelay_steps = 0raises aValueError. For instantaneous (zero-delay) connections, userate_connection_instantaneousinstead.Unit Handling
All parameters accept
saiunit.Quantityobjects or plain numeric values. If aQuantityis provided, its mantissa is extracted. Internally, values are stored as dimensionless floats or integers.Compatibility with NEST
NEST stores delays in time units (ms), while this implementation uses discrete steps to match BrainPy’s event system.
The
set_statusmethod accepts bothdelayanddelay_stepsas aliases for backward compatibility.Secondary event expansion follows NEST’s buffer indexing logic exactly.
- Raises:
ValueError – If
weightordelay_stepsis not scalar, or ifdelay_steps < 1.ValueError – If
delayanddelay_stepsare both provided inset_statuswith conflicting values.ValueError – If coefficient array is empty or delay is less than
min_delay_stepsincoeffarray_to_step_events.
See also
rate_connection_instantaneousZero-delay rate connection model (NEST equivalent)
rate_neuron_ipnInput rate neuron (delayed event receiver)
rate_neuron_opnOutput rate neuron (delayed event receiver)
References
Examples
Basic Usage
Create a delayed connection with weight 2.0 and 3-step delay:
>>> import brainpy.state as bst >>> conn = bst.rate_connection_delayed(weight=2.0, delay_steps=3) >>> conn.get_status() {'weight': 2.0, 'delay_steps': 3, 'delay': 3, 'has_delay': True, 'supports_wfr': False}
Creating Rate Events
Transmit a rate signal with the connection’s parameters:
>>> event = conn.to_rate_event(rate=5.0, multiplicity=1.0) >>> event {'rate': 5.0, 'weight': 2.0, 'delay_steps': 3, 'multiplicity': 1.0}
Secondary Event Expansion
Map a coefficient array to per-step events (e.g., for implicit integration):
>>> coeffs = [0.5, 1.0, 0.3] # Three lag coefficients >>> events = conn.coeffarray_to_step_events(coeffs, min_delay_steps=1) >>> len(events) 3 >>> events[0] {'rate': 0.5, 'weight': 2.0, 'delay_steps': 2, 'multiplicity': 1.0} >>> events[1] {'rate': 1.0, 'weight': 2.0, 'delay_steps': 3, 'multiplicity': 1.0} >>> events[2] {'rate': 0.3, 'weight': 2.0, 'delay_steps': 4, 'multiplicity': 1.0}
Dynamic Parameter Updates
Update connection parameters at runtime:
>>> conn.set_status(weight=1.5, delay_steps=5) >>> conn.get('weight') 1.5 >>> conn.get('delay_steps') 5
Using with Rate Neurons
Typical usage in a rate-based network (conceptual example):
>>> import brainpy.state as bst >>> import saiunit as u >>> # Create rate neurons (assuming rate_neuron_ipn exists) >>> pre = bst.rate_neuron_ipn(size=10, tau=10.0*u.ms) >>> post = bst.rate_neuron_ipn(size=5, tau=10.0*u.ms) >>> # Define delayed connections >>> conns = [bst.rate_connection_delayed(weight=w, delay_steps=d) ... for w, d in zip([0.8, 1.2, 0.5], [2, 3, 1])] >>> # Transmit events during simulation >>> for conn in conns: ... event = conn.to_rate_event(pre.rate, multiplicity=1.0) ... # post.handle_delayed_event(event) # Receiver-side logic
- coeffarray_to_step_events(coeffarray, min_delay_steps=1, multiplicity=1.0)[source]#
Map lag-indexed coefficient array to per-step delayed-rate events.
Expands a coefficient array representing multiple time lags into individual per-step rate events, following NEST’s delayed-rate receiver buffer indexing. Each coefficient \(c_i\) is mapped to an event with delay offset \((d - d_{\text{min}}) + i\), where \(d\) is the connection delay and \(d_{\text{min}}\) is the minimum network delay.
This method is used to distribute secondary event coefficients across future time steps for implicit integration schemes.
- Parameters:
coeffarray (
array-like) – 1D array of coefficients, shape(n,). Each element represents a rate contribution at a successive time lag. Must be non-empty. Acceptssaiunit.Quantity(mantissa will be extracted).min_delay_steps (
intorarray-like, optional) – Minimum delay in the network (in simulation steps). Used to compute the base delay offset. Must be integer-valued scalar>= 1. Default:1.multiplicity (
floatorarray-like, optional) – Scaling factor for all events. Must be scalar. Default:1.0.
- Returns:
List of event dictionaries, one per coefficient. Each event has keys:
'rate'(float): Coefficient value.'weight'(float): Connection weight.'delay_steps'(int): Computed delay =(self.delay_steps - min_delay_steps) + i.'multiplicity'(float): Scaling factor.
Length of list equals
len(coeffarray).- Return type:
- Raises:
ValueError – If
coeffarrayis empty.ValueError – If
self.delay_steps < min_delay_steps(would produce negative delay).ValueError – If
min_delay_stepsormultiplicityis not scalar, or ifmin_delay_steps < 1.
Notes
NEST Buffer Indexing
NEST rate neurons with delayed connections use a ring buffer indexed by:
\[\text{buffer\_slot} = (d - d_{\text{min}}) + i\]where \(d\) is the connection delay, \(d_{\text{min}}\) is the minimum delay, and \(i\) is the coefficient index. This ensures that coefficients are applied to the correct future time steps during implicit integration.
Example Calculation
Suppose
self.delay_steps = 5,min_delay_steps = 2, andcoeffarray = [0.5, 1.0, 0.3]:Coefficient 0 (
0.5):delay_steps = (5 - 2) + 0 = 3Coefficient 1 (
1.0):delay_steps = (5 - 2) + 1 = 4Coefficient 2 (
0.3):delay_steps = (5 - 2) + 2 = 5
See also
prepare_secondary_eventCreate secondary event with coefficient array.
to_rate_eventCreate single-rate event.
Examples
Basic usage with 3 coefficients:
>>> conn = rate_connection_delayed(weight=2.0, delay_steps=5) >>> coeffs = [0.5, 1.0, 0.3] >>> events = conn.coeffarray_to_step_events(coeffs, min_delay_steps=2) >>> len(events) 3 >>> events[0] {'rate': 0.5, 'weight': 2.0, 'delay_steps': 3, 'multiplicity': 1.0} >>> events[1] {'rate': 1.0, 'weight': 2.0, 'delay_steps': 4, 'multiplicity': 1.0} >>> events[2] {'rate': 0.3, 'weight': 2.0, 'delay_steps': 5, 'multiplicity': 1.0}
Error when connection delay is less than minimum delay:
>>> conn = rate_connection_delayed(weight=1.0, delay_steps=1) >>> conn.coeffarray_to_step_events([0.5, 1.0], min_delay_steps=3) Traceback (most recent call last): ... ValueError: delay_steps must be >= min_delay_steps.
Using with multiplicity scaling:
>>> conn = rate_connection_delayed(weight=1.0, delay_steps=3) >>> events = conn.coeffarray_to_step_events([0.5, 1.0], min_delay_steps=1, multiplicity=0.8) >>> events[0]['multiplicity'] 0.8
- get(key='status')[source]#
Retrieve a specific parameter or full status dictionary.
- Parameters:
key (
str, optional) – Parameter name to retrieve. Special value'status'returns full status dictionary. Supported keys:'status','weight','delay','delay_steps','has_delay','supports_wfr'. Default:'status'.- Returns:
If
key == 'status', returns full status dictionary. Otherwise, returns the requested parameter value.- Return type:
dictorscalar- Raises:
KeyError – If
keyis not a recognized parameter name.
Examples
>>> conn = rate_connection_delayed(weight=2.0, delay_steps=3) >>> conn.get('weight') 2.0 >>> conn.get('delay_steps') 3 >>> conn.get('status') {'weight': 2.0, 'delay_steps': 3, ...}
- get_status()[source]#
Retrieve all connection parameters as a dictionary.
Follows NEST’s
GetStatusAPI convention.- Returns:
Dictionary with keys:
'weight'(float): Connection gain.'delay_steps'(int): Delay in simulation steps.'delay'(int): Alias fordelay_steps(NEST compatibility).'has_delay'(bool): AlwaysTrue.'supports_wfr'(bool): AlwaysFalse.
- Return type:
Examples
>>> conn = rate_connection_delayed(weight=1.5, delay_steps=2) >>> status = conn.get_status() >>> status['weight'] 1.5 >>> status['delay'] 2
- prepare_secondary_event(coeffarray)[source]#
Create a delayed secondary-event payload.
Secondary events are used in implicit integration schemes for rate neurons. The coefficient array represents contributions at multiple time lags.
- Parameters:
coeffarray (
array-like) – 1D array of coefficients, shape(n,), representing rate contributions atnconsecutive time lags. Must be non-empty. Acceptssaiunit.Quantity(mantissa will be extracted).- Returns:
Event payload with keys:
'coeffarray'(ndarray): Validated coefficient array, shape(n,), dtypefloat64.'weight'(float): Connection weight.'delay_steps'(int): Connection delay in steps.
- Return type:
- Raises:
ValueError – If
coeffarrayis empty or cannot be converted to a 1D array.
See also
coeffarray_to_step_eventsExpand coefficient array to per-step events.
Examples
>>> conn = rate_connection_delayed(weight=2.0, delay_steps=3) >>> event = conn.prepare_secondary_event([0.5, 1.0, 0.3]) >>> event['coeffarray'] array([0.5, 1. , 0.3]) >>> event['weight'] 2.0
- property properties: dict[str, Any]#
Return connection model properties.
- Returns:
Dictionary with keys:
'has_delay'(bool): AlwaysTruefor this model.'supports_wfr'(bool): AlwaysFalse(waveform relaxation not supported).
- Return type:
- set_delay(delay)[source]#
Update the connection delay (alias for
set_delay_steps).- Parameters:
delay (
intorarray-like) – New delay in simulation steps. Must be integer-valued scalar>= 1. Acceptssaiunit.Quantity(mantissa will be extracted).- Raises:
ValueError – If
delayis not scalar, not integer-valued, or< 1.
Examples
>>> conn = rate_connection_delayed() >>> conn.set_delay(5) >>> conn.get('delay_steps') 5
- set_delay_steps(delay_steps)[source]#
Update the connection delay in simulation steps.
- Parameters:
delay_steps (
intorarray-like) – New delay in simulation steps. Must be integer-valued scalar>= 1. Acceptssaiunit.Quantity(mantissa will be extracted).- Raises:
ValueError – If
delay_stepsis not scalar, not integer-valued, or< 1.
Examples
>>> conn = rate_connection_delayed() >>> conn.set_delay_steps(3) >>> conn.get('delay_steps') 3
- set_status(status=None, **kwargs)[source]#
Update connection parameters from a dictionary or keyword arguments.
Follows NEST’s
SetStatusAPI convention. Accepts bothdelayanddelay_stepsas aliases (if both provided, they must match).- Parameters:
- Raises:
ValueError – If
delayanddelay_stepsare both provided with conflicting values.ValueError – If any parameter fails validation (e.g., non-scalar, delay < 1).
Examples
>>> conn = rate_connection_delayed(weight=1.0, delay_steps=1) >>> conn.set_status({'weight': 2.5, 'delay_steps': 4}) >>> conn.get('weight') 2.5 >>> conn.set_status(weight=3.0) # Keyword argument style >>> conn.get('weight') 3.0
- set_weight(weight)[source]#
Update the connection weight.
- Parameters:
weight (
floatorarray-like) – New connection gain. Must be scalar. Acceptssaiunit.Quantity(mantissa will be extracted).- Raises:
ValueError – If
weightis not scalar.
Examples
>>> conn = rate_connection_delayed() >>> conn.set_weight(2.5) >>> conn.get('weight') 2.5
- to_rate_event(rate, multiplicity=1.0, delay_steps=None)[source]#
Create a delayed-rate event payload for step-based simulation APIs.
Constructs an event dictionary that can be passed to rate neuron receivers to transmit a rate signal with the connection’s weight and delay.
- Parameters:
rate (
floatorarray-like) – Rate value to transmit. Can be scalar (single rate) or array (multiple rates). Acceptssaiunit.Quantity(mantissa will be extracted).multiplicity (
floatorarray-like, optional) – Scaling factor for stochastic or probabilistic connections. Must be scalar. Default:1.0.delay_steps (
intorarray-likeorNone, optional) – Override delay for this event. Must be integer-valued scalar>= 1. IfNone, uses the connection’sself.delay_steps. Default:None.
- Returns:
Event payload with keys:
'rate'(float or ndarray): Rate value (scalar or array).'weight'(float): Connection weight.'delay_steps'(int): Delay in steps.'multiplicity'(float): Scaling factor.
- Return type:
- Raises:
ValueError – If
multiplicityordelay_stepsis not scalar, or ifdelay_steps < 1.
Examples
>>> conn = rate_connection_delayed(weight=2.0, delay_steps=3) >>> event = conn.to_rate_event(rate=5.0) >>> event {'rate': 5.0, 'weight': 2.0, 'delay_steps': 3, 'multiplicity': 1.0}
Override delay for a specific event:
>>> event = conn.to_rate_event(rate=5.0, delay_steps=5) >>> event['delay_steps'] 5