vector-mtrl 0.4.2__tar.gz → 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/CHANGELOG.md +72 -0
  2. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/PKG-INFO +1 -1
  3. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/units-of-measure.md +7 -3
  4. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/prepare-an-ml-dataset.md +23 -32
  5. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/use-scientific-python-libraries.md +3 -1
  6. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/reference.md +33 -16
  7. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/02-save-load-verify.md +6 -4
  8. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/04-handles-and-the-core.md +6 -3
  9. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/05-fix-a-mistake.md +10 -6
  10. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/07-get-your-data-out.md +4 -2
  11. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_archive_integrity.py +118 -1
  12. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_archive_loading.py +49 -10
  13. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_archive_serialise.py +134 -23
  14. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_candidate_matching.py +4 -1
  15. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_summaries.py +79 -49
  16. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_summary_text.py +18 -5
  17. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_unit_summary.py +14 -17
  18. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/features.py +9 -1
  19. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/frames.py +13 -10
  20. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/integrity/canonical.py +15 -0
  21. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/integrity/manifest.py +57 -5
  22. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/integrity/receipts.py +4 -2
  23. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/integrity/verification.py +6 -3
  24. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_dataset.py +24 -7
  25. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_flat.py +23 -28
  26. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_summaries.py +12 -12
  27. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/mtrl.py +51 -1
  28. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/processing/registry.py +1 -1
  29. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/sample.py +7 -5
  30. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/pyproject.toml +7 -1
  31. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/.gitignore +0 -0
  32. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/LICENSE +0 -0
  33. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/NOTICE +0 -0
  34. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/README.md +0 -0
  35. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/01-samples-runs-checkpoints.md +0 -0
  36. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/02-the-commit-boundary.md +0 -0
  37. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/03-two-kinds-of-identity.md +0 -0
  38. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/04-corrections-vs-replacements.md +0 -0
  39. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/05-lineage-and-the-recorded-recipe.md +0 -0
  40. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/06-revisions-the-archive-timeline.md +0 -0
  41. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/07-inside-a-mtrl-archive.md +0 -0
  42. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/08-trust-over-time.md +0 -0
  43. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/concepts/index.md +0 -0
  44. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/align-mixed-resolution-members.md +0 -0
  45. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/anchor-verification-with-receipts.md +0 -0
  46. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/attach-author-disclosure.md +0 -0
  47. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/author-an-ingestion-loader.md +0 -0
  48. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/check-external-evidence.md +0 -0
  49. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/control-the-operation-registry.md +0 -0
  50. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/handle-missing-extras.md +0 -0
  51. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/handle-selection-and-data-errors.md +0 -0
  52. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/index.md +0 -0
  53. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/inspect-a-damaged-archive.md +0 -0
  54. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/record-scientific-assertions.md +0 -0
  55. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/replace-a-checkpoint.md +0 -0
  56. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/replay-a-committed-chain.md +0 -0
  57. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/how-to/resample-with-scipy.md +0 -0
  58. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/01-your-first-record.md +0 -0
  59. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/03-transform-and-plot.md +0 -0
  60. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/06-replicates-and-the-mean.md +0 -0
  61. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/08-record-a-claim.md +0 -0
  62. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/docs/user/start-here/09-one-complete-analysis.md +0 -0
  63. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/__init__.py +0 -0
  64. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_alignment_report.py +0 -0
  65. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_archive_documents.py +0 -0
  66. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_assertions_io.py +0 -0
  67. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_assertions_ops.py +0 -0
  68. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_assertions_validation.py +0 -0
  69. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_cli.py +0 -0
  70. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_disclosure.py +0 -0
  71. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_install_targets.py +0 -0
  72. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_optional.py +0 -0
  73. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_provenance.py +0 -0
  74. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_receipts.py +0 -0
  75. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_record_resolution.py +0 -0
  76. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_replay_plan.py +0 -0
  77. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_replay_run.py +0 -0
  78. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_run_management.py +0 -0
  79. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_source_capture.py +0 -0
  80. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_table_plan.py +0 -0
  81. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_table_provenance.py +0 -0
  82. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_table_values.py +0 -0
  83. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_transform_apply.py +0 -0
  84. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_transform_validation.py +0 -0
  85. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/_uuid7.py +0 -0
  86. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/archive/__init__.py +0 -0
  87. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/archive/canonical.py +0 -0
  88. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/archive/codecs.py +0 -0
  89. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/archive/dtypes.py +0 -0
  90. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/archive/reader.py +0 -0
  91. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/archive/validation.py +0 -0
  92. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/assertions/__init__.py +0 -0
  93. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/assertions/_resolver.py +0 -0
  94. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/connectors/__init__.py +0 -0
  95. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/connectors/protocols.py +0 -0
  96. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/disclosure.py +0 -0
  97. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/__init__.py +0 -0
  98. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/archive_limits.py +0 -0
  99. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/assertions.py +0 -0
  100. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/committed_values.py +0 -0
  101. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/frozen_containers.py +0 -0
  102. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/identities.py +0 -0
  103. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/provenance.py +0 -0
  104. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/records.py +0 -0
  105. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/revisions.py +0 -0
  106. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/source.py +0 -0
  107. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/domain/verification.py +0 -0
  108. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/excel.py +0 -0
  109. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/exceptions.py +0 -0
  110. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/exports.py +0 -0
  111. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/grids.py +0 -0
  112. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/integrity/__init__.py +0 -0
  113. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/integrity/digests.py +0 -0
  114. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/__init__.py +0 -0
  115. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_adapters.py +0 -0
  116. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_canonical.py +0 -0
  117. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_group_keys.py +0 -0
  118. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_metadata_view.py +0 -0
  119. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_preprocessing.py +0 -0
  120. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_provenance.py +0 -0
  121. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_source_walk.py +0 -0
  122. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_specs.py +0 -0
  123. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/ml/_splits.py +0 -0
  124. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/models.py +0 -0
  125. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/__init__.py +0 -0
  126. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/_identity.py +0 -0
  127. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/_validation.py +0 -0
  128. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/arithmetic.py +0 -0
  129. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/base.py +0 -0
  130. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/resampling.py +0 -0
  131. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/resampling_scipy.py +0 -0
  132. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/operations/spectra.py +0 -0
  133. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/processing/__init__.py +0 -0
  134. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/processing/_table_capture.py +0 -0
  135. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/processing/limits.py +0 -0
  136. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/protocols.py +0 -0
  137. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/py.typed +0 -0
  138. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/replay.py +0 -0
  139. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/tables.py +0 -0
  140. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/transformations/__init__.py +0 -0
  141. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/transformations/base.py +0 -0
  142. {vector_mtrl-0.4.2 → vector_mtrl-0.5.0}/mtrl/units.py +0 -0
