-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(MfSimulationList): add functionality to parse the mfsim.lst file #2005
Merged
+397
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
95b39cd
feat(MfSimulationList): add functionality to parse the mfsim.lst file
jdhughes-usgs 014b214
* add testing for MfSimulationList
jdhughes-usgs 4136149
* isort imports
jdhughes-usgs e89a41d
* update MfSimulationList runtime function
jdhughes-usgs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import numpy as np | ||
import pytest | ||
from autotest.conftest import get_example_data_path | ||
from modflow_devtools.markers import requires_exe | ||
|
||
import flopy | ||
from flopy.mf6 import MFSimulation | ||
|
||
|
||
def base_model(sim_path): | ||
load_path = get_example_data_path() / "mf6-freyberg" | ||
|
||
sim = MFSimulation.load(sim_ws=load_path) | ||
sim.set_sim_path(sim_path) | ||
sim.write_simulation() | ||
sim.run_simulation() | ||
|
||
return sim | ||
|
||
|
||
@pytest.mark.xfail | ||
def test_mfsimlist_nofile(function_tmpdir): | ||
mfsimlst = flopy.mf6.utils.MfSimulationList(function_tmpdir / "fail.lst") | ||
|
||
|
||
@requires_exe("mf6") | ||
def test_mfsimlist_normal(function_tmpdir): | ||
sim = base_model(function_tmpdir) | ||
mfsimlst = flopy.mf6.utils.MfSimulationList(function_tmpdir / "mfsim.lst") | ||
assert mfsimlst.is_normal_termination, "model did not terminate normally" | ||
|
||
|
||
@pytest.mark.xfail | ||
def test_mfsimlist_runtime_fail(function_tmpdir): | ||
sim = base_model(function_tmpdir) | ||
mfsimlst = flopy.mf6.utils.MfSimulationList(function_tmpdir / "mfsim.lst") | ||
runtime_sec = mfsimlst.get_runtime(units="abc") | ||
|
||
|
||
@requires_exe("mf6") | ||
def test_mfsimlist_runtime(function_tmpdir): | ||
sim = base_model(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" | ||
) | ||
|
||
|
||
@requires_exe("mf6") | ||
def test_mfsimlist_iterations(function_tmpdir): | ||
it_outer_answer = 13 | ||
it_total_answer = 413 | ||
|
||
sim = base_model(function_tmpdir) | ||
mfsimlst = flopy.mf6.utils.MfSimulationList(function_tmpdir / "mfsim.lst") | ||
|
||
it_outer = mfsimlst.get_outer_iterations() | ||
assert it_outer == it_outer_answer, ( | ||
f"outer iterations is not equal to {it_outer_answer} " | ||
+ f"({it_outer})" | ||
) | ||
|
||
it_total = mfsimlst.get_total_iterations() | ||
assert it_total == it_total_answer, ( | ||
f"total iterations is not equal to {it_total_answer} " | ||
+ f"({it_total})" | ||
) | ||
|
||
|
||
@requires_exe("mf6") | ||
def test_mfsimlist_memory(function_tmpdir): | ||
virtual_answer = 0.0 | ||
|
||
sim = base_model(function_tmpdir) | ||
mfsimlst = flopy.mf6.utils.MfSimulationList(function_tmpdir / "mfsim.lst") | ||
|
||
total_memory = mfsimlst.get_memory_usage() | ||
assert total_memory > 0.0, ( | ||
f"total memory is not greater than 0.0 " + f"({total_memory})" | ||
) | ||
|
||
virtual_memory = mfsimlst.get_memory_usage(virtual=True) | ||
if not np.isnan(virtual_memory): | ||
assert virtual_memory == virtual_answer, ( | ||
f"virtual memory is not equal to {virtual_answer} " | ||
+ f"({virtual_memory})" | ||
) | ||
|
||
non_virtual_memory = mfsimlst.get_non_virtual_memory_usage() | ||
assert total_memory == non_virtual_memory, ( | ||
f"total memory ({total_memory}) " | ||
+ f"does not equal non-virtual memory ({non_virtual_memory})" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
guess this is because virtual memory is only used for mf6 parallel at the moment — once flopy has more parallel support a parallel test case could be added to check virtual memory usage I imagine