mixle.inference.production.provenance module

Reproducible model artifacts: a descriptive header logging what trained a model and how.

A Header records the estimator/model configuration, a summary + content hash of the training data, the data schema, the training settings and final objective, timing, and the software environment (versions + git commit). Attach one at fit time with fit_with_provenance() (or build one for any model + data with build_header()) so a fitted model is self-describing and a run can be reproduced and audited. Headers are plain dicts under the hood (Header.to_dict()), so they serialize to JSON alongside the model.

environment_info()[source]

Snapshot of the software/hardware environment for reproducibility.

Return type:

dict

class Header(model_type, model_summary, schema, n_records, dataset_hash, final_loglik, model_hash=None, training=<factory>, timing=<factory>, resources=<factory>, environment=<factory>, created_at='')[source]

Bases: object

A descriptive, serializable provenance record for a fitted model.

Parameters:
model_type: str
model_summary: str
schema: list[tuple[str, str]]
n_records: int | None
dataset_hash: str
final_loglik: float | None
model_hash: str | None = None
training: dict
timing: dict
resources: dict
environment: dict
created_at: str = ''
to_dict()[source]
Return type:

dict

classmethod from_dict(d)[source]
Parameters:

d (dict)

Return type:

Header

build_header(model, data, *, training=None, started=None, finished=None, final_loglik='auto', resources=None, hash_sort=False, hash_max_records=None)[source]

Build a Header for model trained on data (does not run any fitting).

Parameters:
  • model (Any)

  • data (Any)

  • training (dict | None)

  • started (float | None)

  • finished (float | None)

  • final_loglik (Any)

  • resources (dict | None)

  • hash_sort (bool)

  • hash_max_records (int | None)

Return type:

Header

fit_with_provenance(data, estimator, *, seed=None, lineage=True, **optimize_kw)[source]

Fit estimator on data via EM (mixle.inference.optimize()) and return (model, header), the model carrying a .header Header with the data hash, the final model hash, schema, training settings + per-iteration convergence trace, timing, final log-likelihood, and environment. Pass your own out= to print iterations (then the trace is not captured).

With lineage=True (default) each iteration in the convergence trace also records the accepted model’s model_hash and the previous iteration’s parent_hash, forming a verifiable hash chain (check it with verify_lineage()). This fingerprints the model every iteration; pass lineage=False to skip it for very large models. Any user on_step= is still called.

Parameters:
verify_lineage(header)[source]

Check that a header’s per-iteration convergence trace is an intact model-hash chain.

Returns True when every iteration that recorded a model_hash names the previous such iteration’s hash as its parent_hash (so iteration i+1 provably descends from i), and True vacuously when the trace carries no lineage (fit_with_provenance(lineage=False) or a custom out). Returns False on the first broken link. Accepts a Header or its to_dict.

Parameters:

header (Any)

Return type:

bool