-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Functions do not properly redefine with FunctionWrappers in v1.10? #52635
Comments
Umm it went away now. Even more confused, but okay. |
Okay nope, even more confused. You have to run the failing test before running the MWE? using FunctionWrappers, ForwardDiff, OrdinaryDiffEq, Test
const a = Float64[1.0]
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = u[2]
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 1.0)
prob = ODEProblem(lorenz!, u0, tspan)
@test_throws OrdinaryDiffEq.FirstAutodiffJacError solve(prob, Rosenbrock23())
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = t
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
prob = ODEProblem(lorenz!, u0, tspan)
# Throws the wrong error
@test_throws OrdinaryDiffEq.FirstAutodiffTgradError solve(prob, Rosenbrock23())
u = [1.0; 0.0; 0.0]
du = copy(u)
t = 0.0
dualgen(::Type{T}) where {T} = ForwardDiff.Dual{ForwardDiff.Tag{DiffEqBase.OrdinaryDiffEqTag, T}, T, 1}
T = Float64
T1 = Float64
dualT = dualgen(T)
# Version 1
R = Nothing
A = Tuple{Vector{dualgen(T)}, Vector{dualgen(T)}, SciMLBase.NullParameters, Float64}
ff = FunctionWrappers.FunctionWrapper{R, A}(SciMLBase.Void(lorenz!))
ff(du,u,SciMLBase.NullParameters(),t) If you omit the test runs before it, it will not error. |
using FunctionWrappers, ForwardDiff, OrdinaryDiffEq, Test
const a = Float64[1.0]
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = u[2]
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = t
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = [1.0; 0.0; 0.0]
tspan = (0.0,1.0)
prob = ODEProblem(lorenz!, u0, tspan)
# Throws the wrong error
@test_throws OrdinaryDiffEq.FirstAutodiffTgradError solve(prob, Rosenbrock23()) This throws the right error and the subsequent call works fine, but the following does not: using FunctionWrappers, ForwardDiff, OrdinaryDiffEq, Test
const a = Float64[1.0]
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = u[2]
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = [1.0; 0.0; 0.0]
tspan = (0.0, 1.0)
prob = ODEProblem(lorenz!, u0, tspan)
@test_throws OrdinaryDiffEq.FirstAutodiffJacError solve(prob, Rosenbrock23())
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
a[1] = t
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
u0 = [1.0; 0.0; 0.0]
tspan = (0.0,1.0)
prob = ODEProblem(lorenz!, u0, tspan)
# Throws the wrong error
@test_throws OrdinaryDiffEq.FirstAutodiffTgradError solve(prob, Rosenbrock23()) and the subsequent call errors like in the OP. I think what this is suggesting is that function re-definition #265 stuff with FunctionWrappers somehow broke. It requires that the internal function wrapper with |
Sounds like a FunctionWrappers issue then? I don't think it ever gained full correct support for #265 |
It wasn't miscompiling on v1.9. You can see from our AD and ModelingToolkit downstream tests here https://github.com/SciML/OrdinaryDiffEq.jl/actions/runs/7333458887/job/19968912271?pr=2093 that it's a v1.10 only issue and not v1.9. I'm not sure if that requires a fix here or in FunctionWrappers.jl but this is the kind of issue I'd like to find a way to patch ASAP. |
Perhaps related to the issue JuliaLang/FunctionWrappers.jl#30 ?
|
I have also been writing a code that sometimes had the same error with a cfunction, but now reproducibly segfaults for me, like so
So far I've narrowed it down to redefining a function contained in a mutable struct that gets wrapped with a FunctionWrapper, |
I was able to reduce my segfault to the following, which I seem to trigger reliably with
Which crashes with
In a simpler example, I also noticed an incorrect result without a crash
I don't get either error using v1.6.7, so this is probably due to 1.10, as mentioned above, and most likely not due to FunctionWrappers.jl? P.S. Before simplifying to this segfault and correctness error, I had seen a variety of cryptic error messages, including the OP's |
I don't quite understand what's going on here so it's a bit hard to title it. I found it in a test regression in OrdinaryDiffEq.jl SciML/OrdinaryDiffEq.jl#2093 which started giving the wrong error. Seems innocuous, but digging in made it weirder. The MWE I cam up with is:
Which gives:
And you might go, that's not an MWE! Delete stuff. Well... deleting stuff and replacing it with the same thing... is fine. Here's the definition of
Void
: https://github.com/SciML/SciMLBase.jl/blob/v2.11.7/src/utils.jl#L477-L483 . Let's just remove a bit of package code by copy pasting that into the MWE:Tada! That works fine. What about getting rid of SciMLBase.NullParameters, that's just a singleton so what about
nothing
:That works fine too!
So it seems this exact combination of arguments, and only using the version of things in the precompiled (?) package, causes the error. And I don't know what this error really is. It's a v1.10 only issue, so I'm posting here though it's also maybe FunctionWrappers.jl related?
The text was updated successfully, but these errors were encountered: