Fix number of stress period end states for multi-model simulations#73
Conversation
The `Callbacks.stress_period_end` needs to be emmitted for each model. If it it outside this loop it is only emmitted for the last model.
|
Thanks for this @pya. The state checker is nice. How difficult would it be to write an autotest around it? |
|
@wpbonelli |
|
It's mostly plain pytest, modulo the question of which models to test and how to get them. Maybe the simplest way is just to replace this line with Also fyi the tests currently assume |
|
Sounds easy enough. But I would need to write two tests and would need to add checking of the state sequences. Looks like I am going to copy this twice. So it could make sense to make it a helper, i.e. a fixture, that lives in |
|
If you mean a fixture for the state checker, yes, that sounds good- whatever you think makes the most sense. |
|
What are you thinking re: adding two new tests? I figure we could just use your module in the existing test function and add a few assertions, but maybe I'm thinking about it wrong. |
|
I though about adding a new (parameterized) test. But as long as the callback is read-only, i.e. doesn't change any MF6 variables, just modifying the existing test should work. I will do this. In the long run I see these tests in
What do you think about this strategy? This would require to run the 150+ example multiple times. Is this a problem regarding CI resources? Since all model runs are independent, the problem is embarrassing parallel and parallelization should work automatically for parameterized tests with |
|
I like that approach in the long run, some quick thoughts. On 2), maybe simplest to start with comparing head/conc/etc. We have some comparison utilities in mf6/devtools we could reuse for that. Comparing log files might be tricky. On 3), does changing a variable buy us anything new over running the original model and comparing results? I figure |
|
Thanks for your suggestions. On 2) Yes comparing On 3) |
|
Good points @pya. I am happy to help out with the comparison stuff and the expanded testing. |
|
@pya @wpbonelli |
The number of start and end states of stress period, time step, and iteration needs to match for each model. This checks for the counts. It does not look at the sequence. Furthermore, five models seem to have other problems with the current and total number of time steps and the condition `sim_grp.nstp == sim_grp.kstp + 1` in line 113 in `runner.py` is not met as often as it should. This is a working hypothesis that requires deeper investigation. Skip the count tests for these models for now.
|
I see your point. I think of the tests for the examples more like a scan for potential problems. Once a problem is identified, adding or modifying an interface test might be the next step. Keeping these scans around as tests applies them automatically to new example models. There might a model that has a new combination of features that the tests didn't consider yet. The scan tests might stumble over a potential problem much earlier than an interface test that needs to be designed to find a problem. This requires anticipating the problem in some way. How detailed these scan tests should be is a different question. Ideally, the same test should work for all example models. Adding many different cases may make things a bit too complex. |
The viscosity example uses a separate solution for each model. I'm still new to the api, but the distribution of models into solution groups should be independent of the number of stress period start/end events raised, right?
I think what is under consideration here is just extending the existing test function in |
|
I think we are mixing two topics here:
Why not separate these two? Let's move the discussion about 2. to a "discussion issue" and make this PR only about 1. Are there any necessary changes to make the PR work? Since the stress period count should be per solution group, there should be no difference between one solution and multiple solutions groups in the tests as they are. Or, I am I mistaken here? |
|
@jlarsen-usgs @wpbonelli |
|
@pya, just wanted to check and test on my end. The PR looks good and is likely the simplest solution for this issue, merging it in. |
Problem
The number of start and end states such as
Callback.timestep_startandCallback.timestep_endorCallback.stress_period_startandCallback.stress_period_endhanded to the callback function should match in number over the simulation run time.Furthermore, the states should be grouped in a parenthesis-like fashion with these levels:
This holds for the model
ex-gwf-advtidalfrom the MODFLOW 6 examples:But it this does not apply to the model
ex-gwe-vsc, which has several sub-models. The count of the statestress_period_enddoesn't match the number ofstress_period_startstate expect for one sub-model:Solution
The problem is the location of the code
in
modflowapi.extension.runner.pyafter the solution loop. Moving this code inside this loop fixes the matching problem of the stress period states:Tools
The script
manualtest.collect_states.pyprovides functions to run the model with a callback function that records the states and creates the above shown DataFrames:The function
visualize_statesallows to show the nesting of the states.Example output: