GNN4Colliders / tests /test_config.py
ho22joshua's picture
Claude Opus 5.5
refactor: flat modules, one YAML per experiment, no Hydra
0cef53c
Raw History Blame Contribute Delete
1.46 kB
from pathlib import Path
import pytest
from gnn4colliders.config import load_config, save_config
CONFIGS = sorted((Path(__file__).resolve().parents[1] / "configs").glob("*.yaml"))
@pytest.mark.parametrize("path", CONFIGS, ids=lambda path: path.stem)
def test_every_shipped_config_loads_and_round_trips(path, tmp_path):
config = load_config(path)
assert config.run_dir == f"outputs/{config.name}"
saved = save_config(config, tmp_path / "config.yaml")
assert load_config(saved) == config
def test_overrides_parse_yaml_values_and_fast_expands():
path = CONFIGS[0].parent / "gamgam.yaml"
config = load_config(
path,
[
"train.fast=true",
"train.learning_rate=1e-3",
"data.files=[{path: a, label: 1}]",
],
)
train = config.train
assert train.compile and train.cuda_graphs and train.allow_tf32
assert train.precision == "bfloat16" and train.learning_rate == 1e-3
assert config.data.files == [{"path": "a", "label": 1}]
@pytest.mark.parametrize(
"override, message",
[
("train.learnig_rate=1", "unknown config keys in train"),
("data.validation_folds=[0]", "disjoint"),
("task.name=binary", "out_size"),
("split", "key=value"),
],
)
def test_invalid_configs_are_rejected(override, message):
with pytest.raises(ValueError, match=message):
load_config(CONFIGS[0].parent / "gamgam.yaml", [override])