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

BoundsError in following mwe #2082

Closed
ArbitRandomUser opened this issue Nov 11, 2024 · 4 comments
Closed

BoundsError in following mwe #2082

ArbitRandomUser opened this issue Nov 11, 2024 · 4 comments

Comments

@ArbitRandomUser
Copy link

ArbitRandomUser commented Nov 11, 2024

using Enzyme
using LinearAlgebra

const Z = [1.0  0.0;
           0.0 -1.0]

const X = [0.0    1.0;
           1          0]

const Δt = 0.5

function getp_at_t(p,t)
    p[min(floor(Int,(t/Δt))+1,length(p))]
end


function dfunc(du,u,p,t)
    amp = p[min(floor(Int,(t/Δt))+1,length(p))]
    mul!(du,Z,u,1.0,0.0)
    mul!(du,X,u,amp,1.0)
    nothing
end


u0 = rand(2)
du0 = zero(u0)
p = rand(10)

der_u0 = make_zero(u0)
der_du0 = make_zero(du0)
der_p = make_zero(p)


autodiff(Reverse,dfunc,Const,Duplicated(du0,der_du0),Duplicated(u0,der_u0),Duplicated(p,der_p),Const(0.1))

gives the output

julia> autodiff(Reverse,dfunc,Const,Duplicated(du0,der_du0),Duplicated(u0,der_u0),Duplicated(p,der_p),Const(0.1))
ERROR: BoundsError: attempt to access 10-element Vector{Float64} at index [1]
Stacktrace:
  [1] getindex
    @ ./essentials.jl:13 [inlined]
  [2] dfunc
    @ ~/complexmwe/mwe.jl:18 [inlined]
  [3] diffejulia_dfunc_1755wrap
    @ ~/complexmwe/mwe.jl:0
  [4] macro expansion
    @ ~/.julia/packages/Enzyme/06ueh/src/compiler.jl:8298 [inlined]
  [5] enzyme_call
    @ ~/.julia/packages/Enzyme/06ueh/src/compiler.jl:7861 [inlined]
  [6] CombinedAdjointThunk
    @ ~/.julia/packages/Enzyme/06ueh/src/compiler.jl:7634 [inlined]
  [7] autodiff
    @ ~/.julia/packages/Enzyme/06ueh/src/Enzyme.jl:491 [inlined]
  [8] autodiff(::ReverseMode{…}, ::typeof(dfunc), ::Type{…}, ::Duplicated{…}, ::Duplicated{…}, ::Duplicated{…}, ::Const{…})
    @ Enzyme ~/.julia/packages/Enzyme/06ueh/src/Enzyme.jl:512
  [9] top-level scope
    @ ~/complexmwe/mwe.jl:34
 [10] eval
    @ ./boot.jl:385 [inlined]
Some type information was truncated. Use `show(err)` to see complete types.

gives same error on 0.12.6 , 0.13.14 .

enzyme 0.12.5 would prompt to enable runtime activity,

@wsmoses
Copy link
Member

wsmoses commented Nov 13, 2024

the culprit is the attributor, naturally

@wsmoses
Copy link
Member

wsmoses commented Nov 13, 2024

some slight reductions:

wmoses@beast:~/git/Enzyme.jl ((HEAD detached at origin/main)) $ cat b.jl 


using Enzyme
using LinearAlgebra

# Enzyme.Compiler.DumpPostWrap[] = true

# Enzyme.Compiler.DumpPostOpt[] = true

const Z = [1.0  0.0;
           0.0 -1.0]

const X = [0.0    1.0;
           1          0]

function dfunc(du,u,p,t)
    amp = p[t]
    mul!(du,Z,u,1.0,0.0)
    mul!(du,X,u,amp,1.0)
    nothing
end


u0 = rand(2)
du0 = zero(u0)
p = rand(10)

der_u0 = make_zero(u0)
der_du0 = make_zero(du0)
der_p = make_zero(p)

@show p, der_p

dfunc(du0, u0, p, 1)

autodiff(Reverse,dfunc,Const,Duplicated(du0,der_du0),Duplicated(u0,der_u0),Duplicated(p,der_p),Const(1))
wmoses@beast:~/git/Enzyme.jl ((HEAD detached at origin/main)) $ 

@wsmoses
Copy link
Member

wsmoses commented Nov 13, 2024

okay we will work arouond this in the next jll bump with this fix: EnzymeAD/Enzyme#2166

@wsmoses
Copy link
Member

wsmoses commented Nov 16, 2024

Fix has landed

@wsmoses wsmoses closed this as completed Nov 16, 2024
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

No branches or pull requests

2 participants