Skip to content

Serialization refactor#97

Merged
pdobbelaere merged 10 commits into
molmod:mainfrom
pdobbelaere:serialization
Mar 30, 2026
Merged

Serialization refactor#97
pdobbelaere merged 10 commits into
molmod:mainfrom
pdobbelaere:serialization

Conversation

@pdobbelaere

@pdobbelaere pdobbelaere commented Mar 17, 2026

Copy link
Copy Markdown
Collaborator

(only merge after #96)
fixes #78

Reimplementation of the psiflow.serialization module.

Before this PR, serialization was based on class introspection of type hints to determine how a psiflow class instance should be serialized. Since the Python typing system evolves continuously, this locked psiflow into v3.10. More fundamentally, type hints should not control runtime decisions.

New functionality:

  • resolve_nested_futures in psiflow.utils.future to resolve futures hidden in complex data trees (here)

Updated functionality (psiflow.serialization):

  • JSON format was updated, meaning existing JSON files can no longer be reconstructed
  • serialize is reimplemented, but does the same
  • deserialize is now an app, so works with futures. The regular function is renamed to _deserialize

Developer notes:

  • to make a custom class serializable, you should decorate the class definition with psiflow.register_serializable
  • replaced _create_apps functions in Reference, Hamiltonian and Model. Functionality unchanged.
  • un-convoluted some Reference logic. Functionality unchanged.

After this PR, we can almost update to the latest Python version. The new bottleneck is MACE and PyTorch.

Some analysis and comments to remember the past
currently, Callables and partial bork serialisation (these come from _create_apps calls). In general, I think we should not use this construct, and simply have the apps as class methods, avoiding the problem.
replace _create_apps methods and instead create apps when required:
- get_app for Hamiltonian
- get_train_app and get_initialise_app for Models
This simplifies serialisation (no more Callable instance attributes) and makes the apps react to changes (e.g., changing the force constant in EinsteinCrystal or the parsl_resource_specification in MaceHamiltonian) and should really not cause any noticeable overhead.
- get_execute_app for Reference instances
- also deconvolute some logic

API unchanged
@pdobbelaere pdobbelaere marked this pull request as ready for review March 30, 2026 11:46
@pdobbelaere pdobbelaere changed the title [Do not merge] Serialization refactor Serialization refactor Mar 30, 2026
@pdobbelaere pdobbelaere merged commit 6642a10 into molmod:main Mar 30, 2026
1 check failed
@pdobbelaere pdobbelaere deleted the serialization branch March 30, 2026 12:02
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.

Serialization disagrees with typing for recent Python versions

1 participant