get_dt

Contents

get_dt#

class brainstate.environ.get_dt(*, env=None)[source]#

Get the current numerical integration time step.

Parameters:

env (EnvironmentState | None) – The environment state to query. If None, uses the global environment.

Returns:

The time step value.

Return type:

float

Raises:

KeyError – If dt is not set.

Examples

>>> import brainstate.environ as env
>>>
>>> env.set(dt=0.01)
>>> dt = env.get_dt()
>>> print(f"Time step: {dt} ms")  # Time step: 0.01 ms
>>>
>>> # Use in computation
>>> with env.context(dt=0.001):
...     fine_dt = env.get_dt()
...     print(f"Fine time step: {fine_dt}")  # 0.001

Using custom environment:

>>> import brainstate.environ as env
>>>
>>> custom_env = env.EnvironmentState()
>>> env.set(dt=0.001, env=custom_env)
>>> print(env.get_dt(env=custom_env))  # 0.001