Configuration Manager

class seawrd.config_manager.ConfigManager(config: SEAWRDConfig, config_path: str | Path | None = None)

Bases: object

A class to manage the loading and validation of the SEAWRD configuration from a TOML file.

classmethod from_toml(path: str | Path) ConfigManager

Create a ConfigManager instance from a TOML configuration file.

Parameters:

path (str | Path) – The path to the TOML configuration file.

Returns:

An instance of ConfigManager initialized with the loaded configuration.

Return type:

ConfigManager

to_dict() dict[str, Any]

Convert the current configuration to a dictionary representation.

Returns:

The dictionary representation of the configuration.

Return type:

dict[str, Any]

with_override(dotted_key: str, value: Any) ConfigManager

Return a new ConfigManager with an updated value for a specific configuration field.

Example

cfg2 = cfg.with_override(“training.batch_size”, 2048) cfg3 = cfg.with_override(“model.num_neurons”, 64)

Parameters:
  • dotted_key (str) – The dotted key representing the configuration field to update. In format “section.field”, e.g., “training.batch_size”.

  • value (Any) – The new value for the configuration field.

Returns:

A new ConfigManager instance with the updated value.

Return type:

ConfigManager

Raises:

KeyError – If the specified section or field is not found in the configuration.

with_overrides(overrides: dict[str, Any]) ConfigManager

Return a new ConfigManager with multiple updated values.

Parameters:

overrides (dict[str, Any]) – A dictionary of dotted keys and their corresponding values to override.

Returns:

A new ConfigManager instance with the updated values.

Return type:

ConfigManager