Skip to content

Conversation

isaacsas
Copy link
Member

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:

┌ Warning: `Base.getindex(A::AbstractDiffEqArray, i::Int)` is deprecated, use `Base.getindex(A, :, i)` instead.
│   caller = _broadcast_getindex at broadcast.jl:652 [inlined]

It seems like this is something that should work?

@isaacsas
Copy link
Member Author

(And here by work I mean not cause issues due to the deprecation warning.)

@ChrisRackauckas
Copy link
Member

ChrisRackauckas commented Apr 23, 2025

Yes, it's just lowering to something that is deprecated. It should lower to sol.u[i], it sounds like it's lowering to sol[i]. To figure out where it's doing this, make the depwarn an error (can just Revise https://github.com/SciML/RecursiveArrayTools.jl/blob/master/src/vector_of_array.jl#L405) and then we can probably find the spot in SII to patch.

@isaacsas
Copy link
Member Author

Turning depwarns into errors I just get:

ERROR: `Base.getindex(A::AbstractDiffEqArray, i::Int)` is deprecated, use `Base.getindex(A, :, i)` instead.
Stacktrace:
  [1] _depwarn(msg::Any, funcsym::Any, force::Bool)
    @ Base ./deprecated.jl:152
  [2] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
  [3] invokelatest
    @ ./essentials.jl:1052 [inlined]
  [4] #depwarn#1188
    @ ./deprecated.jl:146 [inlined]
  [5] depwarn
    @ ./deprecated.jl:141 [inlined]
  [6] getindex(A::RecursiveArrayTools.DiffEqArray{…}, i::Int64)
    @ RecursiveArrayTools ./deprecated.jl:104
  [7] _broadcast_getindex
    @ ./broadcast.jl:631 [inlined]
  [8] _getindex
    @ ./broadcast.jl:675 [inlined]
  [9] _getindex
    @ ./broadcast.jl:674 [inlined]
 [10] _broadcast_getindex
    @ ./broadcast.jl:650 [inlined]
 [11] getindex
    @ ./broadcast.jl:610 [inlined]
 [12] macro expansion
    @ ./broadcast.jl:973 [inlined]
 [13] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [14] copyto!
    @ ./broadcast.jl:972 [inlined]
 [15] copyto!
    @ ./broadcast.jl:925 [inlined]
 [16] materialize!
    @ ./broadcast.jl:883 [inlined]
 [17] materialize!(dest::Vector{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:880
 [18] top-level scope
    @ REPL[28]:1
Some type information was truncated. Use `show(err)` to see complete types.

which doesn't seem helpful. I guess because the issue is really in sol(times; idxs = :X) generating the wrong object. But I'd note that the same issue arises even without symbolic indexing, i.e. I get the same error and stacktrace doing:

Xv .+= sol(times; idxs = 1)

(Note that wrapping with an Array fixes this.)

@ChrisRackauckas
Copy link
Member

I think to get a useful stacktrace you may just need to set that to actually error().

@ChrisRackauckas
Copy link
Member

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.

@isaacsas isaacsas merged commit 49e7bbd into master Apr 23, 2025
16 checks passed
@isaacsas isaacsas deleted the fix_deprec_warn branch April 23, 2025 18:50
@isaacsas
Copy link
Member Author

isaacsas commented Apr 23, 2025

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.

@isaacsas
Copy link
Member Author

Start Julia with depwarn=error,

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

ERROR: `Base.getindex(A::AbstractDiffEqArray, i::Int)` is deprecated, use `Base.getindex(A, :, i)` instead.
Stacktrace:
  [1] _depwarn(msg::Any, funcsym::Any, force::Bool)
    @ Base ./deprecated.jl:152
  [2] #invokelatest#2
    @ ./essentials.jl:1055 [inlined]
  [3] invokelatest
    @ ./essentials.jl:1052 [inlined]
  [4] #depwarn#1188
    @ ./deprecated.jl:146 [inlined]
  [5] depwarn
    @ ./deprecated.jl:141 [inlined]
  [6] getindex(A::RecursiveArrayTools.DiffEqArray{…}, i::Int64)
    @ RecursiveArrayTools ./deprecated.jl:104
  [7] _broadcast_getindex
    @ ./broadcast.jl:631 [inlined]
  [8] _getindex
    @ ./broadcast.jl:675 [inlined]
  [9] _getindex
    @ ./broadcast.jl:674 [inlined]
 [10] _broadcast_getindex
    @ ./broadcast.jl:650 [inlined]
 [11] getindex
    @ ./broadcast.jl:610 [inlined]
 [12] macro expansion
    @ ./broadcast.jl:973 [inlined]
 [13] macro expansion
    @ ./simdloop.jl:77 [inlined]
 [14] copyto!
    @ ./broadcast.jl:972 [inlined]
 [15] copyto!
    @ ./broadcast.jl:925 [inlined]
 [16] materialize!
    @ ./broadcast.jl:883 [inlined]
 [17] materialize!(dest::Vector{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:880
 [18] top-level scope
    @ REPL[17]:1
Some type information was truncated. Use `show(err)` to see complete types.

@isaacsas
Copy link
Member Author

The function definition you are changing doesn't seem to get called?

@isaacsas
Copy link
Member Author

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.

@ChrisRackauckas
Copy link
Member

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.

@isaacsas
Copy link
Member Author

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.

ChrisRackauckas added a commit to SciML/RecursiveArrayTools.jl that referenced this pull request Apr 24, 2025
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.
ChrisRackauckas added a commit to SciML/DiffEqDocs.jl that referenced this pull request Apr 24, 2025
@ChrisRackauckas
Copy link
Member

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.

@isaacsas
Copy link
Member Author

Thanks, that should be helpful to users (and me!).

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.

2 participants