Unit testing of MTK sub-models

Hello.

I am curious about the expected behavior of MTK when composing large models from sub-models. I’m hoping to better identify and understand which sub-models I’ve designed poorly.

Questions :

  1. Sometimes when I make an ODESystem, I can structural_simplify() the system, I can solve() the ODEProblem with the structural_simplified system, but cannot solve() it with the original system. Is this acceptable, or is it indicative of a poorly designed MTK ODESystem? Should a correctly defined MTK ODESystem always be solvable in an ODEProblem prior to structural simplification, or are there some ODESystems that must be structural_simplified?

  2. The states and equations of a structurally_simplified ODESystem must be equal. Is that also true for a well designed system before it is strucuturally_simplified? Is that only true if you want to solve an ODEProblem with it? Does that change for a DAE?

  3. If I create an ODESystem that has input states defined, but not connected to anything, can I make this ODESystem, structural_simplify the system, create an ODEProblem of the structural_simplified system and solve the ODEProblem without making those connections first?

Thanks,
JD

That’s natural if it requires inputs.

Not necessarily, if it requires inputs.

No, you have to at some point say what the inputs are. Even if it’s just connecting it to the zero function.

Great, thanks for the response Chris! So for example, if I have a sub-model with 9 states, 3 are input, 3 are output, and 3 are internal with initial conditions supplied, sounds like the right way to unit test this model is to provide the input connections to constants (or steps or some other source) first. I wasn’t sure if supplying initial conditions to those inputs would be sufficient to make the sub-model run standalone.

Follow up question:
If all inputs are provided, and both the input subsystem and the subsystem being tested are defined well, 1. Should the combined system be solvable prior to structural_simplification?
2. Should the states and equations for the combined system be equal prior to structural_simplification?

Of course I plan to structural_simplify all of my models. Just trying to see if I can use the pre-simplified model to determine if it’s been poorly defined. I have made systems to test these ideas but sometimes feel like I’m just getting lucky when it works without really understanding why. Just trying to gain that understanding and intuition about MTK systems.

Actually another follow up question:
3. Do MTK models need to be structurally_simplified, can any well defined model be ran without structural_simplification?

Again, I think SS is one of the coolest features of MTK and plan to use it, and I don’t have a good use case for this scenario. Just curious.

Thanks again,
JD

Kind of but not really. The main thing is numerical difficulties. If your DAE has index > 1 then most ODE solvers cannot solve it because of numerical issues. Thus one of the biggest reasons for structural simplification is that it performs an index reduction which removes Jacobian singularities and thus makes it easier to simulate. So in theory any system can be solved before simplification, but in practice there’s a large class of models which cannot due to this index phenomena.

Yes.

Yes