check_dt function

(Shortest import: from brian2.core.clocks import check_dt)

brian2.core.clocks.check_dt(new_dt, old_dt, target_t)[source]

Check that the target time can be represented equally well with the new dt.


new_dt : float

The new dt value

old_dt : float

The old dt value

target_t : float

The target time


If using the new dt value would lead to a difference in the target time of more than Clock.epsilon_dt times new_dt (by default, 0.01% of the new dt).


>>> from brian2 import *
>>> check_dt(float(17*ms), float(0.1*ms), float(0*ms))  # For t=0s, every dt is fine
>>> check_dt(float(0.05*ms), float(0.1*ms), float(10*ms))  # t=10*ms can be represented with the new dt
>>> check_dt(float(0.2*ms), float(0.1*ms), float(10.1*ms))  # t=10.1ms cannot be represented with dt=0.2ms 
Traceback (most recent call last):
ValueError: Cannot set dt from 100. us to 200. us, the time 10.1 ms is not a multiple of 200. us