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

Inactive declaration ignored #2016

Closed
ChrisRackauckas opened this issue Oct 28, 2024 · 18 comments
Closed

Inactive declaration ignored #2016

ChrisRackauckas opened this issue Oct 28, 2024 · 18 comments

Comments

@ChrisRackauckas
Copy link
Contributor

MWE:

using OrdinaryDiffEq, Enzyme, StaticArrays

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

const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]

function f(y::Array{Float64}, u0::Array{Float64})
    tspan = (0.0, 3.0)
    prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
    sol = DiffEqBase.solve(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
    y .= sol[1,:]
    return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y  = zeros(13)
dy = zeros(13)

Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));

gives:

cannot handle unknown binary operator:   %97 = add i64 %96, 1, !dbg !371


Stacktrace:
 [1] +
   @ ./int.jl:87
 [2] increment_accept!
   @ ~/.julia/packages/OrdinaryDiffEqCore/qpjip/src/integrators/integrator_utils.jl:274
 [3] _loopfooter!
   @ ~/.julia/packages/OrdinaryDiffEqCore/qpjip/src/integrators/integrator_utils.jl:234


Stacktrace:
  [1] _postamble!
    @ ~/.julia/packages/OrdinaryDiffEqCore/qpjip/src/integrators/integrator_utils.jl:154
  [2] loopfooter!
    @ ~/.julia/packages/OrdinaryDiffEqCore/qpjip/src/integrators/integrator_utils.jl:207 [inlined]
  [3] solve!
    @ ~/.julia/packages/OrdinaryDiffEqCore/qpjip/src/solve.jl:555
  [4] #get_concrete_problem#69
    @ ~/.julia/packages/DiffEqBase/frOsk/src/solve.jl:1187 [inlined]
  [5] get_concrete_problem
    @ ~/.julia/packages/DiffEqBase/frOsk/src/solve.jl:1179 [inlined]
  [6] #solve_up#53
    @ ~/.julia/packages/DiffEqBase/frOsk/src/solve.jl:1086
  [7] solve_up
    @ ~/.julia/packages/DiffEqBase/frOsk/src/solve.jl:1078 [inlined]
  [8] #solve#51
    @ ~/.julia/packages/DiffEqBase/frOsk/src/solve.jl:1015 [inlined]
  [9] solve
    @ ~/.julia/packages/DiffEqBase/frOsk/src/solve.jl:1005 [inlined]
 [10] f
    @ ./REPL[9]:4 [inlined]
 [11] diffejulia_f_6507wrap
    @ ./REPL[9]:0
 [12] macro expansion
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:8137 [inlined]
 [13] enzyme_call
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:7703 [inlined]
 [14] CombinedAdjointThunk
    @ ~/.julia/packages/Enzyme/BRtTP/src/compiler.jl:7476 [inlined]
 [15] autodiff
    @ ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:491 [inlined]
 [16] autodiff
    @ ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:537 [inlined]
 [17] autodiff(::ReverseMode{…}, ::typeof(f), ::Duplicated{…}, ::Duplicated{…})
    @ Enzyme ~/.julia/packages/Enzyme/BRtTP/src/Enzyme.jl:504
 [18] top-level scope
    @ REPL[14]:1
Some type information was truncated. Use `show(err)` to see complete types.

but that function is already marked as inactive

function EnzymeCore.EnzymeRules.inactive_noinl(
        ::typeof(OrdinaryDiffEqCore.increment_accept!), args...)
    true
end

Full stack trace: enzyme.txt

@ChrisRackauckas
Copy link
Contributor Author

Note that this should be the final stage of SciML/OrdinaryDiffEq.jl#2282

@wsmoses
Copy link
Member

wsmoses commented Oct 28, 2024

Are you able to reduce this to a MWE without the sciml stack as dependencies?

The fact that the type isn't deduced is odd and we should be able to fix it where the inactive isn't needed at all (but requires debugging on a simpler example)

@ChrisRackauckas
Copy link
Contributor Author

