experiment.progress¶
The progress and the timings of a run of simulation experiments.
A run of ExperimentRunner.run_experiments shows its progress on the console of
the package, see RunProgress: a bar over the experiments and a row per
running experiment with what it does, e.g. its simulations or its figures, and
how far it got. The run ends with a table of the seconds every experiment took
in every phase, see timings_table.
The phases (Phase) are measured where they happen, by a PhaseClock: the
runner measures the loading of the models and the initialization of an
experiment, SimulationExperiment.run its simulations, data, figures and
outputs. The seconds of every phase are the timings of its
ExperimentResult, also of an experiment which ran in a worker process: the
worker measures them and sends them back with the result.
While a phase runs, its clock reports it as an Event to the listener of the
context, see reporting: the display of the run, or in a worker a queue which
the parent forwards to its display. Outside of a run of the runner, e.g. an
experiment run by SimulationExperiment.run directly, the phases are measured
and nothing is reported.
Phase
¶
Bases: StrEnum
A phase of the run of an experiment, the keys of its timings.
Event
dataclass
¶
What an experiment does, which its clock reports to the listener.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
str
|
the experiment. |
phase |
Phase
|
the phase it is in. |
activity |
str
|
what it does in the phase, e.g. |
completed |
int
|
the steps of the activity which are done. |
total |
int
|
the steps of the activity, e.g. its figures, at least 1. |
PhaseClock
¶
Measure the phases of an experiment and report them to the listener.
The listener is the one of the context the clock is created in, see
reporting. Phases do not nest; a phase which runs twice, e.g. the
figures which are drawn and then written, adds up.
Attributes:
| Name | Type | Description |
|---|---|---|
sid |
the experiment. |
|
timings |
dict[str, float]
|
the seconds of every phase, by the value of the phase. |
Create the clock of an experiment, without any time.
RunProgress
¶
The progress of a run of experiments on the console.
A bar over the experiments, which counts an experiment when it is done, and a row per running experiment with its activity and how far it got, which is removed when the experiment is done. An experiment in a worker reports its events through a queue, so the rows of a pool are the experiments the workers run.
The display is safe to update from several threads: the events of the workers arrive in a thread of their own and the finished experiments of a pool in the thread of the pool.
Create the display of a run, it starts with start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_experiments
|
int
|
the experiments of the run. |
required |
workers
|
int
|
the processes which run them, for the overall row. |
required |
console
|
Console | None
|
the console of the output, the one of the package by default. |
None
|
finished
¶
Count an experiment as done, once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sid
|
str
|
the experiment. |
required |
failed
|
bool
|
whether it or one of its figures failed. |
False
|
Glyphs
dataclass
¶
The characters of the marks and the bars of the output.
A console whose encoding is no UTF, e.g. a redirected output on windows
in cp1252, cannot write the check marks and the bars; it gets ASCII
characters instead, as rich draws the lines of its tables in ASCII there.
reporting
¶
Report the phases of the experiments which run in the context.
A run of the runner without a display of its own reports to the listener
of an enclosing context, see current_listener, e.g. the run layer,
which records the events of the experiments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
listener
|
Listener | None
|
what receives the events, |
required |
shown
|
bool | None
|
whether the run shows its progress on the console; by default a run with a listener does. A listener which shows nothing, e.g. one which records the events, is not shown, and the scans of the tasks show no progress either. |
None
|
current_listener
¶
Get the listener of the reporting of the context, None outside of one.
scan_progress
¶
Get the progress of Simulator.run for a task of an experiment.
A run of the runner which shows no progress shows no progress bar of a
scan either; otherwise the simulator decides, see Simulator.run, and in
a run with progress a bar of a scan is shown below the rows of the run.
Returns:
| Type | Description |
|---|---|
bool | None
|
|
advance
¶
Advance the activity of the phase which runs, nothing outside of one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
int
|
the steps which are done, e.g. one figure. |
1
|
show_progress
¶
Decide whether a run shows its progress and timings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress
|
bool | None
|
|
required |
console
|
Console | None
|
the console of the output, the one of the package by default. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the progress and the timings are shown. |
glyphs
¶
timings_table
¶
Get the table of the seconds every experiment took in every phase.
A row per experiment with its seconds per phase, its total and a bar of
its phases in their colours, the bars of all experiments at one scale;
then the total of every phase over the experiments with the bar of the
whole run, and the share of every phase. The headers of the phases have
the colours of their parts of the bars. A phase which no experiment ran
has no column, nor has other when it took no measurable time.
In a run in a pool the experiments run at the same time, so the total over the experiments is more than the time of the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence[ExperimentResult]
|
the results of the experiments, see |
required |
bars
|
bool
|
show the bars, e.g. not on a console too narrow for them. |
True
|
marks
|
Glyphs
|
the characters of the marks and the bars, see |
UNICODE_GLYPHS
|
Returns:
| Type | Description |
|---|---|
Table
|
The table. |
narrow_timings_tables
¶
Get the timings for a console too narrow for timings_table.
The total of every experiment, and the seconds and the share of every phase over the experiments, as two tables of two and three columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence[ExperimentResult]
|
the results of the experiments, see |
required |
marks
|
Glyphs
|
the characters of the marks, see |
UNICODE_GLYPHS
|
Returns:
| Type | Description |
|---|---|
tuple[Table, Table]
|
The table of the experiments and the table of the phases. |
show_timings
¶
Print the timings of a run below a section, see timings_table.
The numbers are what matters: the names give way to the bars down to
MIN_NAME_WIDTH, then the bars give way, and a console too narrow for
the seconds of every phase of every experiment gets the totals of the
experiments and of the phases, see narrow_timings_tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
Sequence[ExperimentResult]
|
the results of the experiments of the run. |
required |
initialized
|
float | None
|
the seconds of the initialization of the experiments
before the run, when the runner was created, |
required |
elapsed
|
float
|
the seconds of the run. |
required |
where
|
str
|
where the experiments ran, e.g. |
required |
console
|
Console | None
|
the console of the output, the one of the package by default. |
None
|