pytyche.experiments.manifest¶
Versioned experiment manifest builder, validator, and atomic writer.
The canonical JSON Schema document lives at
docs/specs/experiment-manifest-schema.json. Validation is hand-rolled
rather than via jsonschema so error messages can name the offending
field directly, and so this module imports cleanly without heavy ML deps.
Module Attributes
Current schema version. |
Functions
|
Build a manifest dict with required top-level fields populated. |
|
Validate a manifest; raise |
|
Atomically write |
- pytyche.experiments.manifest.MANIFEST_SCHEMA_VERSION: int = 1¶
Current schema version. Bump for breaking changes; keep in sync with
docs/specs/experiment-manifest-schema.json($id v1 → version 1).
- pytyche.experiments.manifest.build_manifest(*, experiment_id, params, pytyche_extensions, data_provenance)[source]¶
Build a manifest dict with required top-level fields populated.
git(sha / dirty / branch),env(python / platform), andtimestamp_utcare resolved at call time from the ambient environment (gitvia subprocess againstPath.cwd();envviasysandplatform;timestamp_utcviadatetime.now(timezone.utc)).pytyche_extensionsis a{capability: content}dict; each entry is nested under the reserved top-levelpytychekey, e.g.pytyche_extensions={"calibration": {...}}lands atmanifest["pytyche"]["calibration"]. An empty extensions dict still produces an emptymanifest["pytyche"]object so consumers can rely on the key existing.The returned dict is intentionally not validated here — call
validate_manifest()separately if you want to assert correctness before writing.- Parameters:
experiment_id (
str) – Unique identifier, conventionally{iso8601}_{short_sha}.params (
dict[str,Any]) – Free-form per-experiment hyperparameters.pytyche_extensions (
dict[str,Any]) – Mapping from capability name (e.g."calibration") to its nested content object. Goes under the reservedpytychetop-level key.data_provenance (
dict[str,Any]) – Discriminated-union dict; either{"kind": "synthetic", "seed": int}or{"kind": "external", "hashes": {name: sha256_hex}}.
- Returns:
The constructed manifest. Caller owns persistence.
- Return type:
dict[str,Any]
- pytyche.experiments.manifest.validate_manifest(manifest)[source]¶
Validate a manifest; raise
ValueErroron any violation.Accepts
objectrather thandictbecause callers feed this fromjson.load()of untrusted files — the runtime value may be a list,None, a string, etc. The isinstance narrowing below is the boundary check; downstream code only runs once we know we have a dict.Checks performed (each failure raises with an error message that names the offending field(s) — no silent catch-all messages):
Top-level value is a dict.
Required top-level fields are present (names listed in the error).
No foreign top-level keys (anything not required and not
pytyche).data_provenanceis a dict with a validkinddiscriminator, and forkind == "external"thehashesmap is non-empty.
Passes silently when valid.
- Parameters:
manifest (
object)- Return type:
None
- pytyche.experiments.manifest.write_manifest(manifest, path)[source]¶
Atomically write
manifestas JSON topath.Uses a temporary file in the same directory followed by
os.replaceso partial writes are never visible atpath(POSIX-atomic rename). The temporary file is cleaned up on failure.- Parameters:
manifest (
dict[str,Any]) – The manifest dict. Caller is responsible for validating it first if desired — this function only persists.path (
str|Path) – Destination path. The parent directory must already exist.
- Return type:
None