-
-
Notifications
You must be signed in to change notification settings - Fork 82
Fix indexing deprecation warning #1248
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
Conversation
(And here by work I mean not cause issues due to the deprecation warning.) |
Yes, it's just lowering to something that is deprecated. It should lower to |
Turning depwarns into errors I just get:
which doesn't seem helpful. I guess because the issue is really in Xv .+= sol(times; idxs = 1) (Note that wrapping with an |
I think to get a useful stacktrace you may just need to set that to actually |
What's your reproducer? using RecursiveArrayTools
Base.getindex(A::RecursiveArrayTools.AbstractVectorOfArray, I::Int) = error()
using OrdinaryDiffEq
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
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, 100.0)
prob = ODEProblem(lorenz!, u0, tspan)
sol = solve(prob, Tsit5())
sol([1,2,3], idxs = 1) seems to work fine. |
I'll try to reduce the test that is giving the warning down to a MWE when I have a chance. Have some deadlines currently so don't really have time to explore this currently. |
Start Julia with using Catalyst, OrdinaryDiffEqTsit5
rn = @reaction_network begin
β, X --> 0
β, Y --> 0
α, 0 --> Y
(α * (1 + Y)), 0 --> X
end
p = (α = 6.0, β = 2.0, X₀ = 2.0, Y₀ = 1.0)
u0map = [:X => p.X₀, :Y => p.Y₀]
pmap = [:α => p.α, :β => p.β]
tspan = (0.0, 20.0)
oprob = ODEProblem(rn, u0map, tspan, pmap)
sol = solve(oprob, Tsit5())
times = range(0.0, tspan[2], length = 100)
Xv = zeros(length(times))
s = sol(times, idxs = 1)
Xv .+= s gives
|
The function definition you are changing doesn't seem to get called? |
This seems to be the right deprecation to redefine: julia> Base.getindex(A::AbstractDiffEqArray, i::Int) = error()
julia> Xv .+= s
ERROR:
Stacktrace:
[1] error()
@ Base ./error.jl:44
[2] getindex(A::DiffEqArray{Float64, 1, Vector{…}, StepRangeLen{…}, MTKParameters{…}, ODESolution{…}, Nothing}, i::Int64)
@ Main ./REPL[34]:1
[3] _broadcast_getindex
@ ./broadcast.jl:631 [inlined]
[4] _getindex
@ ./broadcast.jl:675 [inlined]
[5] _getindex
@ ./broadcast.jl:674 [inlined]
[6] _broadcast_getindex
@ ./broadcast.jl:650 [inlined]
[7] getindex
@ ./broadcast.jl:610 [inlined]
[8] macro expansion
@ ./broadcast.jl:973 [inlined]
[9] macro expansion
@ ./simdloop.jl:77 [inlined]
[10] copyto!
@ ./broadcast.jl:972 [inlined]
[11] copyto!
@ ./broadcast.jl:925 [inlined]
[12] materialize!
@ ./broadcast.jl:883 [inlined]
[13] materialize!(dest::Vector{…}, bc::Base.Broadcast.Broadcasted{…})
@ Base.Broadcast ./broadcast.jl:880
[14] top-level scope
@ REPL[35]:1
Some type information was truncated. Use `show(err)` to see complete types. |
Oh yes, that's because the return of the interpolation is a DiffEqArray. using Catalyst, OrdinaryDiffEqTsit5
using RecursiveArrayTools
Base.getindex(A::AbstractDiffEqArray, i::Int) = error()
rn = @reaction_network begin
β, X --> 0
β, Y --> 0
α, 0 --> Y
(α * (1 + Y)), 0 --> X
end
p = (α = 6.0, β = 2.0, X₀ = 2.0, Y₀ = 1.0)
u0map = [:X => p.X₀, :Y => p.Y₀]
pmap = [:α => p.α, :β => p.β]
tspan = (0.0, 20.0)
oprob = ODEProblem(rn, u0map, tspan, pmap)
sol = solve(oprob, Tsit5())
times = range(0.0, tspan[2], length = 100)
Xv = zeros(length(times))
s = sol(times, idxs = 1)
Xv .+= s.u Though actually this is the one case that will actually work post deprecation because the linear index is already correct. I'm not sure if we can signal that better somehow. |
The docs on solution manipulating at https://docs.sciml.ai/DiffEqDocs/stable/basics/solution/#Interpolations-and-Calculating-Derivatives would probably benefit from more fully explaining what is being returned and how to use it in calculations. |
Noticed in SciML/Catalyst.jl#1248, the linear indexing is actually fine when done on scalar arrays because that matches the linear indexing that you get from an AbstractArray interface. So instead the deprecations are made more precise to be just about the array of array case.
Based on comments from SciML/Catalyst.jl#1248
Alright, I took a moment to more properly spell out the interface and update some of the old docs on this. Hopefully this clarifies it. Though @AayushSabharwal you should follow up with some additions to the DiffEqArray interface on discretes definitions and symbolic indexing. |
Thanks, that should be helpful to users (and me!). |
Hopefully this fixes the timeout for the prerelease hybrid tests.
@ChrisRackauckas should doing stuff like
some_vector .+= sol(times; idxs = :X)
causing the following message:It seems like this is something that should work?