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.

Source identity is taken from the ambient repository when there is one, and otherwise from the installed artifact’s embedded build provenance. provenance_source names which, because “no repository here” and “a clean repository” are different facts and were previously reported the same way.

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:
to_dict()[source]

Return the provenance header as a plain dictionary.

Return type:

dict

classmethod from_dict(d)[source]

Reconstruct a provenance header from a dictionary.

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 records a digest-chained transition from the previous accepted model, and a terminal record binds the model actually returned by the optimizer (check it with verify_lineage(); the digests bind the iteration sequence and the model, not the header’s dataset hash, record count, or log-likelihood values, which stay recorded claims). 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]

Verify a complete execution-recorded EM transition chain.

Missing lineage is an unverified result, never a vacuous success. Each iteration must bind its actual model hash to the previous model and transition digests, all records must share one run id, and the final executed model hash must equal the header’s fitted-model hash.

Parameters:

header (Any)

Return type:

bool