Skip to content
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

WIP: fixes for MTK changes #1186

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

WIP: fixes for MTK changes #1186

wants to merge 16 commits into from

Conversation

TorkelE
Copy link
Member

@TorkelE TorkelE commented Feb 17, 2025

Updates conservation laws to work with new remake version.

@isaacsas
Copy link
Member

This is probably never going to pass tests with the change in semantics for complete. We can no longer rely on the parameters of a completed system being the same as what was defined when creating the system, which I think a lot of tests rely on.

@isaacsas
Copy link
Member

We can also no longer rely on issetequal(parmeters(sys), get_ps(sys)) for a flattened system.

@TorkelE
Copy link
Member Author

TorkelE commented Feb 18, 2025

Let's see how this turns out. If something like what you suggest is really changing it would be one of the largest changes to Catalyst ever, probably after moving to maps as inputs to problems. Would probably take ages to figure out all the implications.

@isaacsas isaacsas changed the title Check new remake version WIP: fixes for MTK changes Feb 26, 2025
@isaacsas
Copy link
Member

@TorkelE let's just work in this PR to try to get tests working again.

I've handled the conservation law constants getting scalarized issue, and locally gotten tests in reactionsystem.jl working again.

@isaacsas
Copy link
Member

TODO:

  • isequivalent needs more comprehensive testing (perhaps a followup PR)?

@TorkelE
Copy link
Member Author

TorkelE commented Feb 26, 2025

I had some updates locally to sort out the new parameters, but there are quite a few recent MTK issues that are hard-blocking us so I stopped a bit:
SciML/ModelingToolkit.jl#3411
SciML/ModelingToolkit.jl#3410
SciML/ModelingToolkit.jl#3409
SciML/ModelingToolkit.jl#3408
SciML/ModelingToolkit.jl#3396

@isaacsas
Copy link
Member

OK, I'll get as much fixed here as I can modulo those issues and then plan to merge.

FYI, take a look at the changes to isequivalent. The nice feature is I added a debug kwarg that will printout specifically which fields are not the same. (I seem to always want this functionality when writing tests).

@isaacsas
Copy link
Member

@TorkelE everything before conservation laws should now work. I tried various combinations of guesses and missing but couldn’t get them to work. Are you ok if I merge this and we can resume if/when someone figures out how to handle that stuff?

elseif has_alg_equations(rs)
error("The input ReactionSystem has algebraic equations. This requires setting `structural_simplify=true` within `ODEProblem` call.")
# elseif has_alg_equations(rs)
# error("The input ReactionSystem has algebraic equations. This requires setting `structural_simplify=true` within `ODEProblem` call.")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ANy reason to remove this? structural_simplify is still a mess, but this still seems like a useful error to throw?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the issue with structural simplify? I don't know of one related to Catalyst

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't there the cases where it may or may not simplify things into DAEs. However, depending on whichever variable was reduced to an algebraic equation, the user now have to determine whether its initial condition should go as an initial condition or a guess. And where the user have to explicitly check the simplified system to figure out which ended up being the case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No and no. First of all, that is no issue of structural_simplify, this is just a property of DAEs and index 1 transformations 😅 . So if you're waiting for that to ever change, sorry but it's just the math of DAEs. I'd be happy to hop on a call and explain it since you and @isaacsas keep asking the same question, it's probably just easiest to pull out a whiteboard at this point. But it shouldn't cause any difficulties to the user.

Here's a simple way to understand it. If your DAE is index 1 (which it will be after transformation), then every equation is either a differential equation or an algebraic equation, and every equation is associated through matching to be solving for one variable (this is equivalent to the index 1 condition and not having a singularity in the Jacobian). So with this, any variable can be called either a differential or algebraic variable. You need as many initial conditions as you have algebraic variables, and any variable that doesn't have an initial condition needs a guess. It doesn't matter which one is chosen by the system as differential or algebraic, but it does matter that you have the right number of conditions. If you have more conditions, it throws you a warning because it's generally not a good idea to have an overdetermined system, but it doesn't mean it's impossible to solve. If it's over or underdetermined it will still try to initialize, with many caveats of course.

The simplest way to understand this then is that, every variable needs either an initial condition or a guess. You should probably be making every differential variable have an initial condition, and for every algebraic condition you should be introducing a new variable and give that one a guess.

There is potentially a way to not need guesses if we move beyond Newton methods to more homotopy type solvers, since it's really just a property of Newton that you need a u0, but this'll be years of research and not something to rely on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just commented this out while debugging. I didn't intend to keep it commented out when merging...

@@ -1468,3 +1469,5 @@ let
@observables X2 ~ X1
end
end

nothing
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script was outputting a very long expression to the REPL from one of the tests for some reason.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe move it to the end of the last let ... end block, just to make it clear that it belongs there (at least if that is the block which returns the last output, but I presume that would bet he case?).

@TorkelE
Copy link
Member Author

TorkelE commented Mar 5, 2025

If we want to merge this I am happy with it. Still quite a way to go to update to the latest everything, but not sure if it is possible yet.

@isaacsas
Copy link
Member

isaacsas commented Mar 5, 2025

No, we can keep this open. But it has a lot of fixes for the MTK changes, so we should just push to this PR as we work on tests going forward...

@TorkelE
Copy link
Member Author

TorkelE commented Mar 5, 2025

sounds good, thought from your latest comment that we maybe merge this and then proceed, but happy to continue using this branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants