shamrock.utils.dump.ShamrockDumpHandleHelper#

class shamrock.utils.dump.ShamrockDumpHandleHelper(model, dump_prefix, ext='.sham', metadata=False)#

Bases: object

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.

Methods

get_dump_name

Get the name of the dump file (extension from self.ext)

get_dump_name_extension

Get the name of the dump file with the extension

get_last_dump

Find the last dump number.

load_dump

Load a dump file.

load_last_dump_or

Load the last dump or call a function if no dump is found.

purge_old_dumps

Purge old dump files.

write_dump

Write a dump file.

Production run: Circular disc & pseudo-newtonian Paczynski Wiita potential

Production run: Circular disc & pseudo-newtonian Paczynski Wiita potential
get_dump_name(idump) str#

Get the name of the dump file (extension from self.ext)

get_dump_name_extension(idump, ext) str#

Get the name of the dump file with the extension

get_last_dump() int | None#

Find the last dump number.

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

load_dump(idump) dict | None#

Load a dump file.

Parameters#

idumpint

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.

load_last_dump_or(functor_no_last_dump) dict | None#

Load the last dump or call a function if no dump is found.

Parameters#

functor_no_last_dumpcallable

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.

purge_old_dumps(keep_first=1, keep_last=3) None#

Purge old dump files.

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

Parameters#

keep_firstint, optional

Number of oldest dump files to keep (default is 1, i.e. keep the first dump).

keep_lastint, 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.

write_dump(idump, metadata=None, purge_old_dumps=False, keep_first=1, keep_last=3) None#

Write a dump file.

Parameters#

idumpint

The dump identifier to write.

metadataobject, optional

JSON-serializable metadata stored in a .json companion next to the checkpoint. Required when metadata was enabled at construction.

purge_old_dumpsbool, optional

Whether to purge old dumps (default is False).

keep_firstint, optional

Number of oldest dump files to keep (default is 1, i.e. keep the first dump).

keep_lastint, 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.