I don't know how to reduce this. It's the same thing as what was originally #1636 . In Enzyme v0.12 I just worked around it by moving the pieces that were weird out to a function an inactiviting them, though I could never isolate why it acted so weird there.

@wsmoses
Copy link
Member

wsmoses commented Oct 30, 2024

I mean worst case you can splat in the defn's of all functions/structs in the imported packages used in the above and try to delete some of the struct elements

@ChrisRackauckas
Copy link
Contributor Author

I now get a segfault on main:

julia> Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));
{[0]:Pointer, [0,-1]:Float@double, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Integer, [17]:Integer, [18]:Integer, [19]:Integer, [20]:Integer, [21]:Integer, [22]:Integer, [23]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer}
 canonicalizing 8
Assertion failed: ((size_t)pair.first[0] < len), function CanonicalizeInPlace, file /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h, line 700.

[6731] signal (6): Abort trap: 6
in expression starting at REPL[9]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 81945743 (Pool: 81832412; Big: 113331); GC: 78

@wsmoses
Copy link
Member

wsmoses commented Nov 3, 2024

**** assertion error

In any case can you minimize and post the whole error log?

@ChrisRackauckas
Copy link
Contributor Author

That is the whole error log:

chrisrackauckas@Chriss-MBP-2 ~ % julia
The latest version of Julia in the `release` channel is 1.11.1+0.aarch64.apple.darwin14. You currently have `1.10.5+0.aarch64.apple.darwin14` installed. Run:

  juliaup update

in your terminal shell to install Julia 1.11.1+0.aarch64.apple.darwin14 and update the `release` channel to that version.
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.5 (2024-08-27)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using OrdinaryDiffEq, Enzyme, StaticArrays

julia> 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
lorenz! (generic function with 1 method)

julia> const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
13-element SVector{13, Float64} with indices SOneTo(13):
 0.0
 0.25
 0.5
 0.75
 1.0
 1.25
 1.5
 1.75
 2.0
 2.25
 2.5
 2.75
 3.0

julia> function f(y::Array{Float64}, u0::Array{Float64})
           tspan = (0.0, 3.0)
           prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
           sol = DiffEqBase.__solve(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
           y .= sol[1,:]
           return nothing
       end;

julia> u0 = [1.0; 0.0; 0.0]
3-element Vector{Float64}:
 1.0
 0.0
 0.0

julia> d_u0 = zeros(3)
3-element Vector{Float64}:
 0.0
 0.0
 0.0

julia> y  = zeros(13)
13-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> dy = zeros(13)
13-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));
{[0]:Pointer, [0,-1]:Float@double, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Integer, [17]:Integer, [18]:Integer, [19]:Integer, [20]:Integer, [21]:Integer, [22]:Integer, [23]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer}
 canonicalizing 8
Assertion failed: ((size_t)pair.first[0] < len), function CanonicalizeInPlace, file /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h, line 700.

[70031] signal (6): Abort trap: 6
in expression starting at REPL[9]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 82119436 (Pool: 81991411; Big: 128025); GC: 59
zsh: abort      julia

@ChrisRackauckas
Copy link
Contributor Author

ChrisRackauckas commented Nov 4, 2024

Note this is as minimal as I've been able to get it. Removing the big OrdinaryDiffEq type and using SimpleDiffEq makes it go away:

using SimpleDiffEq, Enzyme, StaticArrays

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

const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]

function f(y::Array{Float64}, u0::Array{Float64})
    tspan = (0.0, 3.0)
    prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
    sol = DiffEqBase.solve(prob, SimpleATsit5())
    y .= sol[1,1:13]
    return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y  = zeros(13)
dy = zeros(13)

Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0)); #works fine

@ChrisRackauckas
Copy link
Contributor Author

There is one small minimization here, which is that I can trigger the segfault by just building the integrator:

using OrdinaryDiffEq, Enzyme, StaticArrays

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

const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]

function f(y::Array{Float64}, u0::Array{Float64})
    tspan = (0.0, 3.0)
    prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
    integ = DiffEqBase.__init(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
    y[1:3] .= integ.u
    return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y  = zeros(13)
dy = zeros(13)

Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));

