Skip to content

Commit ad13527

Browse files
author
Torax team
committed
Merge pull request #1420 from google-deepmind:improve-restart-docs
PiperOrigin-RevId: 792641932
2 parents c2fbafc + 3e28e8f commit ad13527

File tree

2 files changed

+69
-44
lines changed

2 files changed

+69
-44
lines changed

docs/configuration.rst

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,68 @@ transport
17471747
This is the default model. This model does not have any additional
17481748
configurable parameters.
17491749
1750+
restart
1751+
-------
1752+
1753+
If this optional entry is supplied in the config, TORAX will be run starting from the
1754+
selected state in a previous simulation. This can be used to resume a completed
1755+
simulation.
1756+
1757+
If the requested restart time is not exactly available in the state file, the
1758+
simulation will restart from the closest available time. A warning will be
1759+
logged in this case.
1760+
1761+
1762+
``filename`` (PathLike)
1763+
Path to an existing TORAX output file (netCDF format).
1764+
1765+
``time`` (float)
1766+
Time in output file to load as the new initial state.
1767+
1768+
``do_restart`` (bool)
1769+
If True, perform the restart from the selected state. If False, disable the
1770+
restart and run the simulation as normal.
1771+
1772+
``stitch`` (bool)
1773+
If True, concatenate the old and new simulation histories in the resulting
1774+
output file. If False, output file will only contain the new history.
1775+
1776+
1777+
For example, following a simulation in which a state file is saved to
1778+
``/path/to/torax_state_file.nc``, a new simulation can be started from the old
1779+
state at ``t=10`` by adding the following to the config:
1780+
1781+
.. code-block:: python
1782+
1783+
'restart': {
1784+
'filename': '/path/to/torax_state_file.nc',
1785+
'time': 10,
1786+
'do_restart': True,
1787+
'stitch': True,
1788+
}
1789+
1790+
The resulting simulation will recreate the state from ``t=10`` in the
1791+
previous simulation, and then run forwards from that point in time. For
1792+
all subsequent steps the dynamic runtime parameters will be constructed using
1793+
the runtime parameter configuration provided in the new config (from ``t=10``
1794+
onwards).
1795+
1796+
If the requested restart time is not exactly available in the state file, the
1797+
simulation will restart from the closest available time. A warning will be
1798+
logged in this case.
1799+
1800+
Some potential use cases for this feature include:
1801+
1802+
* Restarting a simulation that was healthy up to a certain time and then failed.
1803+
After fixing the cause of the failure, a new simulation can be run from the
1804+
last healthy point.
1805+
1806+
* Performing uncertainty quantification by sweeping a set of configs starting
1807+
from the same initial plasma state. After performing an initial simulation,
1808+
the restart option could be used to run a set of configs with modified
1809+
parameters to evaluate the impact of their variation.
1810+
1811+
17501812
Additional Notes
17511813
================
17521814
@@ -1924,43 +1986,3 @@ CHEASE geometry), is shown below. The configuration file is also available in
19241986
'calculator_type': 'fixed',
19251987
},
19261988
}
1927-
1928-
1929-
Restarting a simulation
1930-
=======================
1931-
In order to restart a simulation a field can be added to the config.
1932-
1933-
For example following a simulation in which a state file is saved to
1934-
``/path/to/torax_state_file.nc``, if we want to start a new simulation from the
1935-
state of the previous one at ``t=10`` we could add the following to our config:
1936-
1937-
.. code-block:: python
1938-
1939-
{
1940-
'filename': '/path/to/torax_state_file.nc',
1941-
'time': 10,
1942-
'do_restart': True, # Toggle to enable/disable a restart.
1943-
# Whether or not to pre"stitch" the contents of the loaded state file up
1944-
# to `time` with the output state file from this simulation.
1945-
'stitch': True,
1946-
}
1947-
1948-
The subsequence simulation will then recreate the state from ``t=10`` in the
1949-
previous simulation and then run the simulation from that point in time. For
1950-
all subsequent steps the dynamic runtime parameters will be constructed using
1951-
the given runtime parameter configuration (from ``t=10`` onwards).
1952-
1953-
If the requested restart time is not exactly available in the state file, the
1954-
simulation will restart from the closest available time. A warning will be
1955-
logged in this case.
1956-
1957-
We envisage this feature being useful for example to:
1958-
1959-
* restart a(n expensive) simulation that was healthy up till a certain time and
1960-
then failed. After discovering the issue for breakage you could then restart
1961-
the sim from the last healthy point.
1962-
1963-
* do uncertainty quantification by sweeping lots of configs following running
1964-
a simulation up to a certain point in time. After running the initial
1965-
simulation you could then modify and sweep the runtime parameter config in
1966-
order to do some uncertainty quantification.

torax/_src/torax_pydantic/file_restart.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ class FileRestart(torax_pydantic.BaseModelFrozen):
2121
"""Pydantic config for restarting a simulation from a file.
2222
2323
Attributes:
24-
filename: Filename to load initial state from.
25-
time: Time in state file at which to load from.
26-
do_restart: Toggle loading initial state from file or not.
27-
stitch: Whether to stitch the state from the file.
24+
filename: Path to an existing TORAX output file (netCDF format).
25+
time: Time in output file to load as the new initial state.
26+
do_restart: If True, perform the restart from the selected state.
27+
If False, disable the restart and run the simulation as normal.
28+
stitch: If True, concatenate the old and new simulation histories
29+
in the resulting output file. If False, output file will only
30+
contain the new history.
2831
"""
2932

3033
filename: pydantic.FilePath

0 commit comments

Comments
 (0)