diff --git a/tests/more-tests/stepper_cache/stepper_cache.mdl b/tests/more-tests/stepper_cache/stepper_cache.mdl new file mode 100644 index 00000000..62728909 --- /dev/null +++ b/tests/more-tests/stepper_cache/stepper_cache.mdl @@ -0,0 +1,89 @@ +{UTF-8} +bar= + 2*foo + ~ + ~ | + +foo= + 5 + ~ + ~ | + +foobar= + 2*bar + ~ + ~ | + +******************************************************** + .Control +********************************************************~ + Simulation Control Parameters + | + +FINAL_TIME = 5 + ~ Month + ~ The final time for the simulation. + | + +INITIAL_TIME = 0 + ~ Month + ~ The initial time for the simulation. + | + +SAVEPER = + TIME_STEP + ~ Month [0,?] + ~ The frequency with which output is stored. + | + +TIME_STEP = 1 + ~ Month [0,?] + ~ The time step for the simulation. + | + +\\\---/// Sketch information - do not modify anything except names +V300 Do not put anything below this section - it will be ignored +*View 1 +$192-192-192,0,Courier|12||0-0-0|0-0-0|0-0-255|-1--1--1|255-255-255|96,96,100,0 +10,1,foo,224,216,16,9,8,3,0,0,0,0,0,0,0,0,0,0,0,0 +10,2,bar,397,218,16,9,8,3,0,0,0,0,0,0,0,0,0,0,0,0 +10,3,foobar,571,216,29,9,8,3,0,0,0,0,0,0,0,0,0,0,0,0 +1,4,1,2,0,0,0,0,0,128,0,-1--1--1,,1|(0,0)| +1,5,2,3,0,0,0,0,0,128,0,-1--1--1,,1|(0,0)| +///---\\\ +:L<%^E!@ +5:foobar +19:100,0 +24:0 +25:0 +26:0 +15:0,0,0,0,0,0 +27:0, +34:0, +42:0 +72:0 +73:0 +35:Date +36:YYYY-MM-DD +37:2000 +38:1 +39:1 +40:2 +41:0 +95:0 +96:0 +97:0 +77:0 +78:0 +102:1 +93:0 +94:0 +92:0 +91:0 +90:0 +87:0 +75: +43: +103:8,8,8,3,8 +105:0,0,0,0,0,0,0,0,0,0 +104:Courier|12||0-0-0|0-0-0|-1--1--1|0-0-255|192-192-192|-1--1--1 diff --git a/tests/pytest_pysd/pytest_pysd.py b/tests/pytest_pysd/pytest_pysd.py index 2df7d12b..09cad057 100644 --- a/tests/pytest_pysd/pytest_pysd.py +++ b/tests/pytest_pysd/pytest_pysd.py @@ -23,7 +23,6 @@ test_model_data = Path( "test-models/tests/get_data_args_3d_xls/test_get_data_args_3d_xls.mdl") - more_tests = Path("more-tests") test_model_constant_pipe = more_tests.joinpath( @@ -1486,7 +1485,7 @@ def test_change_constant_pipe(self, model): (out2["constant3"] == (5*new_var.values-1)*new_var.values).all() @pytest.mark.parametrize("model_path", [test_model]) - def test_stepper(self, model): + def test_stepper_workflow(self, model): output = ModelOutput() @@ -1506,6 +1505,36 @@ def test_stepper(self, model): np.array_equal(result_df["Room Temperature"].values, result_temperatures) assert np.floor(result_df.loc[5, "Teacup Temperature"]) == 144 + def test_stepper_cache_assignment(self, _root): + + test_model_stepper = _root.joinpath( + "more-tests/stepper_cache/stepper_cache.mdl") + + model = pysd.read_vensim(test_model_stepper) + + assert model.cache_type["foo"] == "run" + assert model.cache_type["bar"] == "run" + assert model.cache_type["foobar"] == "run" + + output = ModelOutput() + + model.set_stepper(output, params={"foo": 0}, time_step=0.2, + saveper=0.2, final_time=5, step_vars=["foo"]) + + assert model.cache_type["foo"] == "step" + assert model.cache_type["bar"] == "step" + assert model.cache_type["foobar"] == "step" + + steps = int((model["final_time"] - model["initial_time"]) / + model["time_step"]) + + for i in range(1,steps + 1): + model.step(1, {"foo": i}) + + res = output.collect(model) + + assert np.floor(res.loc[5, "foobar"]) == 100 + class TestExportImport():