kipe.provenance module
Provenance of a run: what ran, with which code, where; written next to the results.
recorded_run() writes, to the output directory of a subcommand (e.g.,
<output.path>/estimation/), next to the log and the results:
run.yaml: what the study does not hold: the status,runningwhile the run lasts, thenfinishedorfailed, with start and end time; for estimation, the assimilation times (which may come from the data files), and the path and SHA-256 hash of each data file it read (data_files()).study.yaml: the validated study options, with all defaults filled in: what actually ran. The comments of the study file are not kept; the CLI logs the study file’s path.environment.yaml: host, platform, Python, MPI, thread settings, and the versions of kipe, of the forward solver’s package and of the main libraries. For kipe and the solver’s package, also their git state if they are run from a git checkout (e.g., an editable install).<package>.patch: the uncommitted changes of such a checkout (git diff HEAD), so that a run from a modified checkout can be reproduced. Untracked files are not included.packages.txt: all installed Python distributions,name==version.spack.yamlandspack.lock, orconda_environment.yml: the environment, if the run happens in a Spack or conda environment.
Synthesis also writes data.sha256: the SHA-256 hash and path of each data file it wrote,
one per line, in the format of sha256sum, so sha256sum -c data.sha256 checks them
(from the directory kipe ran in, since the paths are relative to it).
Only rank 0 writes. The files are overwritten by the next run in the same directory.
- class kipe.provenance.DataFile[source]
Bases:
TypedDictA data file a run read, as recorded in
run.yaml.- path: str
Path to the file, as the run read it, e.g., with the realization filled in.
- sha256: str
SHA-256 hash of the file’s content.
- kipe.provenance.sha256(path: str | Path) str[source]
Return the SHA-256 hash of a file, e.g., of measurement data, to recognize it later.
- Parameters:
path – path to the file
- Returns:
the hash, as 64 hexadecimal digits
- kipe.provenance.data_files(study: StudyOptions, realization: int = 0) dict[str, DataFile][source]
Return the data file of each measurement of a study, with its hash.
- Parameters:
study – the study options
realization – number of the noise realization whose data are meant
- Returns:
measurement name -> data file
- Raises:
StudyFileError – if a data file cannot be read
- kipe.provenance.recorded_run(output: Path, study: StudyOptions, extra: Mapping[str, Any] | None = None, comm: mpi4py.MPI.Comm = mpi4py.MPI.COMM_WORLD) Iterator[None][source]
Write the provenance of the run in the
withblock, and its status at the end.- Parameters:
output – output directory of the subcommand
study – the study options
extra – further entries of
run.yamlthat the study file does not hold, e.g., the assimilation timescomm – communicator of the run; only its rank 0 writes
- Yields:
nothing; the run happens in the
withblock
- kipe.provenance.git_state(module: str, patch: Path | None = None) dict[str, Any] | None[source]
Return the git state of the checkout a module is run from, if any.
- Parameters:
module – import name of the module or package, e.g.,
"kipe"patch – file to write the uncommitted changes to (
git diff HEAD), if there are any
- Returns:
repository,commit,describe(e.g.,v0.1-3-gabc1234-dirty) anddirty; None if the module’s file is not tracked in a git checkout, e.g., for an installed package, or if git is not available