Skip to content

Records: content hashes, and named *.lion.json - #396

Open
AnderBiguri wants to merge 3 commits into
mainfrom
utils/record-checksum
Open

AnderBiguri wants to merge 3 commits into
mainfrom
utils/record-checksum

Conversation

@AnderBiguri

@AnderBiguri AnderBiguri commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

LION's records are not meant to be edited by hand. This PR does two things about it:

  • it makes an edit detectable, with a content hash;
  • it names the files so that they say whose they are, *.lion.json.

What changes

  • Every record LION writes holds its content's hash, lion_sha256. This covers:

    • model files;
    • reconstructor files;
    • test records;
    • comparisons (comparison.lion.json and records/);
    • package files.

    They are written by a new spec.write(path, value).

  • spec.read warns when a file's content no longer matches its hash. The warning reads: "… was changed after LION wrote it: its records may no longer describe what was saved. Change things with parameters_from_file or instantiate(file, **arguments), not by editing the file". The hash is of the content (sorted keys, compact), so re-indenting or reordering a file doesn't warn.

  • A model's .pt holds the hash of its .lion.json (metadata_sha256). LIONmodel.load and load_checkpoint check it before building the model. So a .lion.json that wasn't saved with its .pt (copied from another run, say) warns before it causes any load error.

  • Records are named *.lion.json: model.lion.json + model.pt, reconstructor.lion.json, test.lion.json, a package's package.lion.json, experiment.lion.json, data/training.lion.json, and so on. The name stays JSON for editors and viewers, but says the file is LION's.

    • The helpers are spec.record_file, spec.weights_file and spec.file_base.
    • Names are given without the suffix (model.save("results/model"), load("results/model")). A name ending in .json is used as given.
    • Other JSON stays .json: LIONParameter.save, Geometry.save, and the datasets' preprocessing files.
  • Files without the hash keys load as before.

  • metadata.md, the CHANGELOG, docs/developers.rst, the demos and the paper scripts' "already trained" checks are updated.

Nothing changes for results. Files gain one key each (two for a model's pair).

Saved files are renamed. A model saved before this has a model.json file, and LION now looks for model.lion.json. Rename it, or load it with the .json path. There is no backwards compatibility before v1.0.

Tests

  • test_spec: test_an_edited_file_warns checks:
    • re-indenting and reordering don't warn;
    • an edit warns;
    • a .lion.json from another save warns on load.
  • Two tests that simulate files from another LION version now write them as LION does (helpers.resave).
  • The tests use the new names.
  • The whole suite passes locally. The only failures come from this environment:
    • no spyrit (operators, FISTA, SPGL1);
    • one noise test that fails on main here too.
  • The docs build has no warnings other than intersphinx, which can't fetch from here.

On holly: git fetch && git checkout utils/record-checksum && git pull && pytest pytests/ -n auto. No script: nothing numerical changes.

https://claude.ai/code/session_01LiEbBn1tapdKM5EG8V2As2


Generated by Claude Code

spec.write adds lion_sha256, the hash of the record's content (key
order and indentation don't change it), and spec.read warns when a file
no longer matches it. Model files, reconstructor files, test records,
comparisons and packages are written this way. A model's .pt holds the
hash of its .json (metadata_sha256), checked before the model is built:
a .json not saved with its .pt warns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LiEbBn1tapdKM5EG8V2As2
The environment test's file with another commit, like test_spec's from
other versions, is written with spec.write and its .pt's hash
(helpers.resave), not edited by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LiEbBn1tapdKM5EG8V2As2
Every record LION writes (model files, reconstructor files, test records,
comparisons, packages and their records) is named `*.lion.json`, to say it
is LION's and not to be edited. File names are given without the suffix; a
name ending in `.json` is used as given. Other JSON (LIONParameter.save,
Geometry.save, the datasets' preprocessing files) stays `.json`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LiEbBn1tapdKM5EG8V2As2
@AnderBiguri AnderBiguri changed the title Files LION writes hold their content's hash; edits warn Records: content hashes, and named *.lion.json Nov 17, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants