Repository navigation
add JSON serialization of ffsim objects - #754
Open
Kevin J. Sung (kevinsung) wants to merge 1 commit into
Open
Kevin J. Sung (kevinsung) wants to merge 1 commit into
Kevin J. Sung (kevinsung) wants to merge 1 commit into
Conversation
Kevin J. Sung (kevinsung)
force-pushed
the
serialization
branch
7 times, most recently
from
November 18, 2026 14:50
0070013 to
0f7cc6b
Compare
Add ffsim.to_json and ffsim.from_json, along with the dictionary-level to_json_dict and from_json_dict, for saving and loading every public ffsim dataclass and FermionOperator. Objects are stored as JSON tagged with a stable type name, and arrays are stored as base64 bytes with their dtype and shape, so they round-trip exactly. Loading only constructs ffsim's own classes, and it skips optional validation because validation tolerances are not stored. Compression (gzip, bz2, or lzma) is inferred from the file extension when writing and detected from the file contents when reading. Deprecate MolecularData.to_json and MolecularData.from_json in favor of the new functions. ffsim.from_json still reads MolecularData files written by ffsim 0.0.86 and earlier, but those versions cannot read the new format. This removes the orjson dependency. Add a how-to guide on saving and loading objects to the docs.
Kevin J. Sung (kevinsung)
force-pushed
the
serialization
branch
from
November 20, 2026 20:15
0f7cc6b to
95f1e96
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
ffsim.to_jsonandffsim.from_json, along with the dictionary-levelffsim.to_json_dictandffsim.from_json_dict, for saving and loading ffsim objects.StateVector,ReducedDensityMatrix, andMolecularData) andFermionOperator. A test checks that new public dataclasses get registered. Registration is internal, so users can't register their own classes."ffsim.MolecularHamiltonian", that is independent of the module path. Arrays are stored as base64 bytes with their dtype and shape, so they round-trip exactly. Values that can't be represented exactly raise an error instead of being silently converted.validate=Falseload..gz,.bz2,.xz,.lzma) when writing and detected from the file contents when reading.MolecularData.to_jsonandMolecularData.from_jsonare deprecated in favor of the new functions, and they keep their previous defaults.ffsim.from_jsonstill readsMolecularDatafiles written by ffsim 0.0.86 and earlier, but those versions can't read the new format. This removes theorjsondependency.