Which means I don't need to run the stepping to trigger it.

@ChrisRackauckas
Copy link
Contributor Author

Note I just saw this same segfault mysteriously show up in a completely unrelated test failure. This issue is all about direct differentiation, but it looks like this adjoint rule is seeing something similar after the last patch:

https://github.com/SciML/SciMLSensitivity.jl/actions/runs/11662003401/job/32467464814?pr=1128#step:6:1339

@ChrisRackauckas
Copy link
Contributor Author

{[0]:Pointer, [0,-1]:Float@double, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Integer, [17]:Integer, [18]:Integer, [19]:Integer, [20]:Integer, [21]:Integer, [22]:Integer, [23]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer}
 canonicalizing 8
julia: /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h:700: void TypeTree::CanonicalizeInPlace(size_t, const llvm::DataLayout&): Assertion `(size_t)pair.first[0] < len' failed.

[3665] signal (6.-6): Aborted
in expression starting at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/alternative_ad_frontend.jl:19
pthread_kill at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
raise at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f254042871a)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
CanonicalizeInPlace at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h:700
updateAnalysis at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:1095
considerTBAA at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:1229
analyzeFunction at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:5925
CreateFromClone at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:4345
CreateAugmentedPrimal at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:2277
EnzymeCreateAugmentedPrimal at /workspace/srcdir/Enzyme/enzyme/Enzyme/CApi.cpp:667
EnzymeCreateAugmentedPrimal at /home/runner/.julia/packages/Enzyme/VSRgT/src/api.jl:389
unknown function (ip: 0x7f24d51bd4e8)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
enzyme! at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:3949
unknown function (ip: 0x7f24d51bb928)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
#codegen#19016 at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:7156
codegen at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:5972 [inlined]
_thunk at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8267
_thunk at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8267 [inlined]
cached_compilation at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8308 [inlined]
thunkbase at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8440
unknown function (ip: 0x7f24d51a5c19)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
#s2080#19075 at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8577 [inlined]
#s2080#19075 at ./none:0
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
GeneratedFunctionStub at ./boot.jl:602
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_call_staged at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/method.c:540
ijl_code_for_staged at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/method.c:593
get_staged at ./compiler/utilities.jl:123
retrieve_code_info at ./compiler/utilities.jl:135 [inlined]
InferenceState at ./compiler/inferencestate.jl:430
typeinf_edge at ./compiler/typeinfer.jl:920
abstract_call_method at ./compiler/abstractinterpretation.jl:629
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:95
abstract_call_known at ./compiler/abstractinterpretation.jl:2087
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_call at ./compiler/abstractinterpretation.jl:2162
abstract_call at ./compiler/abstractinterpretation.jl:2354
abstract_eval_call at ./compiler/abstractinterpretation.jl:2370
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2380
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2624
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2913
typeinf_local at ./compiler/abstractinterpretation.jl:3098
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3186
_typeinf at ./compiler/typeinfer.jl:247
typeinf at ./compiler/typeinfer.jl:216
typeinf_ext at ./compiler/typeinfer.jl:1051
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1082
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1078
jfptr_typeinf_ext_toplevel_35741.1 at /opt/hostedtoolcache/julia/1.10.6/x64/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
jl_type_infer at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:394
jl_generate_fptr_impl at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jitlayers.cpp:504
jl_compile_method_internal at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2481 [inlined]
jl_compile_method_internal at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2368
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2887 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
mapreduce at /home/runner/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:802 [inlined]
#sum#41 at /home/runner/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:753 [inlined]
sum at /home/runner/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:752 [inlined]
#sum#40 at /home/runner/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:751 [inlined]
sum at /home/runner/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:751 [inlined]
senseloss0 at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/alternative_ad_frontend.jl:14 [inlined]
senseloss0 at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/alternative_ad_frontend.jl:0 [inlined]
diffejulia_senseloss0_35363_inner_1wrap at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/alternative_ad_frontend.jl:0
macro expansion at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8197 [inlined]
enzyme_call at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:7760 [inlined]
CombinedAdjointThunk at /home/runner/.julia/packages/Enzyme/VSRgT/src/compiler.jl:7533 [inlined]
autodiff at /home/runner/.julia/packages/Enzyme/VSRgT/src/Enzyme.jl:491 [inlined]
autodiff at /home/runner/.julia/packages/Enzyme/VSRgT/src/Enzyme.jl:512
unknown function (ip: 0x7f24d5192e71)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
do_call at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:126
eval_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:617
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:775
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:934
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:877
ijl_toplevel_eval_in at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:985
eval at ./boot.jl:385 [inlined]
include_string at ./loading.jl:2076
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
_include at ./loading.jl:2136
include at ./Base.jl:495
unknown function (ip: 0x7f24f7b17979)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
jl_f__call_latest at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/builtins.c:812
include at /home/runner/.julia/packages/SafeTestsets/raUNr/src/SafeTestsets.jl:28
unknown function (ip: 0x7f24dea03ad5)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
do_call at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:126
eval_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:617
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:544
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:544
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:775
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:934
jl_eval_module_expr at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:215 [inlined]
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:736
ijl_toplevel_eval_in at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:985
eval at ./boot.jl:385
jfptr_eval_25817.1 at /opt/hostedtoolcache/julia/1.10.6/x64/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
macro expansion at /home/runner/.julia/packages/SafeTestsets/raUNr/src/SafeTestsets.jl:28 [inlined]
macro expansion at ./timing.jl:279 [inlined]
macro expansion at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/runtests.jl:71 [inlined]
macro expansion at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
macro expansion at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/runtests.jl:68 [inlined]
macro expansion at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/usr/share/julia/stdlib/v1.10/Test/src/Test.jl:1577 [inlined]
macro expansion at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/runtests.jl:13 [inlined]
macro expansion at ./timing.jl:279 [inlined]
top-level scope at /home/runner/work/SciMLSensitivity.jl/SciMLSensitivity.jl/test/runtests.jl:269
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:925
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:877
ijl_toplevel_eval_in at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:985
eval at ./boot.jl:385 [inlined]
include_string at ./loading.jl:2076
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
_include at ./loading.jl:2136
include at ./client.jl:494
unknown function (ip: 0x7f253f47f275)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
do_call at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:126
eval_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:617
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:775
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:934
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:877
ijl_toplevel_eval_in at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:985
eval at ./boot.jl:385 [inlined]
exec_options at ./client.jl:296
_start at ./client.jl:557
jfptr__start_82944.1 at /opt/hostedtoolcache/julia/1.10.6/x64/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
true_main at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jlapi.c:582
jl_repl_entrypoint at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jlapi.c:731
main at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/cli/loader_exe.c:58
unknown function (ip: 0x7f2540429d8f)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 455951792 (Pool: 455460687; Big: 491105); GC: 287
Package SciMLSensitivity errored during testing (received signal: 6)
Error: Process completed with exit code 1.

@ChrisRackauckas
Copy link
Contributor Author

Note I can confirm that the comment element of the prob construction is fine though:

using OrdinaryDiffEq, Enzyme, StaticArrays

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

const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]

function f(y::Array{Float64}, u0::Array{Float64})
    tspan = (0.0, 3.0)
    prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
    y[1:3] .= prob.u0
    return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y  = zeros(13)
dy = zeros(13)

Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0)); # is successful

which means that Enzyme is only having difficulty when it's hitting the OrdinaryDiffEq integrator type.

@wsmoses
Copy link
Member

wsmoses commented Nov 6, 2024

should be fixed on main

@ChrisRackauckas
Copy link
Contributor Author

On main I get a new error:

julia> Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));
ERROR: 
No augmented forward pass found for jl_genericmemory_copyto
 at context:   call void @jl_genericmemory_copyto({} addrspace(10)* nonnull %26, i64 %39, {} addrspace(10)* %283, i64 %292, i64 %23) #308, !dbg !586

Stacktrace:
 [1] unsafe_copyto!
   @ ./genericmemory.jl:117
 [2] unsafe_copyto!
   @ ./array.jl:284
 [3] getindex
   @ ./array.jl:941
 [4] _getindex
   @ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:335
 [5] getindex
   @ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:404
 [6] f
   @ ./REPL[4]:5


Stacktrace:
  [1] unsafe_copyto!
    @ ./genericmemory.jl:117 [inlined]
  [2] unsafe_copyto!
    @ ./array.jl:284 [inlined]
  [3] getindex
    @ ./array.jl:941 [inlined]
  [4] _getindex
    @ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:335 [inlined]
  [5] getindex
    @ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:404 [inlined]
  [6] f
    @ ./REPL[4]:5 [inlined]
  [7] diffejulia_f_20621wrap
    @ ./REPL[4]:0
  [8] macro expansion
    @ ~/.julia/packages/Enzyme/RvNgp/src/compiler.jl:8305 [inlined]
  [9] enzyme_call
    @ ~/.julia/packages/Enzyme/RvNgp/src/compiler.jl:7868 [inlined]
 [10] CombinedAdjointThunk
    @ ~/.julia/packages/Enzyme/RvNgp/src/compiler.jl:7641 [inlined]
 [11] autodiff
    @ ~/.julia/packages/Enzyme/RvNgp/src/Enzyme.jl:491 [inlined]
 [12] autodiff
    @ ~/.julia/packages/Enzyme/RvNgp/src/Enzyme.jl:537 [inlined]
 [13] autodiff(::ReverseMode{…}, ::typeof(f), ::Duplicated{…}, ::Duplicated{…})
    @ Enzyme ~/.julia/packages/Enzyme/RvNgp/src/Enzyme.jl:504
 [14] top-level scope
    @ REPL[9]:1
Some type information was truncated. Use `show(err)` to see complete types.

@wsmoses
Copy link
Member

wsmoses commented Nov 8, 2024

This is a distinct issue from above [which is resolved on main, and confirmed on 1.10]. Can you open a new issue for the jl_genericmemory_copyto

@wsmoses wsmoses closed this as completed Nov 8, 2024
@ChrisRackauckas
Copy link
Contributor Author

Are you sure this is fixed? This is what I get on master:

chrisrackauckas@Chriss-MBP-2 ~ % julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.6 (2024-10-28)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
  [7da242da] Enzyme v0.13.13 `https://github.com/EnzymeAD/Enzyme.jl.git#main`
  [f151be2c] EnzymeCore v0.8.6 `https://github.com/EnzymeAD/Enzyme.jl.git:lib/EnzymeCore#main`
  [98e50ef6] JuliaFormatter v1.0.62
  [1dea7af3] OrdinaryDiffEq v6.89.0
  [4722fa14] PkgAuthentication v2.0.3
  [90137ffa] StaticArrays v1.9.8

