qxmt.experiment.repository module#
- class qxmt.experiment.repository.ExperimentRepository(logger)
Bases:
object
Repository class for handling experiment-related file system operations.
This class is responsible for managing the persistence layer of experiments, including directory creation, file operations, and JSON serialization/deserialization. It separates side-effecting operations from the core business logic.
- Parameters:
logger (Logger)
- _logger
Logger instance for logging operations.
- Type:
logging.Logger
- __init__(logger)
Initializes the ExperimentRepository.
- Parameters:
logger (logging.Logger) – Logger instance for logging operations.
- Return type:
None
- static check_json_extension(file_path)
Validates if the given file has a .json extension.
- Parameters:
file_path (str | Path) – Path to the file to be checked.
- Raises:
InvalidFileExtensionError – If the file does not have a .json extension.
- Return type:
None
- create_run_dir(experiment_dirc, run_id)
Creates a new run directory under the experiment directory.
- Parameters:
experiment_dirc (str | Path) – Path to the experiment directory.
run_id (int) – ID of the run to create directory for.
- Returns:
Path to the created run directory.
- Return type:
Path
- Raises:
Exception – If the run directory already exists or if there’s an error during directory creation.
- load(exp_file_path)
Loads experiment data from a JSON file.
- Parameters:
exp_file_path (str | Path) – Path to the JSON file containing experiment data.
- Returns:
Loaded experiment database object.
- Return type:
ExperimentDB
- Raises:
FileNotFoundError – If the specified file does not exist.
InvalidFileExtensionError – If the file does not have a .json extension.
- remove_run_dir(experiment_dirc, run_id)
Removes a run directory.
Used for rollback or back-fill operations.
- Parameters:
experiment_dirc (str | Path) – Path to the experiment directory.
run_id (int) – ID of the run whose directory should be removed.
- Return type:
None
- save(exp_db, save_path)
Serializes experiment data into JSON format and saves it to disk.
- Parameters:
exp_db (ExperimentDB) – Experiment database object to be serialized.
save_path (str | Path) – Path where the JSON file should be saved.
- Raises:
JsonEncodingError – If the object contains non-serializable data.
InvalidFileExtensionError – If the save path does not have a .json extension.
- Return type:
None