MonitorPool

class MonitorPool[source]

Bases: Module

Collection of shared monitors.

add_monitor(observed: str, name: str, attr: str, constructor: MonitorConstructor, unique: bool = False, /, **tags: Any) Monitor[source]

Adds a monitor to an observable.

Parameters:
  • observed (str) – name of the observable to which the monitor will be added.

  • name (str) – name of the monitor to add (unique to the observable).

  • attr (str) – dot-separated attribute to monitor, relative to the observable.

  • constructor (MonitorConstructor) – partial constructor for the monitor.

  • unique (bool, optional) – if the monitor should never be aliased from the pool. Defaults to False.

  • **tags (Any) – tags to determine if the monitor is unique amongst monitors with the same name, targeting the same attribute (aligned to the basis).

Raises:

AttributeError – specified observable does not exist.

Returns:

added or retrieved monitor.

Return type:

Monitor

add_observed(name: str, value: Observable) Observable[source]

Adds an observable.

Parameters:
  • name (str) – name of the observable to add.

  • value (Observable) – observable to add to this pool.

Raises:
  • RuntimeError – an observable with the specified name already exists.

  • RuntimeError – an observable with the specified name existed and was registered, but removed from memory without deleting it from the pool.

Returns:

added observable.

Return type:

Observable

del_monitor(observed: str, monitor: str) None[source]

Deletes an added monitor.

Parameters:
  • observed (str) – name of the observable to which the monitor was added.

  • monitor (str) – name of the monitor.

Raises:

AttributeError – specified observable does not exist, or does not have a monitor with the specified name added to it.

del_observed(name: str) None[source]

Deletes an added observable.

Parameters:

name (str) – name of the observable to delete.

Important

This does not strictly delete the observable, it is still owned by its basis. Its monitors are however deleted.

get_monitor(observed: str, monitor: str) Monitor | None[source]

Gets an added monitor.

Parameters:
  • observed (str) – name of the observable to which the monitor was added.

  • monitor (str) – name of the monitor.

Returns:

specified monitor, if it exists.

Return type:

Monitor | None

get_observed(name: str) Observable[source]

Gets an added observable.

Parameters:

name (str) – name of the observable to get.

Returns:

specified observable, if it exists.

Return type:

Observable

property monitors: Iterator[Monitor]

Added monitors.

Because monitors for each Pool are pooled together for each trainer, duplicate monitors are not created where possible. The number of monitors here may be less than the number of added monitors.

Yields:

Monitor – added monitors.

property named_monitors: Iterator[tuple[tuple[str, str], Monitor]]

Iterable of added monitors and tuples of the cell and monitor name.

Yields:

tuple[tuple[str, str], Monitor] – tuple of an added monitor and a tuple of the observable name and monitor name corresponding to it.

named_monitors_of(observed: str) Iterator[tuple[str, Monitor]][source]

Monitors associated with a given observable.

Parameters:

observed (str) – name of the observable to get associated monitors of.

Yields:

tuple[str, Monitor] – associated monitors and their names.

property pool: Iterator[tuple[Observable, dict[str, Monitor]]]

Pool of monitors used by Observable.

Yields:

tuple[Observable, dict[str, Monitor]] – tuple of observable, and its monitors.