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

fix: propagate tofloat, use_union to better_varmap_to_vars #3448

Merged
merged 13 commits into from
Mar 19, 2025

Conversation

vyudu
Copy link
Member

@vyudu vyudu commented Mar 7, 2025

Close #3446

@ChrisRackauckas
Copy link
Member

Looks like this is giving some test failures?

@vyudu
Copy link
Member Author

vyudu commented Mar 10, 2025

The test failures seem unrelated

@vyudu
Copy link
Member Author

vyudu commented Mar 14, 2025

I can't reproduce these failures locally

@AayushSabharwal
Copy link
Member

We should only do this propagation for JumpProblems. A union-typed u0 is not valid for ODEs iirc which looks like the cause of this error.

@vyudu
Copy link
Member Author

vyudu commented Mar 14, 2025

Shouldn't it just error if someone passes use_union = true for an ODEProblem then? It doesn't make sense for someone to pass in use_union = true and it just gets ignored right

@vyudu
Copy link
Member Author

vyudu commented Mar 14, 2025

Or should it propagate for the p but not the u0?

@AayushSabharwal
Copy link
Member

Yeah it needs to propagate for the p

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

Is this good to merge?

@isaacsas
Copy link
Member

Is use_union really relevant or needed anymore? Before it was needed to avoid parameters being converted to integers but that is now handled by making them symbolic integers. All jump systems really need is to preserve integer initial conditions as integers, not as a union type, without requiring users to specify the symbolic variables as integers originally.

@ChrisRackauckas
Copy link
Member

Yes we should probably error for any unions. We created the split parameters to handle that, so if we end up with unions anywhere that's a sign something went wrong.

@AayushSabharwal
Copy link
Member

So use_union is removed as a kwarg and defaults to false? Sounds like a nice idea and simplifies some things.

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

I can add that.

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

Actually we'd still need use_union to handle cases like #1561 right?

@AayushSabharwal
Copy link
Member

varmap_to_vars should remain untouched. We don't use it anyway, it's just for backward compat.

@vyudu
Copy link
Member Author

vyudu commented Mar 17, 2025

What should become of the final test here that tests if p has a union eltype?

vars = @variables y(t)=1 dy(t)=0 ddy(t)=0
pars = @parameters a=1.0 b=2.0 c=3
eqs = [D(y) ~ dy * a
D(dy) ~ ddy * b
ddy ~ sin(t) * c]
@named model = ODESystem(eqs, t, vars, pars)
sys = structural_simplify(model; split = false)
tspan = (0.0, t_end)
prob = ODEProblem(sys, [], tspan, []; build_initializeprob = false)
@test prob.p isa Vector{Float64}
sol = solve(prob, ImplicitEuler());
@test sol.retcode == ReturnCode.Success
# ------------------------ Mixed Type Conserved
prob = ODEProblem(
sys, [], tspan, []; tofloat = false, use_union = true, build_initializeprob = false)
@test prob.p isa Vector{Union{Float64, Int64}}

Removing use_union would break it

Copy link
Member

@AayushSabharwal AayushSabharwal left a comment

Choose a reason for hiding this comment

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

Couple minor things, and needs a format

vyudu and others added 7 commits March 18, 2025 11:00

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@ChrisRackauckas ChrisRackauckas merged commit 5691fa3 into SciML:master Mar 19, 2025
38 of 45 checks passed
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.

Jump simulations are Float64 valued
4 participants