Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions neural_lam/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,40 @@ class InvalidConfigError(Exception):
def load_config_and_datastore(
config_path: str,
) -> tuple[NeuralLAMConfig, Union[MDPDatastore, NpyFilesDatastoreMEPS]]:
"""
Load the neural-lam configuration and the datastore specified in the
"""Load the neural-lam configuration and the datastore specified in the
configuration.

Parameters
----------
config_path : str
Path to the Neural-LAM configuration file.
Path to the Neural-LAM configuration file (YAML format).

Returns
-------
tuple[NeuralLAMConfig, Union[MDPDatastore, NpyFilesDatastoreMEPS]]
The Neural-LAM configuration and the loaded datastore.
The loaded Neural-LAM configuration object and the initialized datastore
instance (MDP or NpyFilesMEPS based on config).

Raises
------
FileNotFoundError
If the configuration file does not exist at the given path.
dataclass_wizard.errors.UnknownJSONKey
If the YAML contains unknown keys not defined in the config dataclass.
InvalidConfigError
If the configuration is invalid or cannot be deserialized properly
(wrapped around underlying errors).
ValueError
If the datastore kind specified in config is not implemented.

Examples
--------
>>> from pathlib import Path
>>> config, datastore = load_config_and_datastore("data/config.yaml")
>>> print(config.datastore.kind)
'npyfilesmeps'
>>> # Use datastore to load data batches
>>> batch = datastore.load_batch(...)
"""
try:
config = NeuralLAMConfig.from_yaml_file(config_path)
Expand Down