Instrument catalog v2: evidence-backed model records grouped by family (GH #549, MC1a).
The v1 catalog (plugins/marianne/docs/ref/instrument-catalog.yaml) is one
2,700-line file whose tiers are price bands and whose entries mostly carry a
single verification date. v2 is a directory: one YAML per model family plus an
index.yaml. Each model says which Marianne profiles (or services) reach it
and how it is paid for, which reasoning efforts it maps, and which capability
tier it sits in at each effort, so a class such as "Opus-class at high" can be
generated from data instead of from a price band.
This module is pure schema plus a validating loader. Nothing at runtime reads
the catalog yet.
Attributes
Classes
CatalogError
Bases: ValueError
The catalog directory is missing, malformed, or inconsistent.
Functions:
load_catalog
Load and cross-check a v2 catalog directory.
Raises CatalogError naming the file for any schema violation, a family file
that disagrees with the index, or a model id used twice.
Source code in src/marianne/core/config/catalog.py
| def load_catalog(directory: Path) -> Catalog:
"""Load and cross-check a v2 catalog directory.
Raises CatalogError naming the file for any schema violation, a family file
that disagrees with the index, or a model id used twice.
"""
index_path = directory / INDEX_FILENAME
if not index_path.is_file():
raise CatalogError(f"no {INDEX_FILENAME} in {directory}")
try:
index = CatalogIndex.model_validate(_read_yaml(index_path))
except ValidationError as exc:
raise CatalogError(f"{index_path}: {exc}") from exc
files: dict[str, CatalogFile] = {}
owner: dict[str, str] = {}
for slug, entry in index.families.items():
path = directory / entry.file
if not path.is_file():
raise CatalogError(f"{index_path} lists {entry.file}, which does not exist")
try:
file = CatalogFile.model_validate(_read_yaml(path))
except ValidationError as exc:
raise CatalogError(f"{path}: {exc}") from exc
if list(file.families) != [slug]:
raise CatalogError(
f"{path}: families {list(file.families)} but the index says '{slug}'"
)
ids = [model.id for model in file.families[slug]]
if ids != entry.model_ids:
raise CatalogError(f"{path}: model ids differ from the index")
for model_id in ids:
if model_id in owner:
raise CatalogError(
f"model id '{model_id}' is in both '{owner[model_id]}' and '{slug}'"
)
owner[model_id] = slug
files[slug] = file
on_disk = {p.name for p in directory.glob("*.yaml")} - {INDEX_FILENAME}
unlisted = on_disk - {entry.file for entry in index.families.values()}
if unlisted:
raise CatalogError(f"family files missing from the index: {sorted(unlisted)}")
return Catalog(index=index, files=files)
|