gemseo.core.execution_statistics module#

Execution statistics.

class ExecutionStatistics(name)[source]#

Bases: Serializable

Record execution statistics of objects.

This should be applied to objects such as BaseMonitoredProcess, hereafter referred to as the _measured object_.

A measured object often has an execution method whose number of calls is counted and time measured. Some have also a linearization method whose number of calls is counted too.

The recording of the statistics can be disabled all at once by setting is_enabled to False. By default, it is set to True. When enabled, the recording of time stamps can be enabled by setting is_time_stamps_enabled to True. By default, it is set to False. These switches are global and shall be modified from the class.

If any of those switches are disabled, the recordings, if any, are not removed.

The helper method record() is a context manager that should be used to record statistics.

The results of the recordings can be accessed with n_executions, n_linearizations, duration, time_stamps. The time stamps should be processed with create_gantt_chart().

The recorded statistics are not restored after pickling.

Initialize self. See help(type(self)) for accurate signature.

Parameters:

name (str) -- The name of the measured object.

record_execution(function)[source]#

Record execution statistics.

Parameters:

function (Callable[..., None])

Return type:

None

record_linearization(function)[source]#

Record linearization statistics.

Parameters:

function (Callable[..., None])

Return type:

None

property duration: float | None#

The cumulated execution duration.

This is property is multiprocessing safe.

Raises:

RuntimeError -- If the statistics are disabled.

is_enabled: ClassVar[bool] = True#

Whether to record all the statistics.

is_time_stamps_enabled: bool = False#

Whether to record the time stamps.

property n_executions: int | None#

The number of executions.

This property is multiprocessing safe.

Raises:

RuntimeError -- If the statistics are disabled.

property n_linearizations: int | None#

The number of linearizations.

This property is multiprocessing safe.

Raises:

RuntimeError -- If the statistics are disabled.

time_stamps: ClassVar[DictProxy[str, ListProxy[tuple[float, float, bool]]] | None] = None#

The mapping from the measured object names to their execution time stamps.

It is None when time stamps recording is disabled.

The structure is

{
"measure object name": [
    (start time, end time, whether it is for linearization),
    ...
    ],
"other measure object name": [
    ...
    ],
}