Skip to content

Registry

gwmock_signal.registry

Public source-type registry for gwmock-signal simulator backends.

list_registered_source_types()

Return the registered source-type keys in sorted order.

Source code in src/gwmock_signal/registry.py
83
84
85
def list_registered_source_types() -> tuple[str, ...]:
    """Return the registered source-type keys in sorted order."""
    return tuple(sorted(_SOURCE_TYPE_REGISTRY))

register_simulator_backend(source_type, backend)

Register a simulator backend class for a gwmock-pop source_type.

Registration is intentionally class-based rather than instance-based so the downstream lookup contract stays stable even when different backends require different constructor arguments.

Parameters:

Name Type Description Default
source_type str

gwmock-pop source-family key such as "bbh".

required
backend type[GWSimulator]

Concrete GWSimulator subclass implementing that source type.

required

Raises:

Type Description
TypeError

If backend is not a GWSimulator subclass.

ValueError

If source_type is empty or already registered to a different backend.

Source code in src/gwmock_signal/registry.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def register_simulator_backend(source_type: str, backend: type[GWSimulator]) -> None:
    """Register a simulator backend class for a gwmock-pop ``source_type``.

    Registration is intentionally class-based rather than instance-based so the
    downstream lookup contract stays stable even when different backends require
    different constructor arguments.

    Args:
        source_type: gwmock-pop source-family key such as ``"bbh"``.
        backend: Concrete ``GWSimulator`` subclass implementing that source type.

    Raises:
        TypeError: If *backend* is not a ``GWSimulator`` subclass.
        ValueError: If *source_type* is empty or already registered to a
            different backend.
    """
    if not issubclass(backend, GWSimulator):
        raise TypeError("backend must be a GWSimulator subclass")

    normalized = _normalize_source_type(source_type)
    existing = _SOURCE_TYPE_REGISTRY.get(normalized)
    if existing is not None and existing is not backend:
        raise ValueError(
            f"source_type {normalized!r} is already registered to {existing.__name__}; "
            f"refusing to replace it with {backend.__name__}"
        )

    _SOURCE_TYPE_REGISTRY[normalized] = backend

resolve_simulator_backend(source_type)

Resolve the registered simulator backend class for a source type.

Parameters:

Name Type Description Default
source_type str

gwmock-pop source-family key such as "bbh".

required

Returns:

Type Description
type[GWSimulator]

The registered concrete GWSimulator subclass.

Raises:

Type Description
KeyError

If no backend is registered for source_type.

ValueError

If source_type is empty.

Source code in src/gwmock_signal/registry.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def resolve_simulator_backend(source_type: str) -> type[GWSimulator]:
    """Resolve the registered simulator backend class for a source type.

    Args:
        source_type: gwmock-pop source-family key such as ``"bbh"``.

    Returns:
        The registered concrete ``GWSimulator`` subclass.

    Raises:
        KeyError: If no backend is registered for *source_type*.
        ValueError: If *source_type* is empty.
    """
    normalized = _normalize_source_type(source_type)
    try:
        return _SOURCE_TYPE_REGISTRY[normalized]
    except KeyError as exc:
        raise KeyError(f"No simulator backend is registered for source_type={normalized!r}") from exc

The built-in CBC backend is registered under the key bbh. For the simulator classes returned by resolve_simulator_backend, see Simulator.

For a short Python example of resolve_simulator_backend, see the README on the project home page.