Time¶
mujou.time ¶
The time of mujou.
Every run measures its nodes' dt on one timer, a time axis that can be scaled
and paused. By default every run shares global_timer; give a run a Timer
of its own with mujou.run(..., timer=...). The host controls the time of a
run through run.timer, and a node reads it with self.timer.
Timer: a time axis, running with the real clock at a scaleVirtualTimer: aTimerthat moves only when advanced, for testsReadOnlyTimer: the reading side of a timer, as a node sees its run's timer (Node.timer)Timestamp: a time on a timer, asRun.read_with_timeandPort.recv_with_timegive itglobal_timer: the timer of every run not given one of its own
Durations are in seconds of the timer (sleep, advance, dt,
period), except timeouts, which are in real seconds. Only the host controls
the time: sleep, pause, resume, set_time_scale and
VirtualTimer.advance raise RuntimeError in a node's hook.
global_timer
module-attribute
¶
A time axis that a run's nodes measure their dt on.
Timer() starts at start and runs with the real clock, time_scale
seconds of the timer per real second. Give it to
mujou.run(..., timer=...) to run a network on a time of its own: a pause
of that run (as Run.state_dict takes) then stops only this timer, not
global_timer, which every other run uses by default. Every time of the
run is a Timestamp on it.
Only the host controls a timer: sleep, pause, resume,
set_time_scale (and VirtualTimer.advance) raise RuntimeError in a
node's hook, where a node would wait for, or change the dt of, the other
nodes. A node reads the time of its run with self.timer.
pause stops the time of every run on the timer at one time T until
resume. Take the states of several runs on one timer while it is paused,
so that all of them are of the same time T.
The time is held in nanoseconds and saturates at about 584 years.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
Timer ¶
A time axis that a run's nodes measure their dt on.
Timer() starts at start and runs with the real clock, time_scale
seconds of the timer per real second. Give it to
mujou.run(..., timer=...) to run a network on a time of its own: a pause
of that run (as Run.state_dict takes) then stops only this timer, not
global_timer, which every other run uses by default. Every time of the
run is a Timestamp on it.
Only the host controls a timer: sleep, pause, resume,
set_time_scale (and VirtualTimer.advance) raise RuntimeError in a
node's hook, where a node would wait for, or change the dt of, the other
nodes. A node reads the time of its run with self.timer.
pause stops the time of every run on the timer at one time T until
resume. Take the states of several runs on one timer while it is paused,
so that all of them are of the same time T.
The time is held in nanoseconds and saturates at about 584 years.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
is_paused ¶
Whether the time is stopped, by pause or by a run on this timer that
is starting or taking its state. The clock of a VirtualTimer standing
still does not count as paused.
pause ¶
Stops the time until resume.
While paused, the nodes of the runs on this timer do not update (the
first dt after resume does not count the pause), and sleep does
not return until resumed. Run.state_dict still works. This is a
switch, not a count: pausing twice needs one resume. A run that takes
its state holds the time paused on its own, apart from this switch, so
resume does not end that, and its end does not end this pause.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
This is called from a node's hook. |
resume ¶
Turns off the switch of pause: the time moves again from where it
stopped, unless a run on this timer is taking its state.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
This is called from a node's hook. |
set_time_scale ¶
Sets how many seconds of this timer pass per real second.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
RuntimeError
|
This is called from a node's hook. |
sleep ¶
Blocks for seconds of this timer's time, following the scale and the
pauses: while paused, it does not return until resumed. Waits without
the GIL and checks for signals (Ctrl-C) in between.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
RuntimeError
|
This is called from a node's hook. |
VirtualTimer ¶
Bases: Timer
A timer for tests: its time moves only when advance moves it.
It starts at start. Its time scale does not apply to advance; it is
kept as a Timer keeps it (time_scale() and the state of a run on it).
mujou.testing.run runs a network on a new one unless given one, and
ManualRun.step(dt) advances it.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
is_paused ¶
Whether the time is stopped, by pause or by a run on this timer that
is starting or taking its state. The clock of a VirtualTimer standing
still does not count as paused.
pause ¶
Stops the time until resume.
While paused, the nodes of the runs on this timer do not update (the
first dt after resume does not count the pause), and sleep does
not return until resumed. Run.state_dict still works. This is a
switch, not a count: pausing twice needs one resume. A run that takes
its state holds the time paused on its own, apart from this switch, so
resume does not end that, and its end does not end this pause.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
This is called from a node's hook. |
resume ¶
Turns off the switch of pause: the time moves again from where it
stopped, unless a run on this timer is taking its state.
| RAISES | DESCRIPTION |
|---|---|
RuntimeError
|
This is called from a node's hook. |
set_time_scale ¶
Sets how many seconds of this timer pass per real second.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
RuntimeError
|
This is called from a node's hook. |
sleep ¶
Blocks for seconds of this timer's time, following the scale and the
pauses: while paused, it does not return until resumed. Waits without
the GIL and checks for signals (Ctrl-C) in between.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
RuntimeError
|
This is called from a node's hook. |
advance ¶
Moves the time forward by seconds, at once.
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
|
RuntimeError
|
The timer is paused (by |
ReadOnlyTimer ¶
The reading side of a timer: its time and its scale, and nothing that
changes them. What a node sees of its run's timer as Node.timer.
ReadOnlyTimer(timer) reads timer. The one a run gives its nodes stops
at the time the run ends: every time of the run is at most that time.
Timestamp ¶
A time on a timer.
float(ts) is the time in seconds; ts.ns is the exact time in
nanoseconds. Timestamps compare and hash by time, so
compare only those of one timer: a timestamp does not say which timer it is
on. a - b is the time from b to a in seconds, a float that is
negative when b is later. Timestamps pickle and copy.