Skip to content

Intermediate state vars

Marmaduke Woodman requested to merge intermediate-state-vars into master

Created by: dionperd

Some corrections to the modifications already merged that need to be updated asap, because now master leads to errors.

The main correction is that we cannot have dfun return only the integrated variables' derivatives because integration schemes with intermediate steps fail, because they rely to state variable X having the same size as the intermediate derivatives dX. So, I have made it to return 0 derivatives for non-integrated intermediate state variables, until some other solution is found. We can't give a reduced (masked) state vector to dfun() either, which would be an alternative solution, because then dfun cannot use the intermediate state variables for its computations. Mind also that although we can modify the integration schemes to use the state_variables_mask, we cannot do so for ScipyODE solvers...

Accordingly we don't need a mask of integrated variables in the base Model class anymore. Instead, I added a _nintvar and a respective property method @nintvar to count the integrated variables during Model.configure. I also added a check of assert to compare integration_variables with state_variables.

So, now, the Simulator checks if nintvar < nvar to decide about the integrate_next_step method.

Moreover, we need to reduce redundancy of node_coupling computation in the master branch. It needs to be computed only after integration of step "step" with argument "step+1".

A possible AfferentCoupling Monitor, though, will still get the node_coupling of step "step", and therefore, node_coupling needs to be recomputed after the computation of outputs, and just before we move to next step.

Also, I use start_step = Simulator.current_step + 1 to reduce a bit the redundancy of this +1 used 3 times.

Finally, I corrected the simulator_test substituting asserts of state_variables_mask with assert simulator.model.nintvar == len(simulator.model.integration_variables)

as well as models_test and integrators_test for minor errors.

I cannot understand the last error the tests lead to...

Merge request reports