Skip to content

Commit

Permalink
Address reviewer comments
Browse files Browse the repository at this point in the history
Add a `do_restart` attribute to keep track of which runs are
restart runs, rather than using the step name.
  • Loading branch information
xylar committed Dec 23, 2024
1 parent ee6d56d commit b6dcacb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
11 changes: 10 additions & 1 deletion polaris/ocean/tasks/cosine_bell/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ class Forward(SphericalConvergenceForward):
"""
A step for performing forward ocean component runs as part of the cosine
bell test case
Attributes
----------
do_restart : bool
Whether this is a restart run
"""

def __init__(self, component, name, subdir, mesh, init,
refinement_factor, refinement):
refinement_factor, refinement, do_restart=False):
"""
Create a new step
Expand All @@ -35,6 +40,9 @@ def __init__(self, component, name, subdir, mesh, init,
refinement : str
Refinement type. One of 'space', 'time' or 'both' indicating both
space and time
do_restart : bool, optional
Whether this is a restart run
"""
package = 'polaris.ocean.tasks.cosine_bell'
validate_vars = ['normalVelocity', 'tracer1']
Expand All @@ -46,6 +54,7 @@ def __init__(self, component, name, subdir, mesh, init,
graph_target=f'{mesh.path}/graph.info',
refinement_factor=refinement_factor,
refinement=refinement)
self.do_restart = do_restart

def setup(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion polaris/ocean/tasks/cosine_bell/restart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ def __init__(self, component, config, icosahedral, refinement_factor,
step_names = ['full_run', 'restart_run']
for name in step_names:
subdir = f'{task_subdir}/{name}'
do_restart = (name == 'restart_run')
step = RestartStep(
component=component, name=name, subdir=subdir,
mesh=base_mesh_step, init=init_step,
refinement_factor=refinement_factor,
refinement=refinement)
refinement=refinement, do_restart=do_restart)
step.set_shared_config(
config, link=config_filename)
self.add_step(step)
Expand Down
10 changes: 4 additions & 6 deletions polaris/ocean/tasks/cosine_bell/restart/restart_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,22 @@ def dynamic_model_config(self, at_setup):
"""
super().dynamic_model_config(at_setup)

do_restart = self.do_restart

dt, _ = get_timestep_for_task(
self.config, self.refinement_factor, refinement=self.refinement)
dt = np.ceil(dt)

if self.name == 'full_run':
if not do_restart:
# 2 time steps without a restart
do_restart = False
start_time = 0.
run_duration = 2. * dt
output_interval = 2. * dt
elif self.name == 'restart_run':
else:
# 1 time step from the restart at 1 time step
do_restart = True
start_time = dt
run_duration = dt
output_interval = dt
else:
raise ValueError(f'Unexpected step name {self.name}')

# to keep the time formatting from getting too complicated, we'll
# assume 2 time steps is never more than a day
Expand Down

0 comments on commit b6dcacb

Please sign in to comment.