pterasoftware.load()¶
- pterasoftware.load(
- path: str | Path,
- /,
- *,
- max_size: int | None = None,
- callables: Mapping[str, Callable[[...], object]] | None = None,
Loads a Ptera Software object from a .psz file.
The archive's header is read first, and its format version and class name are checked before any of the object's data is decompressed. The members are then read one at a time in the order the header's manifest lists them, and each is decompressed in bounded chunks so that the cumulative decompressed size can be checked against max_size as it grows. Each step member's data is deserialized and the member's text dropped before the next member is read, so loading never holds more than one member's worth of text and parsed JSON in memory at once on top of the object being rebuilt.
Nothing in the file is ever executed. A custom callable stored by save() as an inert marker is restored as an UnboundCallable, a placeholder that passes callable checks but raises a RuntimeError naming the original function and printing its recorded source if it is ever invoked. Loading a solved simulation never invokes these callables, so such a file loads and can be visualized as usual. To re-solve or regenerate motion, pass the original functions in callables, keyed by the qualified names the markers recorded (the names the RuntimeError and the file report), and they are restored in place of the placeholders. Every key must match a marker in the file, so a misspelled key raises rather than silently leaving a placeholder behind. When a marker recorded a source hash and the supplied function's own source does not hash to the same value (or cannot be retrieved), a warning is logged naming the function, because the file was saved with a different definition.
The file records an internal serialization format version. A file is accepted only when that format version matches the running code's exactly, and there is no migration of files written under a different format version. A mismatch raises a ValueError reporting the file's format version and the running code's. To read the file, run a build of Ptera Software whose format version matches the file's.
- Parameters:
path -- The file path to load from. Should end with ".psz".
max_size -- The maximum cumulative decompressed size in bytes of every member read from the archive. If None, the default of 4 GB is used. Set this to a larger value if loading very large simulation results.
callables -- A mapping from the qualified names of custom callables recorded in the file to the functions to restore in their place, or None to restore every custom callable as an UnboundCallable. The default is None.
- Returns:
The deserialized Ptera Software object.