Skip to content

qlroms.utils.config

Short names for the standard test cases -- a directory, not a second config.

Everything a case is lives in its own module's TEST_CASES entry (physics, the windows it is generated with, the (K, r) its ql-ROMs are built at, the timescales its characterization needs). This module only maps a readable name onto one of those entries and reads it back, so there is exactly one place to edit a case:

from qlroms.utils.config import CASES, get_case
P = get_case("ks1d chaos")      # P["module"] is the imported case module,
                                # the rest is TEST_CASES["chaotic"], verbatim

A run that wants something other than the case's own settings overrides them where the run is described -- build_fom(overrides=...), or the case / rom blocks of a qlroms.utils.builder config -- never here.

case_module(name)

'ks1d', a registry name, or 'ks1d/chaotic' -> the imported case module.

Source code in qlroms/utils/config.py
28
29
30
31
32
33
34
35
def case_module(name: str):
    """``'ks1d'``, a registry name, or ``'ks1d/chaotic'`` -> the imported case module."""
    from ..intrusive_qlroms import ks1d, ks2d
    modules = {"ks1d": ks1d, "ks2d": ks2d}
    key = CASES[name][0] if name in CASES else str(name).partition("/")[0]
    if key not in modules:
        raise ValueError(f"Unknown case module {key!r}; choose from {sorted(modules)}.")
    return modules[key]

get_case(name)

Registry entry name as the case module states it, plus module and case.

The settings are read live from TEST_CASES (with the 2-D TIME_DEFAULTS windows beneath them), never copied, so editing the case edits this too.

Source code in qlroms/utils/config.py
38
39
40
41
42
43
44
45
46
47
48
49
def get_case(name: str) -> dict:
    """Registry entry `name` as the case module states it, plus `module` and `case`.

    The settings are read live from `TEST_CASES` (with the 2-D `TIME_DEFAULTS` windows
    beneath them), never copied, so editing the case edits this too.
    """
    if name not in CASES:
        raise ValueError(f"Unknown case {name!r}; choose from {sorted(CASES)}.")
    module = case_module(name)
    case = CASES[name][1]
    return {**getattr(module, "TIME_DEFAULTS", {}), **module.TEST_CASES[case],
            "module": module, "case": case}