Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamrock.utils.dump.ShamrockDumpHandleHelper Class Reference

Public Member Functions

 __init__ (self, model, dump_prefix, ext=".sham", metadata=False)
str get_dump_name_extension (self, idump, ext)
str get_dump_name (self, idump)
int|None get_last_dump (self)
None purge_old_dumps (self, keep_first=1, keep_last=3)
dict|None load_dump (self, idump)
None write_dump (self, idump, metadata=None, purge_old_dumps=False, keep_first=1, keep_last=3)
dict|None load_last_dump_or (self, functor_no_last_dump)

Public Attributes

 model = model
 dump_prefix = dump_prefix
 ext = ext
 metadata = metadata

Detailed Description

Helper class to handle Shamrock checkpoint dump files.

When ``metadata`` is enabled at construction, a JSON companion file is written
and read alongside each checkpoint to store simulation metadata.

Definition at line 44 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

shamrock.utils.dump.ShamrockDumpHandleHelper.__init__ ( self,
model,
dump_prefix,
ext = ".sham",
metadata = False )
Parameters
----------
model
    The Shamrock model instance used to write and load dumps.
dump_prefix : str
    Path prefix for dump files; the dump index is appended as a
    zero-padded seven-digit number (e.g. ``prefix0000042``).
ext : str, optional
    File extension for checkpoint dumps (default is ``".sham"``).
metadata : bool, optional
    If ``True``, also write/read a ``.json`` companion with per-checkpoint
    metadata (default is ``False``).

Definition at line 52 of file __init__.py.

Member Function Documentation

◆ get_dump_name()

str shamrock.utils.dump.ShamrockDumpHandleHelper.get_dump_name ( self,
idump )
Get the name of the dump file (extension from self.ext)

Definition at line 77 of file __init__.py.

Here is the call graph for this function:

◆ get_dump_name_extension()

str shamrock.utils.dump.ShamrockDumpHandleHelper.get_dump_name_extension ( self,
idump,
ext )
Get the name of the dump file with the extension

Definition at line 73 of file __init__.py.

◆ get_last_dump()

int | None shamrock.utils.dump.ShamrockDumpHandleHelper.get_last_dump ( self)
Find the last dump number.

When metadata mode is enabled, validate that checkpoint dumps and JSON
companion files agree on the latest checkpoint index.

Definition at line 81 of file __init__.py.

◆ load_dump()

dict | None shamrock.utils.dump.ShamrockDumpHandleHelper.load_dump ( self,
idump )
Load a dump file.

Parameters
----------
idump : int
    The dump identifier to load.

Returns
-------
dict or None
    If ``metadata`` was enabled at construction, the JSON metadata
    loaded from the companion file; otherwise ``None``.

Definition at line 124 of file __init__.py.

Here is the call graph for this function:

◆ load_last_dump_or()

dict | None shamrock.utils.dump.ShamrockDumpHandleHelper.load_last_dump_or ( self,
functor_no_last_dump )
Load the last dump or call a function if no dump is found.

Parameters
----------
functor_no_last_dump : callable
    Setup function invoked when no dump exists. Must not return a value.

Returns
-------
dict or None
    If a dump was loaded and ``metadata`` was enabled at construction,
    the JSON metadata from the companion; otherwise ``None``.

Definition at line 189 of file __init__.py.

Here is the call graph for this function:

◆ purge_old_dumps()

None shamrock.utils.dump.ShamrockDumpHandleHelper.purge_old_dumps ( self,
keep_first = 1,
keep_last = 3 )
Purge old dump files.

When metadata mode is enabled, also purge old JSON companion files.

Parameters
----------
keep_first : int, optional
    Number of oldest dump files to keep (default is 1, i.e. keep the first dump).
keep_last : int, optional
    Number of newest dump files to keep (default is 3, i.e. keep the last 3 dumps).

Returns
-------
None
    This method does not return a value.

Definition at line 101 of file __init__.py.

◆ write_dump()

None shamrock.utils.dump.ShamrockDumpHandleHelper.write_dump ( self,
idump,
metadata = None,
purge_old_dumps = False,
keep_first = 1,
keep_last = 3 )
Write a dump file.

Parameters
----------
idump : int
    The dump identifier to write.
metadata : object, optional
    JSON-serializable metadata stored in a ``.json`` companion next to the
    checkpoint. Required when ``metadata`` was enabled at construction.
purge_old_dumps : bool, optional
    Whether to purge old dumps (default is False).
keep_first : int, optional
    Number of oldest dump files to keep (default is 1, i.e. keep the first dump).
keep_last : int, optional
    Number of newest dump files to keep (default is 3, i.e. keep the last 3 dumps).

Returns
-------
None
    This method does not return a value.

Definition at line 150 of file __init__.py.

Here is the call graph for this function:

Member Data Documentation

◆ dump_prefix

shamrock.utils.dump.ShamrockDumpHandleHelper.dump_prefix = dump_prefix

Definition at line 68 of file __init__.py.

◆ ext

shamrock.utils.dump.ShamrockDumpHandleHelper.ext = ext

Definition at line 69 of file __init__.py.

◆ metadata

shamrock.utils.dump.ShamrockDumpHandleHelper.metadata = metadata

Definition at line 71 of file __init__.py.

◆ model

shamrock.utils.dump.ShamrockDumpHandleHelper.model = model

Definition at line 67 of file __init__.py.


The documentation for this class was generated from the following file: