-
-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plotting no longer works for MTK JumpSystems over ODEProblems #3188
Comments
@AayushSabharwal are jumps captured as discrete variables now? |
I don't think so. There's nothing special we do for discrete variables in JumpSystem to my knowledge |
The problem here is that solutions of jump systems seem to do some black magic that SII isn't aware of: infil> sol
retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 36-element Vector{Float64}:
0.0
# ...
u: 36-element Vector{ExtendedJumpArray{Float64, 1, Vector{Float64}, Vector{Float64}}}:
[0.0, 0.0]
# ... Note how it appears julia> sol.u[1]
3-element ExtendedJumpArray{Float64, 1, Vector{Float64}, Vector{Float64}}:
0.0
0.0
-0.2529329586712836 I'm not aware of what this is or what it's supposed to mean. As far as SII/the |
Yeah they have pseudo variables that are used for the event handling in jump detection. They aren't real variables. I have thought for over a year now that we should probably just not hide them from the user and just use a ComponentArray by default or something. But SII validation needs to somehow allow this. Maybe we need to declare pseudonames for them in the MTK side? |
If the system specification can determine the number and names of pseudo variables, SII will be happy. Right now, The true solution would be for |
Yes, that will be the case for the general solution. But for a more immediate solution, maybe we just need an interface |
Do we not want to plot the first two? |
You want to plot only the first two. |
Alright yeah then |
I'd need an MWE to tell you more. Just from the stacktrace, it could be either of the two reasons. |
Note that propensities/intensities in JumpProcesses arising from VariableRateJumps, the "pseudo-variables" in the discussion above, can be continuous in time. So it wouldn't be appropriate to treat them as discrete (or even as piecewise-constant in general). |
Yeah, so those should be turned into states instead of being anonymous variables and we should get better discrete/piecewise continuous support and use that here |
How can JumpProcesses turn them into states? They are only added at the level of the edit: I mean turn them into states in a way that works with symbolic indexing? |
The JumpSystem contains enough information to compute how many of them are required, right? So it should just be able to add them as artificial states in, say, a custom |
Maybe we can have a kwarg that is passed to a JumpProblem that MTK generates, For now can we do what Chris suggested above to get |
Why would we need to do that? Just because they're unknowns in the system doesn't mean they have to be part of
Already merged to SciMLBase#master |
Yes, they don't need to be. A better implementation would use https://docs.sciml.ai/DiffEqCallbacks/stable/integrating/. A slightly more complicated discretecallback could be used to do the integral approximation with a direct rootfinding approach on it. But doing the full thing here would be a good chunk of work. |
OK, that is great to hear. I have no idea how one can get MTK to generate a system/Problem where the final generated |
Awesome! |
#3193 is the issue for it. If we modeled the variable rate jumps symbolically and MTK did this optimization, we'd actually be quite a bit faster in many cases. But we'd have to move the rootfinding to the callback as well. But, because the interpolation of the ODE solution is a polynomial, that rootfinding would be a polynomial rootfind on the integral of the interpolating polynomial, and so we could use HomotopyContinuation to guarantee that we find all roots w.r.t. t. That would make it much more robust and quite a bit faster. It's a good chunk of work but that is probably what we really need to make the hybrid modeling shine. The nice part of doing it explicitly through MTK though is that this optimization can apply to many systems. A lot of systems people write down can simplify out part of it, so you'd get some good speedups in lots of places. ExtendedJumpArray only had its weird behavior because SII didn't exist. Without SII and symbolic indexing, changing someone's So with all of the SII things, and then also the inline SCC nonlinear solving stuff (which is an even bigger change to most Catalyst integration, especially with homotopy integration), we'll really need to reconsider the variable rate jump implementation since I would not be surprised to see it get 100x faster through connecting with the other optimizations going on. |
With the SciMLBase fix and SciML/JumpProcesses.jl#461 this seems to work now. Thanks @AayushSabharwal for the quick fix. |
gives
Environment:
For a JumpProblem over a DiscreteProblem things still seem to work:
The text was updated successfully, but these errors were encountered: