drytorch.core.experimenting

Module containing the Experiment and Run class.

Classes

Experiment(config, *[, name, par_dir, tags])

Manage experiment configuration, directory, and tracking.

Run(experiment, run_id[, resumed, record])

Execution lifecycle for a single run of an Experiment.

RunMetadata(id, status, timestamp, commit)

Metadata for a run.

RunRegistry(path)

Creates and manages a JSON file for run metadata.

class Experiment(config: _T_co, *, name: str = '', par_dir: str | Path = PosixPath('.'), tags: list[str] | None = None)[source]

Bases: Generic[_T_co]

Manage experiment configuration, directory, and tracking.

This class associates a configuration file, a name, and a working directory with a machine learning experiment. It also contains the trackers responsible for tracking the metadata and metrics for the experiment. Finally, it allows global access to a configuration file with the correct type annotations.

folder_name

name of the hidden folder storing experiment metadata.

Type:

ClassVar[str]

run_file

filename storing the registry of run IDs for this experiment.

Type:

ClassVar[str]

previous_runs

a list of all previous runs created by this class.

Type:

ClassVar[list[drytorch.core.experimenting.Run]]

par_dir

parent directory for experiment data.

Type:

pathlib.Path

tags

descriptors for the experiment.

Type:

list[str]

trackers

dispatcher for publishing events.

Type:

drytorch.core.tracking.EventDispatcher

Initialize.

Parameters:
  • config (_T_co) – Configuration for the experiment.

  • name (str) – The name of the experiment (defaults to class name).

  • par_dir (Path) – Parent directory for experiment data.

  • tags (list[str]) – Descriptors for the experiment (e.g., "lr=0.01").

property name: str

The name of the experiment.

property config: _T_co

Experiment configuration.

create_run(*, run_id: str | None = None, resume: bool = False, record: bool = True) Run[_T_co][source]

Convenience constructor for a Run using this experiment.

Parameters:
  • run_id (str | None) – identifier of the run; defaults to timestamp.

  • resume (bool) – resume the selected run if run_id is set, else the last run.

  • record (bool) – record the run in the registry.

Returns:

The created run object.

Raises:

RunAlreadyRecordedError – if creating a new run with an existing id.

Return type:

Run[_T_co]

property run: Run[_T_co]

Get the current run.

Raises:

NoActiveExperimentError – if no run is currently active.

classmethod get_config() _T_co[source]

Retrieve the configuration of the current experiment.

Return type:

_T_co

classmethod get_current() Self[source]

Return the currently active experiment.

Raises:

NoActiveExperimentError – if no experiment is currently active.

Return type:

Self

static set_current(experiment: Experiment[_T_co]) None[source]

Set an experiment as active.

Raises:

NestedScopeError – if there is an already active run.

Parameters:

experiment (Experiment[_T_co])

Return type:

None

class Run(experiment: Experiment[_T_co], run_id: str | None, resumed: bool = False, record: bool = True)[source]

Bases: CreatedAtMixin, Generic[_T_co]

Execution lifecycle for a single run of an Experiment.

status

Current status of the run.

Type:

RunStatus

resumed

whether the run was resumed.

Type:

bool

metadata_manager

Manager for run metadata.

Type:

tracking.MetadataManager

record

whether to record the run in the registry.

Type:

bool

Initialize.

Parameters:
  • experiment (Experiment[_T_co]) – the experiment this run belongs to.

  • run_id (str | None) – identifier of the run.

  • resumed (bool) – whether the run was resumed.

  • record (bool) – record the run in the registry.

property experiment: Experiment[_T_co]

The experiment this run belongs to.

property id: str

The identifier of the run.

__enter__() Self[source]

Enter the experiment scope.

Return type:

Self

__exit__(exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) None[source]

Exit the experiment scope.

Parameters:
Return type:

None

is_active() bool[source]

Check if the run is currently active.

Return type:

bool

stop() None[source]

Stop the experiment scope.

Return type:

None

start() None[source]

Start the experiment scope.

Parameters:

self (Self)

Return type:

None