Inconsistent number of time steps
IngridKJ opened this issue · comments
For certain parameter values in TimeManager, an inconsistent number of time steps is run. When the simulation reaches its final time step, it varies (due to floating points) whether the model.time_manager.time has reached set final time. So, the condition in run_models.py, line 141, is fulfilled though it shouldn't.
E.g., for 10 assigned time steps (see code snippet below), the final time is set to be 1.0. However, when the final time step has been run, the model.time_manager.time only holds a value of .9999999999999999. Therefore it runs an additional time step.
For e.g. 20 time steps, the expected number of time steps is run. So there is an inconsistency here.
Code snippet is in this file:
inconsistent_time_steps.txt
Should be a simple matter of using np.isclose. Beware the tolerance pitfalls.
Indeed, this is simply a matter of introducing np.isclose
for all time comparisons. We should consider passing a tol
input at instantiation with a default value and make sure np.isclose
is used throughout the the class.
Resolved in #1100