RestartModule#

class fridom.framework.modules.RestartModule(realtime_interval: timedelta64 | None = None, clock_trigger: ClockTrigger | None = None, restart_command: str | Callable | None = None, file_path: Path | str = PosixPath('restart/model.dill'))[source]#

Bases: Module

Automatically restart the job at a given interval.

Description#

Parameters#

realtime_intervalnp.timedelta64, optional

The interval in real time at which the model should restart. If None, the model will not restart based on real time.

clock_triggerfr.ClockTrigger, optional

Triggers the restart based on the model time. If None, the model will not restart based on model time.

restart_commandstr or Callable, optional

The command to start the job. If the command is a string:

The model will restart by running the command in a subprocess.

If the command is a callable:

The model will restart by calling the function. This function should simply restart the job. It should have no arguments, and should return nothing.

If the command is None:

The model will try to find the command from the environment. If the command is not found, the model will not be able to restart.

file_pathPath, optional

The path to the restart file.

__init__(realtime_interval: timedelta64 | None = None, clock_trigger: ClockTrigger | None = None, restart_command: str | Callable | None = None, file_path: Path | str = PosixPath('restart/model.dill')) None[source]#

Methods

__init__([realtime_interval, clock_trigger, ...])

disable()

Disable the module.

enable()

Enable the module.

is_enabled()

Whether the module is enabled or not.

reset()

Stop and start the module.

restart(model)

Restart the model.

set_full_filename(it)

Set the full filename with the iteration number and rank.

setup(mset[, setup_mode])

Set the module up.

should_reload()

Check if the model should reload from a restart file.

should_restart(mz)

Check if one of the restart conditions is met.

start()

Start the module.

stop()

Stop the module.

update(mz)

Update the model state.

Attributes

clock_trigger

Triggers the restart based on the model time.

diff_module

The differentiation module to be used by this module.

file_path

The path to the restart file.

grid

The grid of the model settings.

info

Return a dictionary with information about the time stepper.

interp_module

The interpolation module to be used by this module.

is_setup

Whether the module is set up.

mset

The model settings.

name

realtime_interval

The interval in real time at which the model should restart.

required_halo

The required halo points for this module.

restart_command

The command to restart the job.

name = 'Restart Module'#
should_restart(mz: ModelState) bool[source]#

Check if one of the restart conditions is met.

should_reload() bool[source]#

Check if the model should reload from a restart file.

Description#

If a restart file is found in the directory, the model will reload. If multiple restart files are found, the model will reload from the restart file with the highest iteration number.

set_full_filename(it: int) None[source]#

Set the full filename with the iteration number and rank.

restart(model: Model) None[source]#

Restart the model.

Description#

This function stops the model, saves the model state to a file, and executes the restart command.

Parameters#

modelfr.Model

The model to restart.

property info: dict#

Return a dictionary with information about the time stepper.

Description#

This method should be overridden by the child class to return a dictionary with information about the time stepper. This information is used to print the time stepper in the __repr__ method.

property realtime_interval: timedelta64 | None#

The interval in real time at which the model should restart.

property clock_trigger: ClockTrigger | None#

Triggers the restart based on the model time.

By default, the clock trigger will not trigger on the first step. Any other option will be overridden. To trigger on the first step, set the trigger_on_first_step to True after setting the clock trigger, e.g.:

import fridom.framework as fr
restart_module = fr.modules.RestartModule(clock_trigger=fr.ClockTrigger())
restart_module.clock_trigger.trigger_on_first_step = True
property file_path: Path#

The path to the restart file.

property restart_command: str#

The command to restart the job.