@@ -10,6 +10,78 @@ break, and every breaking change is named in the release entry.
10
10
 
11
11
  ## [Unreleased]
12
12
 
13
+ Prepared version: `0.5.0` (2026-11-03). This minor release includes all core changes since
14
+ `vector-mtrl-v0.4.2`, through `d39972f`, plus this release preparation. Keep these entries under
15
+ `Unreleased` until publication, as the tag gate requires. The separate web viewer does not ship
16
+ in the wheel or source archive.
17
+
18
+ ### Added
19
+
20
+ - `mtrl.ml.build_dataset()` takes a keyword-only `target_source`, defaulting to `'assertion'`.
21
+ `'run_metadata'` reads the target from a run metadata field instead of an assertion property,
22
+ and `TargetSpec` stays the single validator for the source and the task type, so a
23
+ metadata-target call and the hand-built specification still produce one `spec_summary` and
24
+ one `dataset_digest`.
25
+
26
+ ### Changed
27
+
28
+ - The distribution version and the source-tree operation version fallback advance to `0.5.0`.
29
+ - `Sample.history()` marks superseded inputs through their recorded chains rather than only
30
+ through the versions the active records name, so an original replaced by two successive
31
+ corrections still reads `(original version, corrected)`. The walk reads the committed record
32
+ store the facade already passes as its lookup: no archive read, no integrity check, and no
33
+ revision.
34
+ - `MLDataset.summary()` and `repr(dataset)` report the dataset's own row and group totals, so a
35
+ subset that `split_grouped()` produces no longer repeats its parent's counts. The digest line
36
+ keeps the canonical digest of the whole dataset that produced the subset.
37
+ - `run.to_pandas()` keeps the original column labels of a plain two-dimensional checkpoint, so
38
+ integer labels reach the frame and an integer `0` column never merges with a text `"0"`
39
+ column. Only a label that the label-column alias rule rewrites becomes text.
40
+ - `build_dataset()` refuses `mode='auto-shared-linear'` with an error that names the advanced
41
+ `DatasetSpec` route, because that mode derives its grid from the sources and needs a
42
+ `target_count` the flat route cannot name.
43
+ - **Breaking archive format:** a save that writes more than one revision now writes integrity
44
+ schema `mtrl-integrity/2`. Each revision body cites its records by record digest, and
45
+ `integrity.json` holds each record body once in `record_bodies`. Releases before this change
46
+ cannot open a schema 2 archive. This release still loads `mtrl-integrity/1` archives. A save
47
+ without a new revision keeps their integrity bytes, and a new revision keeps every legacy body,
48
+ root, and record digest (#66).
49
+ - A schema 2 save stores provenance `effective_parameters` as one reference marker when they
50
+ equal the transformation parameters. An archive with the marker requires the new core format
51
+ feature `mtrl.operation-parameter-aliases/1` (#66).
52
+ - The committed-integrity check before each mutation verifies the saved archive again only when
53
+ its SHA-256 digest or the effective limits change, so a session no longer re-verifies an
54
+ unchanged file on every commit (#66).
55
+
56
+ ### Fixed
57
+
58
+ - Archive digest reads enforce `max_archive_bytes` before and during the read, so verification
59
+ reuse cannot bypass the configured archive size limit.
60
+ - Alias feature validation uses the normalised record descriptor, including nested payload
61
+ lineage. Load and verification reject an alias without its required format feature (#91).
62
+ - A list-valued integrity schema fails with `UnsupportedArchiveFeatureError`, not `TypeError`.
63
+ - `Sample.ingest()` is documented as returning a tuple of `RecordedData` handles, the flat
64
+ builder's documented `group_by`, `stage`, and `mode` values now match the enums it accepts,
65
+ `to_numpy()` no longer promises NaN-free extraction, and the units concept page separates the
66
+ workbook's units sheet from the unit-free CSV export.
67
+ - The unit views report unrecognised units as comparing by their declared text, and the tutorial
68
+ lessons 2, 4, 5, and 7 keep their promised destinations, their continuation chain, and their
69
+ verified output.
70
+ - `Mtrl.correct_checkpoint()` and `Mtrl.replace_checkpoint()` keep the operation provenance of a
71
+ built-in candidate with a list parameter, such as the `x_targets` of `mtrl.resample.linear`.
72
+ The descriptor check now receives plain parameter values, not the frozen committed values.
73
+ Before this fix, the new record lost its `transformation`, `input_refs`, and `provenance` with
74
+ no warning (#58).
75
+
76
+ ### Removed
77
+
78
+ - Duplicate internal helpers: `_member_text`, `_named_fields`, the second `_counted`
79
+ formatter, the unused `joiner` option of `bounded_list_preview`, the redundant
80
+ `copy.deepcopy` wrappers around `json_value_to_plain`, the unused `build:notebook` script
81
+ alias, and the `limit` keywords of the per-record summary helpers. No public API is removed.
82
+
83
+ ## [0.4.2] - 2026-10-28
84
+
13
85
  ### Added
14
86
 
15
87
  - Data-first `Sample` workflows, including explicit selection and correction helpers and
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: vector-mtrl
3
- Version: 0.4.2
3
+ Version: 0.5.0
4
4
  Summary: Materials research tools for spectra and archive workflows.
5
5
  Project-URL: Documentation, https://mtrl-docs.vector-labs.app
6
6
  Author-email: Fuzzy Labs <info@fuzzylabs.ai>
@@ -43,15 +43,19 @@ standard terms:
43
43
 
44
44
  Anything else — `"K"`, `"MPa"`, `"counts"`, your own domain unit — is kept exactly as you
45
45
  wrote it, with no standard terms attached. It still records, exports and round-trips; it
46
- plays no part in unit-checked comparisons until the recognised set grows.
46
+ participates in unit-checked comparisons through exact matches of the declared text, so a
47
+ record declaring `K` and one declaring `MPa` fail an alignment check rather than bypassing
48
+ it.
47
49
 
48
50
  ## Where units matter
49
51
 
50
52
  Declared units do real work in three places. A transform preserves the declarations of the
51
53
  fields its output keeps, so derived records stay labelled. Machine-learning dataset
52
54
  specifications can require an `expected_unit` for a channel, feature or target, and a
53
- mismatch fails the build with the field and its declared unit named. And exports carry the
54
- declared text, so a colleague reading your CSV or workbook sees the same unit you wrote.
55
+ mismatch fails the build with the field and its declared unit named. And the workbook export
56
+ carries the declared text on its units sheet, so a colleague reading the workbook sees the
57
+ same unit you wrote. A CSV export holds the checkpoint labels and numeric fields only, so
58
+ share the unit context beside the CSV or hand over the archive.
55
59
 
56
60
  ## How to write units well
57
61
 
@@ -63,50 +63,40 @@ with TemporaryDirectory() as directory:
63
63
  target_grid=np.linspace(500.0, 3900.0, 100).tolist(),
64
64
  target="polymer.identity",
65
65
  )
66
- print(f"features shape: {dataset.features.shape}; channels: {dataset.channel_names}")
67
- print(f"class names: {dataset.class_names}; targets: {dataset.targets.tolist()}")
68
-
69
66
  bundle = dataset.split_grouped(test_size=0.5, seed=42)
70
- print(f"train rows: {len(bundle.train)}; test rows: {len(bundle.test)}")
67
+ sklearn_bundle = bundle.train.to_sklearn()
71
68
 
72
69
  print(dataset.summary())
73
-
74
- sklearn_bundle = bundle.train.to_sklearn()
75
70
  print(f"dataset digest: {sklearn_bundle.dataset_digest}")
71
+
72
+ print(f"features shape: {dataset.features.shape}; channels: {dataset.channel_names}")
73
+ print(f"class names: {dataset.class_names}; targets: {dataset.targets.tolist()}")
74
+ print(f"train rows: {len(bundle.train)}; test rows: {len(bundle.test)}")
76
75
  ```
77
76
 
78
- ```console
77
+ ```text
79
78
  features shape: (2, 100); channels: ('raw',)
80
79
  class names: ('polyethylene', 'polypropylene'); targets: [1, 0]
81
80
  train rows: 1; test rows: 1
82
- MLDataset — 2 rows; 2 groups; 1 channel
83
- target: 'polymer.identity' (classification); classes: 'polyethylene', 'polypropylene'
84
- channels:
85
- [0] 'raw' — 100 points on 'wavenumber' (span 500.0–3900.0); resample-linear, resampled
86
- auxiliary: none
87
- metadata detail: standard
88
- group by: sample-uid
89
- excluded: 0 candidate runs
90
- digest: sha256:89327935f52952ee86d514bf0d8787d75f7295ff89b5cece59fc74bf7ed9f1b2
91
- dataset digest: sha256:89327935f52952ee86d514bf0d8787d75f7295ff89b5cece59fc74bf7ed9f1b2
92
81
  ```
93
82
 
94
- The last line labels the canonical dataset digest `dataset digest`; that digest derives from the
95
- exact source records, whose identities mint per run, so your digest differs from this one. The
96
- bundle you fit on is `bundle.train.to_sklearn()`: it serves the training rows alone and carries
97
- the canonical digest of the parent dataset, because a split subset keeps its parent's provenance
98
- manifest. Everything above it is stable, except the `digest:` line inside the summary, which
99
- carries that same canonical digest.
100
- `dataset.summary()` recaps the prepared dataset: the row, group, and channel totals, the target
101
- property with its task type and sorted class vocabulary, the one signal channel with its point
102
- count, coordinate field, span, alignment mode, and resample flag, the auxiliary basis, the
103
- metadata detail level, the group kind, and the excluded candidate count. The first line prints
83
+ The example prints the recap and the digest first, because those lines carry a value that
84
+ mints per run. `dataset.summary()` recaps the prepared dataset: the row, group, and channel
85
+ totals, the target property with its task type and sorted class vocabulary, the one signal
86
+ channel with its point count, coordinate field, span, alignment mode, and resample flag, the
87
+ auxiliary basis, the metadata detail level, the group kind, and the excluded candidate count.
88
+ Its closing `digest:` line, and the `dataset digest:` line after it, carry the canonical
89
+ dataset digest: `sha256:` followed by 64 hexadecimal digits. That digest derives from the
90
+ exact source records, whose identities mint per run, so your value differs from any printed
91
+ one and no fence displays it. The bundle you fit on is `bundle.train.to_sklearn()`: it
92
+ serves the training rows alone and carries the canonical digest of the parent dataset,
93
+ because a split subset keeps its parent's provenance manifest.
94
+ The fenced tail holds the deterministic output. The first line prints
104
95
  `features shape: (2, 100); channels: ('raw',)`: two rows, one per archive, aligned onto the
105
96
  100-point target grid even though the archives hold a 200-point and a 120-point spectrum.
106
- The second line prints the sorted class vocabulary `('polyethylene', 'polypropylene')` and the
107
- encoded targets `[1, 0]`. The split puts one film in each subset, which the third line reports
108
- as `train rows: 1; test rows: 1`. The last line prints the canonical dataset digest: `sha256:`
109
- followed by 64 hexadecimal digits.
97
+ The second line prints the sorted class vocabulary `('polyethylene', 'polypropylene')` and
98
+ the encoded targets `[1, 0]`. The split puts one film in each subset, which the third line
99
+ reports as `train rows: 1; test rows: 1`.
110
100
 
111
101
  ## What just happened?
112
102
 
@@ -137,7 +127,8 @@ without touching the archives.
137
127
  > retirement details and the replay limits.
138
128
 
139
129
  `target` names the property that supplies each row's label, read from the active assertions
140
- on the sample — here the `polymer.identity` claim that each archive carries. The default
130
+ on the sample — here the `polymer.identity` claim that each archive carries. Pass
131
+ `target_source='run_metadata'` to read the target from a run metadata field instead. The default
141
132
  `group_by='sample-uid'` is your leakage control: every run of one physical sample forms one
142
133
  group, and `split_grouped` shuffles groups, not rows. Replicates of one film therefore
143
134
  always land in the same subset. One seeded generator drives the shuffle, so the same seed
@@ -4,7 +4,9 @@ MTRL stores your data; NumPy, pandas, SciPy, and matplotlib analyse it. This gui
4
4
  the four hand-offs: a DataFrame in, DataFrames back out, your own functions as operations,
5
5
  and direct plots of committed data.
6
6
 
7
- `sample.transform` takes your NumPy or SciPy function and commits its output as one result, while NaN-free extraction for these libraries stays `result.to_numpy()`.
7
+ `sample.transform` takes your NumPy or SciPy function and commits its output as one result.
8
+ `result.to_numpy()` returns a detached copy for these libraries; it preserves any NaN
9
+ values, so the missing-value policy you choose stays yours to apply.
8
10
 
9
11
  **This guide assumes:** you have finished the
10
12
  [tutorial path](../start-here/01-your-first-record.md), so you are comfortable committing
@@ -16,9 +16,9 @@ Use these `Mtrl` routes:
16
16
  structured arrays or DataFrames, `sample.transform()` runs your own function, and
17
17
  `sample.records` lists the committed results as `RecordedData` handles. `sample.core`
18
18
  returns the `Mtrl` container behind the sample, so every route below stays available.
19
- `Sample.record`, `Sample.transform`, `Sample.correct`, `Sample.aggregate` and
20
- `Sample.ingest` return `RecordedData`, which exposes `.ref`, `.name`, `.to_numpy()` and
21
- `.to_pandas()`.
19
+ `Sample.record`, `Sample.transform`, `Sample.correct` and `Sample.aggregate` return
20
+ `RecordedData`, which exposes `.ref`, `.name`, `.to_numpy()` and `.to_pandas()`.
21
+ `Sample.ingest` returns a tuple of `RecordedData` handles, even for one checkpoint.
22
22
  - Read verification facts through the facade with `sample.verify()`, export one committed
23
23
  result with `sample.export(result, path)`, and record or read scientific claims with
24
24
  `sample.claim()` and `sample.claims()`.
@@ -854,6 +854,7 @@ def build_dataset(
854
854
  y_field: str,
855
855
  target_grid: Sequence[float],
856
856
  target: str,
857
+ target_source: str = ASSERTION_SOURCE,
857
858
  stage: str = "raw",
858
859
  mode: str = "resample-linear",
859
860
  task_type: str = "classification",
@@ -875,19 +876,30 @@ def build_dataset(
875
876
  record. Both are required, because MTRL never guesses a field name.
876
877
  - `target_grid`: the shared axis, as a sequence of at least two finite numbers. Required; the
877
878
  default resample mode interpolates every spectrum onto it.
878
- - `target`: the property identifier that supplies each row's target value. Required.
879
- - `stage`: the committed checkpoint state that the channel selects from each run, as the
880
- canonical text of `CheckpointStage`: `'active-latest'`, `'raw'`, `'latest-processed'`,
881
- `'by-name'`, or `'by-operation'`. Defaults to `'raw'`.
882
- - `mode`: the grid alignment mode, as the canonical text of `GridAlignmentMode`: `'strict'`,
883
- `'auto-shared-linear'`, `'resample-linear'`, `'resample-pchip'`, or `'resample-cubic'`.
884
- Defaults to `'resample-linear'`.
879
+ - `target`: the identifier that supplies each row's target value: an assertion property
880
+ identifier by default, or a run metadata field name with
881
+ `target_source='run_metadata'`. Required.
882
+ - `target_source`: `'assertion'` reads the target from the active assertions on each
883
+ sample, and `'run_metadata'` reads it from a run metadata field instead. Defaults to
884
+ `'assertion'`. Note the underscore: the group kind of the same name is spelled
885
+ `'run-metadata'` with a hyphen.
886
+ - `stage`: the committed checkpoint state that the channel selects from each run:
887
+ `'active-latest'`, `'raw'`, or `'latest-processed'`. Defaults to `'raw'`. The
888
+ `'by-name'` and `'by-operation'` stages need a checkpoint or operation selector that the
889
+ flat route cannot name, so the flat route refuses them; use the advanced `DatasetSpec`
890
+ route for them.
891
+ - `mode`: the grid alignment mode: `'strict'`, `'resample-linear'`, `'resample-pchip'`,
892
+ or `'resample-cubic'`. Defaults to `'resample-linear'`. The flat route refuses
893
+ `'auto-shared-linear'`, because that mode derives its grid from the sources and needs
894
+ `target_count`; the error directs the caller to the advanced `DatasetSpec` route.
885
895
  - `task_type`: `'classification'` encodes the sorted class vocabulary as int64 indices, and
886
896
  `'regression'` keeps finite float64 values. Defaults to `'classification'`.
887
- - `group_by`: `'sample-uid'` groups rows by the portable physical sample identity, and
888
- `'property'` groups them by one assertion property. Defaults to `'sample-uid'`.
889
- - `group_property`: the assertion property identifier for the `'property'` group kind, or
890
- `None`. Defaults to `None`.
897
+ - `group_by`: the group kind for leak-free splitting, as the canonical text of
898
+ `GroupByKind`: `'sample-uid'`, `'sample-id'`, `'archive-id'`, `'assertion'`, or
899
+ `'run-metadata'`. Defaults to `'sample-uid'`.
900
+ - `group_property`: the assertion property identifier or run metadata field name that the
901
+ `'assertion'` and `'run-metadata'` group kinds share, or `None`. Required for those
902
+ kinds and rejected for the others. Defaults to `None`.
891
903
  - `metadata_detail`: the per-row metadata detail, as the canonical text of
892
904
  `MetadataDetailLevel`: `'none'`, `'minimal'`, `'standard'`, or `'full-audit'`. Defaults to
893
905
  `'standard'`.
@@ -900,13 +912,18 @@ that the flat call leaves at their defaults.
900
912
 
901
913
  **Raises:** `TypeError` if a mandatory keyword is missing. `DatasetPreparationError` if an
902
914
  enumeration keyword holds unknown text — the message names the received value and the valid
903
- choices — or if the composed specification is invalid. The build also raises the documented
915
+ choices — if a selector stage (`'by-name'` or `'by-operation'`) or `'auto-shared-linear'` is
916
+ requested, with the message directing the caller to the advanced `DatasetSpec` route, or if
917
+ the composed specification is invalid. `MissingOptionalDependencyError` if `mode` is
918
+ `'resample-pchip'` or `'resample-cubic'` and the `vector-mtrl[interp]` extra is not
919
+ installed. The build also raises the documented
904
920
  `build_ml_dataset()` failures: `IntegrityMismatchError` for one loaded source whose committed
905
921
  state changed, `InvalidRecordRevisionError` for an unknown revision, `GridMismatchError` for
906
922
  unaligned grids or disagreeing units, `ConflictingAssertionError` for competing target
907
923
  claims, and `DatasetPreparationError` when no sample is retained.
908
924
 
909
- **Extras:** none.
925
+ **Extras:** `vector-mtrl[interp]` for `resample-pchip` and `resample-cubic`;
926
+ none for the other modes.
910
927
 
911
928
  #### `MLDataset.summary`
912
929
 
@@ -26,9 +26,11 @@ copies the values. An earlier check cannot silently become a check of that new w
26
26
 
27
27
  ## Save, reopen and watch the check change
28
28
 
29
- The example uses a temporary directory so you can repeat it without leaving files behind.
30
- Inside that directory it saves the first archive, reloads it, commits a copied spectrum
31
- and saves the updated history under a second filename.
29
+ Run this example — and the rest of the tutorial — in a fresh, empty working directory.
30
+ `sample.save(path)` writes `polymer-film-01.mtrl` beside your script without prompting and
31
+ replaces any file of that name, and later lessons keep reading that saved archive. The
32
+ example saves the first archive, reloads it, commits a copied spectrum and saves the
33
+ updated history under a second filename.
32
34
 
33
35
  The call to `loaded.one(...)` finds the unique active result with the requested name.
34
36
  That gives the newly loaded sample its own handle to the measurement before processing it.
@@ -106,7 +108,7 @@ what was checked, not quietly follow whatever you do next.
106
108
  :::caution
107
109
  Keep the saved file available while continuing work on its loaded history.
108
110
  MTRL checks saved evidence before later mutations and refuses when that evidence is missing
109
- or changed. This example keeps both archives until the temporary directory closes.
111
+ or changed. This example keeps both archives in the working directory you created.
110
112
  :::
111
113
 
112
114
  :::tip
@@ -70,7 +70,7 @@ not the application holding your results.
70
70
 
71
71
  <!-- example: Exact handles -->
72
72
 
73
- <!-- continues: Creation -->
73
+ <!-- continues: Transform -->
74
74
  ```python
75
75
  print(f"checkpoint: {raw.checkpoint_id}; record: {raw.record_id}")
76
76
  print(f"original handle still resolves: {raw.ref == sample.core.active_ref(raw.checkpoint_id, run_id=raw.run_id)}")
@@ -93,15 +93,18 @@ print(f"active records: {len(sample.records)}")
93
93
 
94
94
  ```console
95
95
  checkpoint: 01a18304-dadc-74b8-b8cf-70ae86c8e344; record: 01a18304-dae2-7181-9fb2-17f65805fcec
96
+ ```
97
+
98
+ ```text
96
99
  original handle still resolves: True
97
100
  aligned: aligned, 51 points
98
- active records: 2
101
+ active records: 3
99
102
  ```
100
103
 
101
104
  The first line shows the two generated identifiers of the measurement and its corrected
102
105
  replacement. Yours will differ — identifiers mint on each commit — but the shape stays: two
103
106
  distinct versions side by side, the stale check passing for the original, and the aligned
104
- output holding all 51 target points across the two active records.
107
+ output holding all 51 target points across the three active records.
105
108
 
106
109
  ## What just happened?
107
110
 
@@ -7,7 +7,8 @@ still points to the original. It takes about ten minutes.
7
7
 
8
8
  Read [Look underneath a result](04-handles-and-the-core.md) first if checkpoints and
9
9
  record versions are unfamiliar. The example then carries on from the session you built
10
- in lessons 1 and 3: it corrects the very spectrum you recorded and normalised.
10
+ in lessons 1, 3 and 4: it corrects the very spectrum you recorded and normalised, while
11
+ the aligned result from lesson 4 stays active beside them.
11
12
 
12
13
  ## Find the measurement you mean
13
14
 
@@ -35,7 +36,7 @@ investigating the detector problem.
35
36
 
36
37
  <!-- example: Sample selection and correction -->
37
38
 
38
- <!-- continues: Transform -->
39
+ <!-- continues: Exact handles -->
39
40
  ```python
40
41
  print(f"matches by name: {len(sample.select(name='ftir-replicate-01'))}")
41
42
  target = sample.one(name="ftir-replicate-01", run_id=raw.run_id)
@@ -61,11 +62,13 @@ selection finds correction: True
61
62
  matches by original record: 0
62
63
  original peak: 1.0075
63
64
  normalised peak: 1.0
64
- Sample 'polymer-film-01' — 2 active records; 0 active claims
65
+ Sample 'polymer-film-01' — 3 active records; 0 active claims
65
66
  Records (commit order):
66
67
  [0] 'normalised' 101 values, shape=(101,)
67
68
  fields: wavenumber (cm^-1), absorbance (a.u.)
68
- [1] 'ftir-replicate-01' 101 values, shape=(101,)
69
+ [1] 'aligned' 51 values, shape=(51,)
70
+ fields: wavenumber (cm^-1), absorbance (a.u.)
71
+ [2] 'ftir-replicate-01' 101 values, shape=(101,)
69
72
  fields: wavenumber (cm^-1), absorbance (a.u.)
70
73
  ```
71
74
 
@@ -75,8 +78,9 @@ returns the original version. Yet the old handle still reads its original peak,
75
78
  earlier normalisation still peaks at 1.0.
76
79
 
77
80
  The summary the example prints recaps the state after the correction: its header counts
78
- two active records — the replaced version no longer inflates that count — and the listing
79
- shows the normalised result first and the corrected version last, in commit order. The
81
+ three active records — the replaced version no longer inflates that count — and the listing
82
+ shows the normalised result first, the aligned result next, and the corrected version last,
83
+ in commit order. The
80
84
  superseded version stays in
81
85
  the stored history. The text carries no generated identifiers, so the same recorded work
82
86
  always prints the same summary.
@@ -20,8 +20,10 @@ owned by that facade; the path suffix selects the writer. A `.csv` destination n
20
20
  neither pandas nor a plotting dependency.
21
21
 
22
22
  The first example writes both files, then reads the CSV back with NumPy to compare the
23
- exported absorbance values with the mean's. Both outputs live in a temporary directory
24
- so the example cleans up after itself. In your own work, choose destinations you retain.
23
+ exported absorbance values with the mean's. Both outputs land in your working directory —
24
+ the fresh directory you created in lesson 2 — and the saved archive must stay there,
25
+ because MTRL checks the saved copy before later work. In your own work, choose
26
+ destinations you retain.
25
27
 
26
28
  <!-- example: CSV -->
27
29
 
@@ -36,6 +36,7 @@ from mtrl.integrity.canonical import decode_schema_int
36
36
  from mtrl.integrity.digests import (
37
37
  DigestOrder,
38
38
  canonical_payload_digest,
39
+ is_digest_text,
39
40
  raw_digest,
40
41
  record_digest,
41
42
  revision_digest,
@@ -44,7 +45,12 @@ from mtrl.integrity.digests import (
44
45
  from mtrl.integrity.digests import (
45
46
  storage_digest as calculate_storage_digest,
46
47
  )
47
- from mtrl.integrity.manifest import changed_active_selections, record_body
48
+ from mtrl.integrity.manifest import (
49
+ INTEGRITY_SCHEMA,
50
+ LEGACY_INTEGRITY_SCHEMA,
51
+ changed_active_selections,
52
+ record_body,
53
+ )
48
54
  from mtrl.models import ArchiveEntry, CheckpointEncoding, CheckpointManifestEntry, Manifest
49
55
 
50
56
  if TYPE_CHECKING:
@@ -463,6 +469,7 @@ def _validate_integrity_revision_roots(
463
469
  layer="revision",
464
470
  )
465
471
  active_maps = active_assertion_maps(revision.events for revision in documents.revisions)
472
+ integrity_schema = integrity_data.get("integrity_schema")
466
473
  manifest_sample_uid = None if manifest.sample_uid is None else str(manifest.sample_uid)
467
474
  expected_sample_uids = _expected_revision_sample_uids(
468
475
  documents.revisions,
@@ -489,6 +496,11 @@ def _validate_integrity_revision_roots(
489
496
  active_assertions,
490
497
  expected_sample_uid=expected_sample_uids[revision_id],
491
498
  )
499
+ compact_bodies = [
500
+ (revision_id, revision_bodies[revision_id])
501
+ for revision_id in revision_ids
502
+ if _is_compact_revision_body(revision_bodies[revision_id], revision_id, integrity_schema)
503
+ ]
492
504
  head_revision_id = integrity_data.get("head_revision_id")
493
505
  if head_revision_id != revision_ids[-1]:
494
506
  raise InvalidArchiveStructureError(
@@ -506,6 +518,111 @@ def _validate_integrity_revision_roots(
506
518
  "Archive integrity inventory does not match the head snapshot.",
507
519
  layer="revision",
508
520
  )
521
+ _validate_compact_record_references(integrity_data, integrity_schema, compact_bodies)
522
+
523
+
524
+ def _validate_compact_record_references(
525
+ integrity_data: Mapping[str, Any],
526
+ integrity_schema: Any,
527
+ compact_bodies: Sequence[tuple[str, Mapping[str, Any]]],
528
+ ) -> None:
529
+ """Validate the shared record bodies and each compact revision reference."""
530
+ if integrity_schema == INTEGRITY_SCHEMA and not compact_bodies:
531
+ raise InvalidArchiveStructureError(
532
+ "A compact integrity document must contain a compact revision snapshot."
533
+ )
534
+ _validate_integrity_record_bodies(integrity_data, integrity_schema)
535
+ for revision_id, body in compact_bodies:
536
+ _validate_revision_record_references(body, integrity_data, revision_id)
537
+
538
+
539
+ def _is_compact_revision_body(
540
+ body: Mapping[str, Any],
541
+ revision_id: str,
542
+ integrity_schema: Any,
543
+ ) -> bool:
544
+ """Return whether one revision body uses compact record references."""
545
+ body_schema: object = body.get("integrity_schema")
546
+ if body_schema not in (LEGACY_INTEGRITY_SCHEMA, INTEGRITY_SCHEMA):
547
+ raise InvalidArchiveStructureError(
548
+ f"Revision '{revision_id}' has an unsupported integrity schema."
549
+ )
550
+ if integrity_schema == LEGACY_INTEGRITY_SCHEMA and body_schema != LEGACY_INTEGRITY_SCHEMA:
551
+ raise InvalidArchiveStructureError(
552
+ "A legacy integrity document cannot contain compact revision snapshots."
553
+ )
554
+ if body_schema == LEGACY_INTEGRITY_SCHEMA and not isinstance(body.get("records"), Mapping):
555
+ raise InvalidArchiveStructureError(
556
+ f"Revision '{revision_id}' has an invalid legacy record snapshot."
557
+ )
558
+ return body_schema == INTEGRITY_SCHEMA
559
+
560
+
561
+ def _validate_integrity_record_bodies(
562
+ integrity_data: Mapping[str, Any],
563
+ integrity_schema: Any,
564
+ ) -> None:
565
+ """Bind the record bodies of a compact document to the record digest index."""
566
+ record_bodies = integrity_data.get("record_bodies")
567
+ if integrity_schema != INTEGRITY_SCHEMA:
568
+ if record_bodies is not None:
569
+ raise InvalidArchiveStructureError(
570
+ "A legacy integrity document cannot contain shared record bodies."
571
+ )
572
+ return
573
+ record_digests = integrity_data.get("record_digests")
574
+ if not isinstance(record_bodies, Mapping) or not isinstance(record_digests, Mapping):
575
+ raise InvalidArchiveStructureError("Archive integrity record bodies are incomplete.")
576
+ if set(record_bodies) != set(record_digests):
577
+ raise IntegrityMismatchError(
578
+ "Archive integrity record bodies do not match the record digest index.",
579
+ layer="record",
580
+ )
581
+ for record_id, body in record_bodies.items():
582
+ if not isinstance(body, Mapping) or record_digest(body) != record_digests[record_id]:
583
+ raise IntegrityMismatchError(
584
+ f"Archive integrity record body '{record_id}' has a record digest mismatch.",
585
+ layer="record",
586
+ )
587
+
588
+
589
+ def _validate_revision_record_references(
590
+ body: Mapping[str, Any],
591
+ integrity_data: Mapping[str, Any],
592
+ revision_id: str,
593
+ ) -> None:
594
+ """Bind one compact revision record map to its inventory and record digest index.
595
+
596
+ A historical body inventory can list records that its snapshot does not
597
+ hold, so each reference must appear in the inventory, but not the reverse.
598
+ """
599
+ records = body.get("records")
600
+ inventory = body.get("inventory")
601
+ record_digests = integrity_data.get("record_digests")
602
+ if not isinstance(records, Mapping) or not isinstance(inventory, Mapping):
603
+ raise InvalidArchiveStructureError(
604
+ f"Revision '{revision_id}' has incomplete compact record references."
605
+ )
606
+ if not isinstance(record_digests, Mapping):
607
+ raise InvalidArchiveStructureError("Archive integrity record digest index is incomplete.")
608
+ for record_id, digest in records.items():
609
+ if (
610
+ not isinstance(record_id, str)
611
+ or not isinstance(digest, str)
612
+ or not is_digest_text(digest)
613
+ ):
614
+ raise InvalidArchiveStructureError(
615
+ f"Revision '{revision_id}' has an invalid record digest reference."
616
+ )
617
+ descriptor = inventory.get(f"records/{record_id}")
618
+ inventory_digest = (
619
+ descriptor.get("record_digest") if isinstance(descriptor, Mapping) else None
620
+ )
621
+ if digest != inventory_digest or digest != record_digests.get(record_id):
622
+ raise IntegrityMismatchError(
623
+ f"Revision '{revision_id}' record '{record_id}' has a digest-reference mismatch.",
624
+ layer="revision",
625
+ )
509
626
 
510
627
 
511
628
  def _validate_integrity_inventory_keys(