julia> using OrdinaryDiffEq, Enzyme, StaticArrays

julia> 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
lorenz! (generic function with 1 method)

julia> const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
13-element SVector{13, Float64} with indices SOneTo(13):
 0.0
 0.25
 0.5
 0.75
 1.0
 1.25
 1.5
 1.75
 2.0
 2.25
 2.5
 2.75
 3.0

julia> function f(y::Array{Float64}, u0::Array{Float64})
           tspan = (0.0, 3.0)
           prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
           sol = DiffEqBase.solve(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
           y .= sol[1,:]
           return nothing
       end;

julia> u0 = [1.0; 0.0; 0.0]
3-element Vector{Float64}:
 1.0
 0.0
 0.0

julia> d_u0 = zeros(3)
3-element Vector{Float64}:
 0.0
 0.0
 0.0

julia> y  = zeros(13)
13-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> dy = zeros(13)
13-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));
{[0]:Pointer, [0,-1]:Float@double, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Integer, [17]:Integer, [18]:Integer, [19]:Integer, [20]:Integer, [21]:Integer, [22]:Integer, [23]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer}
 canonicalizing 8
Assertion failed: ((size_t)pair.first[0] < len), function CanonicalizeInPlace, file /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h, line 700.

[56101] signal (6): Abort trap: 6
in expression starting at REPL[10]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 85708382 (Pool: 85577671; Big: 130711); GC: 55
zsh: abort      julia

