Skip to content

Commit

Permalink
Merge pull request #784 from PhilipDeegan/elapsed_time_test
Browse files Browse the repository at this point in the history
elapsed time tests, find restart timestep
  • Loading branch information
nicolasaunai authored Nov 26, 2023
2 parents ab52821 + 5262a75 commit 501fb3b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/simulator/test_restarts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
import numpy as np
from pathlib import Path
from datetime import timedelta

from ddt import ddt, data, unpack
Expand Down Expand Up @@ -329,10 +330,23 @@ def test_restarts_elapsed_time(self, ndim, interp, simInput, expected_num_levels
self.register_diag_dir_for_cleanup(local_out)
diag_dir0 = local_out

def _find_restart_time():
maxRestartTime = 35
# elapsedtime restarts are stored with the simulation time (timestep * time_step_idx)
# so we have to find it in the output directory cause we can't know in advance
# which timestep index will write to disk
from pyphare.cpp import cpp_etc_lib
for i in range(1, maxRestartTime):
restart_time = i*time_step
if Path(cpp_etc_lib().restart_path_for_time(diag_dir0, restart_time)).exists():
return restart_time
raise RuntimeError("tests_restarts::test_restarts_elapsed_time No restart file found")

# second restarted simulation
local_out = f"{local_out}_n2"
simput["diag_options"]["options"]["dir"] = local_out
simput["restart_options"]["restart_time"] = restart_time

simput["restart_options"]["restart_time"] = _find_restart_time()
ph.global_vars.sim = None
del simput["restart_options"]["elapsed_timestamps"]
ph.global_vars.sim = ph.Simulation(**simput)
Expand Down

0 comments on commit 501fb3b

Please sign in to comment.