Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion deep_lst/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def experiment_name(config: dict, choices: dict) -> str:


def validate_config(config: dict) -> None:
"""Fail on an objective that the chosen data option cannot serve, before any data is read."""
"""Validate the objective and loader settings before any data is read."""
keys = get_keys_from_config(split_views(config)["train"])
prognostic_keys = keys["prognostic_keys"]
diagnostic_keys = keys["diagnostic_keys"]
Expand All @@ -278,6 +278,14 @@ def validate_config(config: dict) -> None:
f"(data=full_joint); no diagnostic copy of {without_copy}"
)

training = config["training"]
batch_size = training.get("batch_size")
if type(batch_size) is not int or batch_size < 1:
raise ValueError(f"training.batch_size must be a positive integer (got {batch_size!r})")
num_workers = training.get("num_workers")
if type(num_workers) is not int or num_workers < 0:
raise ValueError(f"training.num_workers must be a non-negative integer (got {num_workers!r})")


def get_keys_from_config(dataset_config):
in_keys = []
Expand Down
25 changes: 25 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ def test_the_combinations_in_use_are_valid(overrides):
validate_config(_config(overrides))


def test_training_loader_settings_allow_batch_size_one_and_zero_workers():
validate_config(_config(["training.batch_size=1", "training.num_workers=0"]))


@pytest.mark.parametrize(
("field", "value"),
[
("batch_size", "0"),
("batch_size", "-1"),
("batch_size", "invalid"),
("batch_size", "1.5"),
("batch_size", "true"),
("batch_size", '"2"'),
("num_workers", "-1"),
("num_workers", "invalid"),
("num_workers", "1.5"),
("num_workers", "false"),
("num_workers", '"2"'),
],
)
def test_training_loader_settings_reject_invalid_values(field, value):
with pytest.raises(ValueError, match=rf"^training\.{field} must be"):
validate_config(_config([f"training.{field}={value}"]))


def test_diagnostic_objective_refuses_a_data_option_with_a_prognostic():
with pytest.raises(ValueError, match="objective=diagnostic needs a data option without prognostics"):
validate_config(_config(["objective=diagnostic", "data=full"]))
Expand Down
Loading