@wsmoses
Copy link
Member

wsmoses commented Nov 13, 2024

julia> using OrdinaryDiffEq, Enzyme, StaticArrays


julia> 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
lorenz! (generic function with 1 method)

julia> const _saveat =  SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
13-element SVector{13, Float64} with indices SOneTo(13):
 0.0
 0.25
 0.5
 0.75
 1.0
 1.25
 1.5
 1.75
 2.0
 2.25
 2.5
 2.75
 3.0

julia> function f(y::Array{Float64}, u0::Array{Float64})
           tspan = (0.0, 3.0)
           prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
           sol = DiffEqBase.solve(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
           y .= sol[1,:]
           return nothing
       end;

julia> u0 = [1.0; 0.0; 0.0]
3-element Vector{Float64}:
 1.0
 0.0
 0.0

julia> d_u0 = zeros(3)
3-element Vector{Float64}:
 0.0
 0.0
 0.0

julia> y  = zeros(13)
13-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> dy = zeros(13)
13-element Vector{Float64}:
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0
 0.0

julia> Enzyme.autodiff(Reverse, f,  Duplicated(y, dy), Duplicated(u0, d_u0));


┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in   %48 = load {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %47, align 8, !dbg !215, !tbaa !219, !alias.scope !223, !noalias !226, !enzyme_type !231 
│ Caused by:
│ Stacktrace:
│  [1] _deleteend!
│    @ ./array.jl:1081
│  [2] resize!
│    @ ./array.jl:1320
│  [3] _postamble!
│    @ ~/.julia/packages/OrdinaryDiffEqCore/Hp3EU/src/integrators/integrator_utils.jl:155
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in   %getfield90 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %281 unordered, align 8, !dbg !470, !tbaa !222, !alias.scope !226, !noalias !229, !nonnull !0, !dereferenceable !263, !align !264, !enzyme_type !324 
│ Caused by:
│ Stacktrace:
│  [1] _deleteend!
│    @ ./array.jl:1081
│  [2] resize!
│    @ ./array.jl:1320
│  [3] _savevalues!
│    @ ~/.julia/packages/OrdinaryDiffEqCore/Hp3EU/src/integrators/integrator_utils.jl:145
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in   %getfield7 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %24 unordered, align 8, !dbg !274, !tbaa !222, !alias.scope !226, !noalias !229, !nonnull !0, !dereferenceable !241, !align !242, !enzyme_type !276 
│ Caused by:
│ Stacktrace:
│  [1] _deleteend!
│    @ ./array.jl:1081
│  [2] resize!
│    @ ./array.jl:1320
│  [3] #reeval_internals_due_to_modification!#29
│    @ ~/.julia/packages/OrdinaryDiffEqCore/Hp3EU/src/integrators/integrator_interface.jl:49
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in   %getfield = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %7 unordered, align 8, !dbg !235, !tbaa !221, !alias.scope !225, !noalias !239, !nonnull !0, !dereferenceable !240, !align !241, !enzyme_type !242 
│ Caused by:
│ Stacktrace:
│  [1] _deleteend!
│    @ ./array.jl:1081
│  [2] resize!
│    @ ./array.jl:1320
│  [3] initialize!
│    @ ~/.julia/packages/OrdinaryDiffEqTsit5/DHYtz/src/tsit_perform_step.jl:166
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59

julia> 

julia> 

julia> st
ERROR: UndefVarError: `st` not defined

(tmp) pkg> st
Status `~/git/OrdinaryDiffEq.jl/tmp/Project.toml`
  [7da242da] Enzyme v0.13.14
  [1dea7af3] OrdinaryDiffEq v6.90.1
  [90137ffa] StaticArrays v1.9.8

so idk what's happening on your end

@wsmoses
Copy link
Member

wsmoses commented Nov 13, 2024

but it does look like you were on an old version of enzyme

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