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

Throw an error if structural simplification is applied twice #3027

Merged
merged 6 commits into from
Sep 9, 2024

Conversation

ChrisRackauckas
Copy link
Member

Fixes #3012


@named rc_model = ODESystem(rc_eqs, t; systems)
sys = structural_simplify(rc_model)
@test_throws ModelingToolkit.RepeatedStructuralSimplificationError structural_simplify(sys)
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@test_throws ModelingToolkit.RepeatedStructuralSimplificationError structural_simplify(sys)
@test_throws ModelingToolkit.RepeatedStructuralSimplificationError structural_simplify(sys)

@@ -12,3 +12,6 @@ end
@safetestset "Bareiss" begin
include("bareiss.jl")
end
@safetestset "Errors" begin
include("errors.jl")
end
Copy link
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
end
end

ChrisRackauckas added a commit to SciML/Catalyst.jl that referenced this pull request Sep 8, 2024
This is a bug in the tests that was found by SciML/ModelingToolkit.jl#3027
@ChrisRackauckas
Copy link
Member Author

@YingboMa that failing test... doesn't make much sense?

@ChrisRackauckas
Copy link
Member Author

Since downstreams all seem fine other than test bugs, this is good to go. I'm sure someone will complain about this one, but this is pretty much required in order to make sure no weird hidden bugs show up. Calling a system complete means you have completed the system: if you try to change it after you say you will never change it (i.e. that it's complete), bad things will happen. We have to assume users don't lie about when their system is completed or else we could never optimize things like schedules. So... this error is pretty necessary, and if you were violating it there's issues you could have hit before which is why it was made explicit.

@ChrisRackauckas
Copy link
Member Author

I'll follow up with SBMLToolkit which is over zealous at calling complete in the system construction which is simply invalid: a file reader cannot read the future on what a user wants to do.

@ChrisRackauckas ChrisRackauckas merged commit 2f518c4 into master Sep 9, 2024
25 of 26 checks passed
@ChrisRackauckas ChrisRackauckas deleted the double_ss_error branch September 9, 2024 02:12
@baggepinnen
Copy link
Contributor

I'm sure someone will complain about this one

yes I will, this was quite breaking. Calling complete is required to access variables with the correct name space, and one has to access variables before structural_simplify for things like linearization and generation of dynamics functions with inputs. Why is iscomplete used for this check and not a check that actually determines if structural_simplify has been called?

@ChrisRackauckas
Copy link
Member Author

iscomplete is a flag for whether no more changes will happen to a system. You're literally saying that you are breaking that promise, and there are many things that rely on that promise. Of course you want an error when that happens!

@@ -21,6 +29,7 @@ function structural_simplify(
sys::AbstractSystem, io = nothing; simplify = false, split = true,
allow_symbolic = false, allow_parameter = true, conservative = false, fully_determined = true,
kwargs...)
iscomplete(sys) && throw(RepeatedStructuralSimplificationError())
Copy link
Member

Choose a reason for hiding this comment

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

This is the wrong check and breaking. You should just check the existence of schedule.

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.

repeated application of structural_simplify leads to error
3 participants