Configuration

class seawrd.config.CallbackConfig(reduce_lr: bool = True, reduce_lr_monitor: str = 'val_loss', reduce_lr_factor: float = 0.5, reduce_lr_patience: int = 20, min_lr: float = 1e-06, early_stopping: bool = True, early_stopping_monitor: str = 'val_loss', early_stopping_patience: int = 50)

Bases: ConfigSection

Configuration for Keras callbacks during training.

early_stopping: bool = True
early_stopping_monitor: str = 'val_loss'
early_stopping_patience: int = 50
min_lr: float = 1e-06
reduce_lr: bool = True
reduce_lr_factor: float = 0.5
reduce_lr_monitor: str = 'val_loss'
reduce_lr_patience: int = 20
class seawrd.config.CompileConfig(loss: str = 'mean_squared_error', optimiser: Literal['adam'] = 'adam', learning_rate: float = 0.005, metrics: tuple[str, ...] = ('mean_squared_error',), steps_per_execution: int = 1, jit_compile: str | bool = 'auto')

Bases: ConfigSection

Configuration for compiling the Keras model.

classmethod from_dict(data: Mapping[str, Any] | None = None) CompileConfig

Create a CompileConfig instance from a dictionary representation.

Overrides the base from_dict method to ensure that the ‘metrics’ field is converted to a tuple if it is provided as a list.

Parameters:

data (Mapping[str, Any] | None, optional) – The dictionary representation of the configuration, by default None

Returns:

The created CompileConfig instance

Return type:

CompileConfig

jit_compile: str | bool = 'auto'
learning_rate: float = 0.005
loss: str = 'mean_squared_error'
metrics: tuple[str, ...] = ('mean_squared_error',)
optimiser: Literal['adam'] = 'adam'
steps_per_execution: int = 1
class seawrd.config.ConfigSection

Bases: object

Base helper for simple dataclass config sections, with potential for future extensions.

classmethod from_dict(data: Mapping[str, Any] | None = None) Self

Load a dataclass instance from a dictionary, ensuring that only known fields are used for initialisation.

This allows for creation of dataclass instances (i.e., ConfigSections) from dictionaries while validating that the provided keys match the expected fields of the dataclass.

Parameters:
  • cls (type[Self]) – The dataclass type to instantiate.

  • data (Mapping[str, Any] | None, optional) – The dictionary containing the configuration data, by default None

Returns:

An instance of the dataclass initialized with the provided configuration.

Return type:

Self

Raises:

ValueError – If there are unknown fields in the data dictionary that do not correspond to any fields in the dataclass.

to_dict() dict[str, Any]

Convert the dataclass instance to a dictionary.

Returns:

A dictionary representation of the dataclass instance, including all fields and their values.

Return type:

dict[str, Any]

with_update(**updates: Any) Self

Create a new instance of the dataclass with updated fields.

Parameters:
  • self (Self) – The current instance of the dataclass.

  • **updates (Any) – Keyword arguments representing the fields to update and their new values.

Returns:

A new instance of the dataclass with the specified fields updated.

Return type:

Self

Raises:

ValueError – If there are unknown fields in the updates that do not correspond to any fields in the dataclass.

class seawrd.config.DeviceConfig(mode: Literal['auto', 'cpu', 'gpu'] = 'auto', benchmark_device: bool = True, min_gpu_speedup: float = 1.2, warmup_epochs: int = 10, benchmark_epochs: int = 100, benchmark_repeats: int = 3)

Bases: ConfigSection

Configuration for the device on which to run the training (CPU or GPU).

benchmark_device: bool = True
benchmark_epochs: int = 100
benchmark_repeats: int = 3
min_gpu_speedup: float = 1.2
mode: Literal['auto', 'cpu', 'gpu'] = 'auto'
warmup_epochs: int = 10
class seawrd.config.ModelConfig(model_name: str = '', num_layers: int = 4, num_neurons: int = 8, num_outputs: int = 1, activation: str = 'relu', use_normalisation: bool = True)

Bases: ConfigSection

Configuration for the model architecture.

activation: str = 'relu'
model_name: str = ''
num_layers: int = 4
num_neurons: int = 8
num_outputs: int = 1
use_normalisation: bool = True
class seawrd.config.OutputConfig(model_dir: str = 'models/', cache_dir: str = 'cache/', use_cache: bool = True, version: int = 1, save_model: bool = True, save_plots: bool = True)

Bases: ConfigSection

Configuration for output settings, including model saving and plot generation.

cache_dir: str = 'cache/'
model_dir: str = 'models/'
save_model: bool = True
save_plots: bool = True
use_cache: bool = True
version: int = 1
class seawrd.config.SEAWRDConfig(model: ModelConfig, training: TrainingConfig, compile: CompileConfig, callbacks: CallbackConfig, device: DeviceConfig, output: OutputConfig)

Bases: object

Main configuration class for the SEAWRD framework. This class aggregates all the individual configuration sections into a single, unified configuration object.

callbacks: CallbackConfig
compile: CompileConfig
device: DeviceConfig
classmethod from_dict(raw: Mapping[str, Any] | None = None) SEAWRDConfig

Create a SEAWRDConfig instance from a dictionary representation.

Parameters:

raw (Mapping[str, Any] | None, optional) – The dictionary representation of the configuration, by default None

Returns:

The initialized SEAWRDConfig instance

Return type:

SEAWRDConfig

Raises:

ValueError – If there are unknown sections in the provided dictionary that do not correspond to any of the expected configuration sections.

model: ModelConfig
output: OutputConfig
to_dict() dict[str, Any]

Convert the SEAWRDConfig dataclass into a dictionary representation.

Returns:

A dictionary representation of the SEAWRDConfig dataclass, including all nested configurations.

Return type:

dict[str, Any]

training: TrainingConfig
with_update(**updates: Any) SEAWRDConfig

Create a new SEAWRDConfig instance with updated sections.

Parameters:

**updates (Any) – Keyword arguments representing the sections to update and their new values.

Returns:

A new instance of SEAWRDConfig with the specified sections updated.

Return type:

SEAWRDConfig

Raises:

ValueError – If there are unknown sections in the updates that do not correspond to any of the expected configuration sections.

with_update_section(section_name: str, **updates: Any) SEAWRDConfig

Create a new SEAWRDConfig instance with an updated section.

Parameters:
  • section_name (str) – The name of the section to update (e.g., ‘model’, ‘training’).

  • **updates (Any) – Keyword arguments representing the fields to update within the specified section.

Returns:

A new instance of SEAWRDConfig with the specified section updated.

Return type:

SEAWRDConfig

Raises:
  • KeyError – If the specified section is not found in the configuration.

  • ValueError – If there are unknown fields in the updates that do not correspond to any fields in the specified section.

class seawrd.config.TrainingConfig(num_epochs: int = 200, batch_size: int = 1024, validation_split: float = 0.2, num_models: int = 5, shuffle: bool = True)

Bases: ConfigSection

Configuration for the training process.

batch_size: int = 1024
num_epochs: int = 200
num_models: int = 5
shuffle: bool = True
validation_split: float = 0.2