jangada.serialization.Persistable.save#
- Persistable.save(path: Path | str, overwrite: bool = True, use_default_extension: bool = True) None#
Save this object to an HDF5 file.
- Parameters:
- pathPath | str
File path to save to.
- overwritebool, optional
If True, overwrite existing file. If False, raise FileExistsError if file exists. Default is True.
- use_default_extensionbool, optional
If True, add the class’s default extension if not present. Default is True.
- Raises:
- FileExistsError
If file exists and overwrite=False.
See also
loadLoad counterpart
Notes
The save process: 1. Resolves path (adds extension if needed) 2. Checks if file exists (if overwrite=False) 3. Serializes object to dictionary 4. Writes dictionary to HDF5 file
The entire object is serialized, so this may be slow for very large objects. For incremental updates, use context manager mode.
Examples
Basic save:
exp = Experiment(name="Test", temperature=300.0) exp.save('experiment.hdf5')
Save without overwriting:
exp.save('experiment.hdf5', overwrite=False)
Save with custom extension:
exp.save('data.h5', use_default_extension=False)