2.23.5.1. pycsamt.format.provenance#

Provenance of models predicted by learned methods.

The implementation lives in the standalone pcsf package (pcsf.core.provenance), the reference implementation of the format. This module re-exports it under its pyCSAMT name, so that existing imports keep working and pyCSAMT objects are the pcsf objects themselves.

See also

pcsf.core.provenance

Implementation.

class pycsamt.format.provenance.ModelProvenance(architecture='', framework='', framework_version='', checkpoint='', checkpoint_sha256='', training_data='', hyperparameters=<factory>, random_seed=None, git_commit='', authors=<factory>, contact='', notes='', extra=<factory>)

Bases: PCSFObject

Describe the AI/DL model that produced a resistivity result.

Parameters:
  • architecture (str, optional) – Free-text model family/architecture, e.g. "UNet", "GCN", "ResNet18", or any third-party name.

  • framework (str, optional) – e.g. "pytorch"/"2.3.0", "tensorflow"/"2.16.1".

  • framework_version (str, optional) – e.g. "pytorch"/"2.3.0", "tensorflow"/"2.16.1".

  • checkpoint (str, optional) – Path or identifier of the trained weights used to produce the result (e.g. a filename, a model-hub id, a DOI).

  • checkpoint_sha256 (str, optional) – SHA-256 hex digest of the checkpoint file, so a reader can verify they are re-running the exact weights this result claims – see compute_checkpoint_hash().

  • training_data (str, optional) – Free-text reference to the training dataset (name, DOI, path).

  • hyperparameters (dict, default {}) – Free-form training/model hyperparameters.

  • random_seed (int, optional) – Seed used for training and/or inference, when reproducibility depends on it.

  • git_commit (str, optional) – Commit hash of the code that produced this result.

  • authors (list of str, default []) – Model authors/maintainers.

  • contact (str, optional) – Contact e-mail or URL for questions about this result.

  • notes (str, optional) – Free-text notes not covered by the fields above.

  • extra (dict, default {}) – Unmodelled provenance fields, retained losslessly.

Examples

>>> from pcsf.core.provenance import ModelProvenance
>>> prov = ModelProvenance(
...     architecture="UNet",
...     framework="pytorch",
...     framework_version="2.3.0",
...     checkpoint="unet_v3.pt",
...     random_seed=42,
... )
>>> prov.to_dict()["architecture"]
'UNet'
architecture: str = ''
framework: str = ''
framework_version: str = ''
checkpoint: str = ''
checkpoint_sha256: str = ''
training_data: str = ''
hyperparameters: dict[str, Any]
random_seed: int | None = None
git_commit: str = ''
authors: list[str]
contact: str = ''
notes: str = ''
extra: dict[str, Any]
validate()

Check field types.

Raises:

TypeError – If random_seed is neither an int nor None.

Return type:

None

to_dict()

Plain dictionary form of the provenance.

Returns:

Every field, with containers copied; suitable for PCSFModel.metadata["model_provenance"].

Return type:

dict

pycsamt.format.provenance.compute_checkpoint_hash(path, *, chunk_size=1048576)

SHA-256 of a model-checkpoint file, read in chunks.

Parameters:
  • path (path-like) – The checkpoint file to hash (e.g. a .pt/.h5/.onnx file).

  • chunk_size (int, default 1 MiB) – Read block size; large checkpoints are hashed without loading the whole file into memory.

Returns:

Lowercase hex digest, directly comparable to ModelProvenance.checkpoint_sha256.

Return type:

str

Examples

>>> from pcsf.core.provenance import compute_checkpoint_hash
>>> compute_checkpoint_hash("unet_v3.pt")
'3b1c...'