From 4597f5f8d275188516119ce26a2b36deb137ca4c Mon Sep 17 00:00:00 2001 From: mjr-deltares Date: Wed, 15 Nov 2023 12:33:45 +0100 Subject: [PATCH 1/2] fix: add missing seek to get_runtime method --- autotest/test_mfsimlist.py | 34 +++++++++++++++++--------------- flopy/mf6/utils/mfsimlistfile.py | 1 + 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/autotest/test_mfsimlist.py b/autotest/test_mfsimlist.py index e45a046e89..8889f6bed6 100644 --- a/autotest/test_mfsimlist.py +++ b/autotest/test_mfsimlist.py @@ -43,22 +43,24 @@ def test_mfsimlist_runtime(function_tmpdir): mfsimlst = flopy.mf6.utils.MfSimulationList(function_tmpdir / "mfsim.lst") for sim_timer in ("elapsed", "formulate", "solution"): runtime_sec = mfsimlst.get_runtime(simulation_timer=sim_timer) - if not np.isnan(runtime_sec): - runtime_min = mfsimlst.get_runtime( - units="minutes", simulation_timer=sim_timer - ) - assert runtime_sec / 60.0 == runtime_min, ( - f"model {sim_timer} time conversion from " - + "sec to minutes does not match" - ) - - runtime_hrs = mfsimlst.get_runtime( - units="hours", simulation_timer=sim_timer - ) - assert runtime_min / 60.0 == runtime_hrs, ( - f"model {sim_timer} time conversion from " - + "minutes to hours does not match" - ) + + assert not np.isnan(runtime_sec) + + runtime_min = mfsimlst.get_runtime( + units="minutes", simulation_timer=sim_timer + ) + assert runtime_sec / 60.0 == runtime_min, ( + f"model {sim_timer} time conversion from " + + "sec to minutes does not match" + ) + + runtime_hrs = mfsimlst.get_runtime( + units="hours", simulation_timer=sim_timer + ) + assert runtime_min / 60.0 == runtime_hrs, ( + f"model {sim_timer} time conversion from " + + "minutes to hours does not match" + ) @requires_exe("mf6") diff --git a/flopy/mf6/utils/mfsimlistfile.py b/flopy/mf6/utils/mfsimlistfile.py index 387da10be7..713d244d80 100644 --- a/flopy/mf6/utils/mfsimlistfile.py +++ b/flopy/mf6/utils/mfsimlistfile.py @@ -114,6 +114,7 @@ def get_runtime( times_sec = np.sum(times * time2sec) else: seekpoint = self._seek_to_string(TIMERS_DICT[simulation_timer]) + self.f.seek(seekpoint) line = self.f.readline().strip() if line == "": return np.nan From dc29231b386bd02223c24bad4a7820d3270a12e1 Mon Sep 17 00:00:00 2001 From: mjr-deltares Date: Wed, 15 Nov 2023 15:37:10 +0100 Subject: [PATCH 2/2] too early for that assert --- autotest/test_mfsimlist.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/autotest/test_mfsimlist.py b/autotest/test_mfsimlist.py index 8889f6bed6..5a4f1661ab 100644 --- a/autotest/test_mfsimlist.py +++ b/autotest/test_mfsimlist.py @@ -44,23 +44,22 @@ def test_mfsimlist_runtime(function_tmpdir): for sim_timer in ("elapsed", "formulate", "solution"): runtime_sec = mfsimlst.get_runtime(simulation_timer=sim_timer) - assert not np.isnan(runtime_sec) - - runtime_min = mfsimlst.get_runtime( - units="minutes", simulation_timer=sim_timer - ) - assert runtime_sec / 60.0 == runtime_min, ( - f"model {sim_timer} time conversion from " - + "sec to minutes does not match" - ) - - runtime_hrs = mfsimlst.get_runtime( - units="hours", simulation_timer=sim_timer - ) - assert runtime_min / 60.0 == runtime_hrs, ( - f"model {sim_timer} time conversion from " - + "minutes to hours does not match" - ) + if not np.isnan(runtime_sec): + runtime_min = mfsimlst.get_runtime( + units="minutes", simulation_timer=sim_timer + ) + assert runtime_sec / 60.0 == runtime_min, ( + f"model {sim_timer} time conversion from " + + "sec to minutes does not match" + ) + + runtime_hrs = mfsimlst.get_runtime( + units="hours", simulation_timer=sim_timer + ) + assert runtime_min / 60.0 == runtime_hrs, ( + f"model {sim_timer} time conversion from " + + "minutes to hours does not match" + ) @requires_exe("mf6")