Skip to content

State management#

Experiment state#

The state of an experiment is defined by these attributes:

  • id_experiment: UUID of the experiment.
  • name: Name of the experiment. If not provided, a short 6-alphanum hash of id_experiment is generated.
  • db: Database handler (discarded on pickling).
  • fields: Accessible at any time, with database storage.
  • runs: Collection of runs associated with the experiment implemented as a dictionary with run IDs as keys.

Run state#

The state of a run is defined by these attributes:

  • id_experiment: UUID of the associated experiment.
  • id_run: UUID of the run.
  • config: Fixed parameters of the run, cleared after execution.
  • params: Variable parameters of the run, cleared after execution.
  • vars: Accessible only within steps execution.
  • state: Accessible after execution of steps.
  • fields: Accessible at any time, with database storage.
  • exception: Set transparently if the step raised an exception before raising the exception at experiment-level.
  • steps: Sequence of functions to execute, accessible only within steps execution.

Tip

  • For a comprehensive discussion of the semantics of the different attributes, see Model of computation.
  • The steps attribute can be inspected by a step function to read the Python source code of the steps, which can be used to track the state lineage and/or the steps code for backup and later analysis.

Example#

We programmatically print the attributes that constitute the strict state of experiments and runs, as well as the respective subsets that are considered for pickling. Declaring the __slots__ attribute allows us to declare explicitly which attributes are allowed, and deny the creation of new ones. This behaviour keeps these objects clean, and enforces the correct use of the available run state attributes. The __state__ attribute is not inherited by Object, it simply defines a list of attributes to be considered by __getstate__ for pickling.

The state attributes of experiments and runs

from pprint import pprint

from mltraq.experiment import Experiment
from mltraq.run import Run

print("List of Experiment state attributes:")
pprint(Experiment.__slots__, width=60)
print("\nList of Experiment pickled attributes:")
pprint(Experiment.__state__, width=60)


print("\nList of Run state attributes:")
pprint(Run.__slots__, width=60)
print("\nList of Run pickled attributes:")
pprint(Run.__state__, width=60)
Output
List of Experiment state attributes:
('id_experiment', 'name', 'fields', 'runs', 'db')

List of Experiment pickled attributes:
('id_experiment', 'name', 'fields', 'runs')

List of Run state attributes:
('id_experiment',
 'id_run',
 'config',
 'params',
 'fields',
 'state',
 'exception',
 'vars',
 'steps')

List of Run pickled attributes:
('id_experiment',
 'id_run',
 'config',
 'params',
 'fields',
 'state',
 'exception')