Skip to content

Commit

Permalink
return to get_simulation. Cache call to time()
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Jan 18, 2024
1 parent c50fae0 commit a2f9982
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions cylc/flow/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self, itask: 'TaskProxy', broadcast_mgr: 'BroadcastMgr'):
else:
rtconfig = itask.tdef.rtconfig
self.simulated_run_length = (
set_simulated_run_len(rtconfig))
get_simulated_run_len(rtconfig))
self.sim_task_fails = sim_task_failed(
rtconfig['simulation'],
itask.point,
Expand All @@ -88,7 +88,7 @@ def configure_sim_modes(taskdefs, sim_mode):
rtc['pre-script'] = ""
rtc['post-script'] = ""
rtc['script'] = build_dummy_script(
rtc, set_simulated_run_len(rtc))
rtc, get_simulated_run_len(rtc))

disable_platforms(rtc)

Expand All @@ -102,7 +102,7 @@ def configure_sim_modes(taskdefs, sim_mode):
)


def set_simulated_run_len(rtc: Dict[str, Any]) -> int:
def get_simulated_run_len(rtc: Dict[str, Any]) -> int:
"""Calculate simulation run time from a task's config.
rtc = run time config
Expand Down Expand Up @@ -196,6 +196,7 @@ def sim_time_check(
Returns:
True if _any_ simulated task state has changed.
"""
now = time()
sim_task_state_changed: bool = False
for itask in itasks:
if (
Expand Down Expand Up @@ -223,7 +224,7 @@ def sim_time_check(
itask.mode_settings = ModeSettings(itask, broadcast_mgr)

timeout = started_time + itask.mode_settings.simulated_run_length
if time() > timeout:
if now > timeout:
job_d = itask.tokens.duplicate(job=str(itask.submit_num))
now_str = get_current_time_string()

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
parse_fail_cycle_points,
build_dummy_script,
disable_platforms,
set_simulated_run_len,
get_simulated_run_len,
sim_task_failed,
)

Expand All @@ -38,7 +38,7 @@
param('P1D', 24, 'PT1M', id='speed-up-and-execution-tl'),
)
)
def test_set_simulated_run_len(
def test_get_simulated_run_len(
execution_time_limit, speedup_factor, default_run_length
):
"""Test the logic of the presence or absence of config items.
Expand All @@ -53,7 +53,7 @@ def test_set_simulated_run_len(
'time limit buffer': 'PT0S',
}
}
assert set_simulated_run_len(rtc) == 3600
assert get_simulated_run_len(rtc) == 3600


@pytest.mark.parametrize(
Expand Down

0 comments on commit a2f9982

Please sign in to comment.