class brainpy.math.TimeDelay(delay_target, delay_len, before_t0=None, t0=0.0, dt=None, name=None, interp_method='linear_interp')[source]#

Delay variable which has a fixed delay time length.

For example, we create a delay variable which has a maximum delay length of 1 ms

>>> import brainpy.math as bm
>>> delay = bm.TimeDelay(bm.zeros(3), delay_len=1., dt=0.1)
>>> delay(-0.5)
[-0. -0. -0.]

This function supports multiple dimensions of the tensor. For example,

  1. the one-dimensional delay data

>>> delay = bm.TimeDelay(bm.zeros(3), delay_len=1., dt=0.1, before_t0=lambda t: t)
>>> delay(-0.2)
[-0.2 -0.2 -0.2]
  1. the two-dimensional delay data

>>> delay = bm.TimeDelay(bm.zeros((3, 2)), delay_len=1., dt=0.1, before_t0=lambda t: t)
>>> delay(-0.6)
[[-0.6 -0.6]
 [-0.6 -0.6]
 [-0.6 -0.6]]
  1. the three-dimensional delay data

>>> delay = bm.TimeDelay(bm.zeros((3, 2, 1)), delay_len=1., dt=0.1, before_t0=lambda t: t)
>>> delay(-0.8)
  • delay_target (ArrayType) – The initial delay data.

  • t0 (float, int) – The zero time.

  • delay_len (float, int) – The maximum delay length.

  • dt (float, int) – The time precesion.

  • before_t0 (callable, bm.ndarray, jnp.ndarray, float, int) –

    The delay data before ::math`t_0`. - when before_t0 is a function, it should receive a time argument t - when before_to is a tensor, it should be a tensor with shape

    of \((num\_delay, ...)\), where the longest delay data is aranged in the first index.

  • name (str) – The delay instance name.

  • interp_method (str) –

    The way to deal with the delay at the time which is not integer times of the time step. For exameple, if the time step dt=0.1, the time delay length delay\_len=1., when users require the delay data at t-0.53, we can deal this situation with the following methods:

    • "linear_interp": using linear interpolation to get the delay value at the required time (default).

    • "round": round the time to make it is the integer times of the time step. For the above situation, we will use the time at t-0.5 to approximate the delay data at t-0.53.

    New in version 2.1.1.

See also


__init__(delay_target, delay_len, before_t0=None, t0=0.0, dt=None, name=None, interp_method='linear_interp')[source]#


__init__(delay_target, delay_len[, ...])


Move all variable into the CPU device.


Move all variables into the GPU device.

load_state_dict(state_dict[, warn, compatible])

Copy parameters and buffers from state_dict into this module and its descendants.

load_states(filename[, verbose])

Load the model states.

nodes([method, level, include_self])

Collect all children nodes.

register_implicit_nodes(*nodes[, node_cls])

register_implicit_vars(*variables[, var_cls])

reset(delay_target, delay_len[, t0, before_t0])

Reset the delay variable.

save_states(filename[, variables])

Save the model states.


Returns a dictionary containing a whole state of the module.


Moves all variables into the given device.


Move all variables into the TPU device.

train_vars([method, level, include_self])

The shortcut for retrieving all trainable variables.


Flattens the object as a PyTree.

tree_unflatten(aux, dynamic_values)

Unflatten the data to construct an object of this class.

unique_name([name, type_])

Get the unique name for this object.


vars([method, level, include_self, ...])

Collect all variables in this node and the children nodes.



Name of the model.