Skip to content

experimentinfo

experimentinfo

Module for experimentinfo

Classes

ExpIdNotFoundError

Bases: Exception

Exception which is raised when an experiment id is not found

ExperimentInfo dataclass

Dataclass which holds information about an experiment but not the data

Functions
as_save_dict
as_save_dict()

Returns a dictionary which can be saved to a yaml file

Source code in niceml/experiments/experimentinfo.py
def as_save_dict(self) -> dict:
    """Returns a dictionary which can be saved to a yaml file"""
    return {
        EXP_NAME_KEY: self.experiment_name,
        EXP_PREFIX_KEY: self.experiment_prefix,
        EXP_TYPE_KEY: self.experiment_type,
        RUN_ID_KEY: self.run_id,
        SHORT_ID_KEY: self.short_id,
        ENVIRONMENT_KEY: self.environment,
        DESCRIPTION_KEY: self.description,
        EXP_DIR_KEY: self.exp_dir,
        LAST_MODIFIED_KEY: self.last_modified,
    }
is_modified
is_modified(other)

Checks if the other experiment info is modified

Source code in niceml/experiments/experimentinfo.py
def is_modified(self, other) -> bool:
    """Checks if the other experiment info is modified"""
    return self.last_modified != other.last_modified

Functions

experiment_info_factory

experiment_info_factory(data, path=None)

Creates an experiment info from a dictionary

Source code in niceml/experiments/experimentinfo.py
def experiment_info_factory(data: dict, path: Optional[str] = None) -> ExperimentInfo:
    """Creates an experiment info from a dictionary"""
    return ExperimentInfo(
        experiment_name=data[EXP_NAME_KEY],
        experiment_prefix=data[EXP_PREFIX_KEY],
        experiment_type=data.get(EXP_TYPE_KEY, ""),
        run_id=data[RUN_ID_KEY],
        short_id=data[SHORT_ID_KEY],
        environment=data.get(ENVIRONMENT_KEY, ""),
        description=data.get(DESCRIPTION_KEY, ""),
        exp_dir=data.get(EXP_DIR_KEY, ""),
        exp_filepath=path,
        last_modified=data.get(LAST_MODIFIED_KEY, None),
    )

get_exp_id_from_name

get_exp_id_from_name(input_name)

Returns a 4 digit alphanumeric string with the experiment id. The id follows after 'id_' and follow with a non alphanumeric char.

Source code in niceml/experiments/experimentinfo.py
def get_exp_id_from_name(input_name: str) -> str:
    """
    Returns a 4 digit alphanumeric string with the experiment id.
    The id follows after 'id_' and follow with a non alphanumeric char.
    """
    input_name = basename(input_name)
    index = input_name.rfind("id_")
    if index == -1:
        raise ExpIdNotFoundError(
            f"ID not found anywhere starting with 'id_': {input_name}"
        )
    cur_id = input_name[index + 3 : index + 7]
    if len(cur_id) != 4:  # noqa: PLR2004
        raise ExpIdNotFoundError(f"ID not complete: {input_name}")
    if any((x not in ALPHANUMERICLIST for x in cur_id)):
        raise ExpIdNotFoundError(
            f"ID shouldn't have any non alphanumeric chars: {cur_id}"
        )
    return cur_id

load_exp_info

load_exp_info(exp_info_file, file_system=None)

Loads an experiment info from a yaml file

Source code in niceml/experiments/experimentinfo.py
def load_exp_info(
    exp_info_file, file_system: Optional[AbstractFileSystem] = None
) -> ExperimentInfo:
    """Loads an experiment info from a yaml file"""
    file_system = file_system or LocalFileSystem()
    data = read_yaml(exp_info_file, file_system)

    exp_info = experiment_info_factory(data)
    return exp_info