Repository navigation
[v2-backport] Fix integer time-step indexing under AD (#1325) - #1328
Merged
ChrisRackauckas merged 1 commit intoApr 24, 2026
Merged
ChrisRackauckas merged 1 commit into
ChrisRackauckas merged 1 commit into
Conversation
The broad `rrule!!(::CoDual{typeof(getindex)}, ::CoDual{<:AbstractTimeseriesSolution}, ::CoDual)`
in the Mooncake extension (and the analogous `rrule` in the ChainRulesCore
extension) caught `sol[i::Integer]` and mis-treated `i` as a state-variable
index, producing a `BoundsError` when the number of time steps exceeded the
state size (the path exercised by `for i in eachindex(sol)` loops).
Add dedicated, more-specific methods for the `Integer` argument that
correctly scatter the output cotangent into the i-th time step. Julia's
dispatch picks these over the broad symbolic methods for integer inputs,
leaving the symbolic path (`sol[sym]`) unchanged. On this v2 backport the
Zygote extension still carries the pre-v3 `::Int` adjoint, so no Zygote
changes are needed here.
Regression test mirrors the reported MWE.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Co-Authored-By: Chris Rackauckas <[email protected]>
This was referenced Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BoundsErrorunder Mooncake when iteratingeachindex(sol)and indexingsol[i], reported against v2.155.0 in 2.155 breaks Mooncake when iterating overODESolution#1325.@adjoint Base.getindex(VA::ODESolution, i::Int)that was removed on v3 is still present here and already handles the time-step case correctly.Issue: #1325
Companion: #1327
Verification
BoundsError: attempt to access 2-element Vector{Float64} at index [101]on unpatched v2.155.0 (exact MWE from 2.155 breaks Mooncake when iterating overODESolution#1325).[8.304244028181515, -159.48401961551903, 75.20316229897975, -339.1951631373029].runicformat-check clean.🤖 Generated with Claude Code