Many Brian objects store a clock object (always passed in the
initialiser with the keyword
clock=...). If no clock is specified,
the program uses the global default clock. When Brian is initially
imported, this is the object
defaultclock, and it has a default
time step of 0.1ms. In a simple script, you can override this by
writing (for example):
defaultclock.dt = 1*ms
However, there are other ways to access or redefine the default clock (see functions below).
You may wish to use multiple clocks in your program. In this case,
for each object which requires one, you have to pass a copy of its
Clock object. The network run function automatically handles objects
with different clocks, updating them all at the appropriate time
according to their time steps (value of
Multiple clocks can be useful, for example, for defining a simulation
that runs with a very small
dt, but with some computationally
expensive operation running at a lower frequency.
Clock(dt=0.1 * msecond, t=0.0 * second, order=0, makedefaultclock=False)¶
An object that holds the simulation time and the time step.
- The time step of the simulation.
- The current time of the clock.
- If two clocks have the same time, the order of the clock is used to resolve which clock is processed first, lower orders first.
- Set to
Trueto make this clock the default clock.
The times returned by this clock are always off the form
offset. For example, for a clock with
offset=5*ms. For a clock that uses true float values for
trather than underlying integers, use
FloatClock(although see the caveats there).
In order to make sure that certain operations happen in the correct sequence, you can use the
orderattribute, clocks with a lower order will be processed first if the time is the same. The condition for two clocks to be considered as having the same time is
abs(t1-t2)<epsilon*abs(t1), a standard test for equality of floating point values. For ordinary clocks based on integer times, the value of
1e-14, and for float based clocks it is
Reinitialises the clock time to zero (or to your specified time).
The time at which the current simulation will end, set by the
Advances the clock by one time step.
The time until the current simulation ends.
Set the time until the current simulation ends.
boolto indicate whether the current simulation is still running.
EventClock(dt=0.1 * msecond, t=0.0 * second, order=0, makedefaultclock=False)¶
Clock that is used for events.
FloatClock(dt=0.1 * msecond, t=0.0 * second, order=0, makedefaultclock=False)¶
Similar to a
Clockexcept that it uses a float value of
trather than an integer based underlying value. This means that over time the values of
tcan drift slightly off the grid, and sometimes
t/dtwill be slightly less than an integer value, sometimes slightly more. This can cause problems in cases where the computation
int(t/dt)is performed to extract an index value, as sometimes an index will be repeated or skipped. However, this form of clock can be used for backwards compatibility with versions of Brian before the new integer based clock was introduced, and for more flexibility than the new version allows for. Note also that the equality condition for this clock uses an
Clockfor more details on this. For full backwards compatibility with older versions of Brian, use
NaiveClock(dt=0.1 * msecond, t=0.0 * second, order=0, makedefaultclock=False)¶
Provided for backwards compatibility with older versions of Brian. Does not perform any approximate equality tests for clocks, meaning that clock processing sequence is undpredictable. Typically, users should use
The default clock¶
The default clock object
Note that this is only the default clock object if you haven’t redefined it with the
define_default_clock()function or the
makedefaultclock=Trueoption of a
Clockobject. A safe way to get hold of the default clock is to use the functions:
However, it is suitable for short scripts, e.g.:
defaultclock.dt = 1*ms ...
Create a new default clock
Uses the keywords of the
reinit_default_clock(t=0.0 * second)¶
Reinitialise the default clock (to zero or a specified time)
Returns the default clock object.