Skip to content

Family schemas

These keyword schemas fix the parameter names and argument structure that a call of a distribution family in QVR source must match (fixed and conditional families). They catch an error such as a scale keyword given where the family expects a rate before any backend distribution is built.

family_schemas

QVR adapter for the dependency-free shared constructor schemas.

The core and source boundaries consume the same complete alternatives. This module retains the source tooling import path without maintaining another table.

DISTRIBUTION_FAMILIES module-attribute

DISTRIBUTION_FAMILIES: frozenset[str] = frozenset((*_FAMILY_PARAMETERS, *FAMILY_ALIASES))

Every distribution-family name accepted in QVR source.

Highlighters consume this set so their surface vocabulary follows the same schemas used by validation and lowering.

FAMILY_ALIASES module-attribute

FAMILY_ALIASES: dict[str, str] = {'Pushforward': 'Transformed', 'Truncate': 'Restrict'}

Surface family names that resolve to another family's registry record.

A key is a name a source may write; its value is the family whose specification builds the distribution.

PARAMETER_ALIASES module-attribute

PARAMETER_ALIASES: dict[str, dict[str, str]] = {'LogitNormal': {'mu': 'loc', 'sigma': 'scale'}, 'TruncatedNormal': {'mu': 'loc', 'sigma': 'scale'}, 'Mixture': {'components': 'component'}, 'OrderedLogistic': {'predictor': 'eta'}, 'Pushforward': {'bijector': 'transforms'}}

Surface keywords that name a registry parameter under another name.

A family's entry maps each keyword a source may write to the registry parameter it fills, which means the same quantity. A keyword absent here and from the registry record names no parameter of the family.

family_parameter_names

family_parameter_names(family: str) -> tuple[str, ...] | None

Return the canonical QVR keyword order for family.

PARAMETER DESCRIPTION
family

The family name as written in source.

TYPE: str

RETURNS DESCRIPTION
tuple[str, ...] | None

The keyword names in canonical order, or None when no keyword schema is declared for family.

Source code in src/quivers/_family_schemas.py
def family_parameter_names(family: str) -> tuple[str, ...] | None:
    """Return the canonical QVR keyword order for ``family``.

    Parameters
    ----------
    family : str
        The family name as written in source.

    Returns
    -------
    tuple[str, ...] | None
        The keyword names in canonical order, or None when no keyword
        schema is declared for ``family``.
    """
    return _FAMILY_PARAMETERS.get(family)

family_parameterizations

family_parameterizations(family: str, canonical: tuple[str, ...]) -> tuple[tuple[str, ...], ...]

Return every complete keyword schema accepted by family.

PARAMETER DESCRIPTION
family

The family name as written in source.

TYPE: str

canonical

The parameter names the family's registry record declares, used when no schema for family is declared here.

TYPE: tuple[str, ...]

RETURNS DESCRIPTION
tuple[tuple[str, ...], ...]

One tuple of keyword names per accepted parameterization, empty when the family takes no parameters.

Source code in src/quivers/_family_schemas.py
def family_parameterizations(
    family: str, canonical: tuple[str, ...]
) -> tuple[tuple[str, ...], ...]:
    """Return every complete keyword schema accepted by ``family``.

    Parameters
    ----------
    family : str
        The family name as written in source.
    canonical : tuple[str, ...]
        The parameter names the family's registry record declares,
        used when no schema for ``family`` is declared here.

    Returns
    -------
    tuple[tuple[str, ...], ...]
        One tuple of keyword names per accepted parameterization, empty
        when the family takes no parameters.
    """
    alternatives = _ALTERNATIVE_SCHEMAS.get(family)
    if alternatives is not None:
        if family in ("Restrict", "Truncate"):
            # Endpoint policies are independent optional Boolean arguments.
            # Retain the legacy positional schema and accept every explicit
            # subset without inventing a second operator construction path.
            return tuple(
                (*schema, *flags)
                for schema in alternatives
                for flags in (
                    (),
                    ("lower_closed",),
                    ("upper_closed",),
                    ("lower_closed", "upper_closed"),
                )
            )
        return alternatives
    parameters = _FAMILY_PARAMETERS.get(family, canonical)
    return (parameters,) if parameters else ()