Skip to content

Experiment

hhh@AIMC-714-hhh-wsl-ubuntu22 edited this page Nov 4, 2025 · 2 revisions

dmlx.experiment

Experiment Objects

class Experiment()

Experiment.before_main

def before_main() -> Callable[[Callable[..., None]], Callable[..., None]]

Register a hook function to be invoked before the main function. The function will receive the same input as the main function and have the final chance to modify experiment meta data. For example, this function can be utilized to modify experiment name according to command line args.

Experiment.birth

@property
def birth() -> datetime

The creation time of the experiment object.

Experiment.name

@property
def name() -> str

Experiment name.

Experiment.meta_file_path

@property
def meta_file_path() -> Path

Path to the meta file, relative to the experiment directory.

Experiment.args

@property
def args() -> dict[str, object]

Parsed command args.

Experiment.path

@property
@cache
def path() -> Path

Path to the experiment directory.

Experiment.dump_meta

def dump_meta(**json_options: Any) -> Meta

Dump experiment meta to JSON file.

Returns:

  • meta Experiment.Meta - The dumped meta.

Experiment.init

def init(meta_json_options: dict[str, Any] | None = None) -> None

Initialize the experiment directory.

Experiment.main

def main(*command_args, **command_kwargs) -> Callable[[Callable], click.Command]

Creates the click command and use the decorated function as callback. (Additional command arguments and options can be declared with corresponding click functions.)

Returns:

decorator (Callable[[Callable], click.Command]): The decorator for the callback.

Experiment.param

def param(cls: type[click.Parameter], *args, **kwargs) -> property

Create a param property that is to be read from the experiment command. (All arguments will be forwarded to the constructor.)

Returns:

  • param click.Parameter - The created param.

Experiment.argument

def argument(*args, **kwargs) -> property

Create an argument property that is to be read from the experiment command. (All arguments will be forwarded to click.Argument().)

Returns:

  • argument click.Argument - The created argument.

Experiment.option

def option(*args, **kwargs) -> property

Create an option property that is to be read from the experiment command. (All arguments will be forwarded to click.Option().)

Returns:

  • option click.Option - The created option.

Experiment.context

def context() -> "ExperimentContext"

Get an experiment context for the experiment.

Experiment.run

def run(*args, **kwargs) -> object

Run experiment command. (All arguments will be passed to the command.)

Returns:

  • return_value object - The value returned by the command.

Experiment.load

def load(**json_options: Any) -> None

Load the experiment from an existing archive.