Skip to content

Error in Using DataInterpolations.jl and Enzyme.jl for Real-Time Interpolation and Gradient Computation in ODE Problems #469

@chooron

Description

@chooron

Describe the bug 🐞

Hello, I currently have an ODE problem where I need to use DataInterpolations.jl to interpolate and obtain real-time values, which are then used for computing du. Next, I need to use Enzyme.jl to compute the gradients of parameters during the computation process. According to the suggestion in ChrisRackauckas's reply, I opened an issue here for this bug.

Expected behavior

Successful execution yields results similar to ForwardDiff

Minimal Reproducible Example 👇

Without MRE, we would only be able to help you to a limited extent, and attention to the issue would be limited. to know more about MRE refer to wikipedia and stackoverflow.

using DifferentiationInterface, Enzyme
using DifferentialEquations, DataInterpolations, SciMLSensitivity
using ComponentArrays

t_data = collect(0.0:1.0:11.0)
alpha_values = rand(length(t_data))

function loss_function(params, config)

    interpolator = config.interpolator_type(
        alpha_values,
        config.t_data,
    )

    function my_ode!(du, u, p, t)
        alpha_t = interpolator(t)
        du[1] = -alpha_t * u[1] * p[1] + p[2]
        return nothing
    end

    u0 = [10.0]
    tspan = (1.0, 10.0)

    prob = ODEProblem(my_ode!, u0, tspan, params, sensealg=GaussAdjoint(autojacvec=EnzymeVJP()))
    sol = solve(prob, Tsit5(), save_everystep=false, save_start=false)
    return Array(sol) |> sum
end

config = (
    interpolator_type=ConstantInterpolation,
    t_data=t_data,
)

initial_alpha_values = rand(length(t_data))
params = [1.0, 2.0]
target_func(p) = loss_function(p, config)
target_func(params)
ad_backend = AutoEnzyme(mode=Enzyme.set_runtime_activity(Enzyme.Reverse),)
val, grad = value_and_gradient(target_func, ad_backend, params)

Error & Stacktrace ⚠️
I tried using ConstantInterpolation or LinearInterpolation for interpolation, but both resulted in the following issues:

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x7ffc3391e40d -- gc_try_setmark_tag at C:/workdir/src\gc.c:826 [inlined]
gc_try_claim_and_push at C:/workdir/src\gc.c:2094 [inlined]
gc_mark_obj16 at C:/workdir/src\gc.c:2146
in expression starting at e:\JlCode\HydroModels\dev\tmp2.jl:39
gc_try_setmark_tag at C:/workdir/src\gc.c:826 [inlined]
gc_try_claim_and_push at C:/workdir/src\gc.c:2094 [inlined]
gc_mark_obj16 at C:/workdir/src\gc.c:2146
gc_mark_outrefs at C:/workdir/src\gc.c:2895 [inlined]
gc_mark_loop_serial_ at C:/workdir/src\gc.c:2938
gc_mark_loop_serial at C:/workdir/src\gc.c:2961
gc_mark_loop at C:/workdir/src\gc.c:3143 [inlined]
_jl_gc_collect at C:/workdir/src\gc.c:3532
ijl_gc_collect at C:/workdir/src\gc.c:3893
maybe_collect at C:/workdir/src\gc.c:926 [inlined]
jl_gc_pool_alloc_inner at C:/workdir/src\gc.c:1319
jl_gc_pool_alloc_noinline at C:/workdir/src\gc.c:1386 [inlined]
jl_gc_alloc_ at C:/workdir/src\julia_internal.h:523 [inlined]
jl_gc_alloc at C:/workdir/src\gc.c:3946
_new_genericmemory_ at C:/workdir/src\genericmemory.c:56 [inlined]
jl_alloc_genericmemory at C:/workdir/src\genericmemory.c:99
GenericMemory at .\boot.jl:516 [inlined]
array_new_memory at .\array.jl:1058 [inlined]
#134 at .\array.jl:1129
_growend! at .\array.jl:1116 [inlined]
push! at .\array.jl:1261 [inlined]
compute_basic_blocks at .\compiler/ssair\ir.jl:144
InferenceState at .\compiler\inferencestate.jl:288
InferenceState at .\compiler\inferencestate.jl:500
typeinf_edge at .\compiler\typeinfer.jl:913
abstract_call_method at .\compiler\abstractinterpretation.jl:660
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:102
abstract_call_known at .\compiler\abstractinterpretation.jl:2200
abstract_call at .\compiler\abstractinterpretation.jl:2282
abstract_call at .\compiler\abstractinterpretation.jl:2275
abstract_call at .\compiler\abstractinterpretation.jl:2423
abstract_eval_call at .\compiler\abstractinterpretation.jl:2438
abstract_eval_statement_expr at .\compiler\abstractinterpretation.jl:2454
abstract_eval_statement at .\compiler\abstractinterpretation.jl:2752
abstract_eval_basic_statement at .\compiler\abstractinterpretation.jl:3068
typeinf_local at .\compiler\abstractinterpretation.jl:3331
typeinf_nocycle at .\compiler\abstractinterpretation.jl:3413
_typeinf at .\compiler\typeinfer.jl:244
typeinf at .\compiler\typeinfer.jl:215
typeinf_edge at .\compiler\typeinfer.jl:923
abstract_call_method at .\compiler\abstractinterpretation.jl:660
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:102
abstract_call_known at .\compiler\abstractinterpretation.jl:2200
abstract_call at .\compiler\abstractinterpretation.jl:2282
abstract_call at .\compiler\abstractinterpretation.jl:2275
abstract_call at .\compiler\abstractinterpretation.jl:2423
abstract_eval_call at .\compiler\abstractinterpretation.jl:2438
abstract_eval_statement_expr at .\compiler\abstractinterpretation.jl:2454
abstract_eval_statement at .\compiler\abstractinterpretation.jl:2752
abstract_eval_basic_statement at .\compiler\abstractinterpretation.jl:3044
typeinf_local at .\compiler\abstractinterpretation.jl:3331
typeinf_nocycle at .\compiler\abstractinterpretation.jl:3413
_typeinf at .\compiler\typeinfer.jl:244
typeinf at .\compiler\typeinfer.jl:215
typeinf_edge at .\compiler\typeinfer.jl:923
abstract_call_method at .\compiler\abstractinterpretation.jl:660
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:102
abstract_call_unknown at .\compiler\abstractinterpretation.jl:2269
abstract_call at .\compiler\abstractinterpretation.jl:2279
abstract_call at .\compiler\abstractinterpretation.jl:2275
abstract_call at .\compiler\abstractinterpretation.jl:2423
abstract_eval_call at .\compiler\abstractinterpretation.jl:2438
abstract_eval_statement_expr at .\compiler\abstractinterpretation.jl:2454
abstract_eval_statement at .\compiler\abstractinterpretation.jl:2752
abstract_eval_basic_statement at .\compiler\abstractinterpretation.jl:3068
typeinf_local at .\compiler\abstractinterpretation.jl:3331
typeinf_nocycle at .\compiler\abstractinterpretation.jl:3413
_typeinf at .\compiler\typeinfer.jl:244
typeinf at .\compiler\typeinfer.jl:215
typeinf_ext at .\compiler\typeinfer.jl:1101
typeinf_ext_toplevel at .\compiler\typeinfer.jl:1139
typeinf_ext_toplevel at .\compiler\typeinfer.jl:1135
jfptr_typeinf_ext_toplevel_41140.1 at C:\Users\OMEN\.julia\juliaup\julia-1.11.5+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
_jl_invoke at C:/workdir/src\gf.c:2948 [inlined]
ijl_apply_generic at C:/workdir/src\gf.c:3125 [inlined]
jl_apply at C:/workdir/src\julia.h:2157 [inlined]
jl_type_infer at C:/workdir/src\gf.c:390
jl_generate_fptr_impl at C:/workdir/src\jitlayers.cpp:519
jl_compile_method_internal at C:/workdir/src\gf.c:2536
jl_compile_method_internal at C:/workdir/src\gf.c:2946 [inlined]
_jl_invoke at C:/workdir/src\gf.c:2940 [inlined]
ijl_invoke at C:/workdir/src\gf.c:2955
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:447
unknown function (ip: 00000204b273f9b0)
unknown function (ip: 00000204b273f34d)
unknown function (ip: 00000204b273efb1)
Merger at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:35 [inlined]
macro expansion at .\ntuple.jl:72 [inlined]
ntuple at .\ntuple.jl:69 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:447
unknown function (ip: 00000204b273eee0)
unknown function (ip: 00000204b273e60d)
unknown function (ip: 00000204b273e5a1)
Merger at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:35 [inlined]
ntuple at .\ntuple.jl:48 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:447
unknown function (ip: 00000204b273e4d0)
unknown function (ip: 00000204b273dc7d)
unknown function (ip: 00000204b273db01)
Merger at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:35 [inlined]
macro expansion at .\ntuple.jl:72 [inlined]
ntuple at .\ntuple.jl:69 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:447
unknown function (ip: 00000204b273da30)
unknown function (ip: 00000204b273b15d)
unknown function (ip: 00000204b273aed1)
Merger at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:35 [inlined]
macro expansion at .\ntuple.jl:72 [inlined]
ntuple at .\ntuple.jl:69 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:447
unknown function (ip: 00000204b273ae00)
unknown function (ip: 00000204b27397ed)
unknown function (ip: 00000204b2739561)
Merger at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:35 [inlined]
macro expansion at .\ntuple.jl:72 [inlined]
ntuple at .\ntuple.jl:69 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:447
unknown function (ip: 00000204b27391f0)
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:206 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:206 [inlined]
active_reg_inner at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:206 [inlined]
guaranteed_const_nongen at D:\Julia\packages\packages\Enzyme\lmg7D\src\analyses\activity.jl:487 [inlined]
thunkbase at D:\Julia\packages\packages\Enzyme\lmg7D\src\compiler.jl:5885
thunk_generator at D:\Julia\packages\packages\Enzyme\lmg7D\src\compiler.jl:6122
jfptr_thunk_generator_36804 at D:\Julia\packages\compiled\v1.11\Enzyme\G1p5n_WkAWM.dll (unknown line)
jl_call_staged at C:/workdir/src\method.c:601
ijl_code_for_staged at C:/workdir/src\method.c:656
get_staged at .\compiler\utilities.jl:123
retrieve_code_info at .\compiler\utilities.jl:135 [inlined]
InferenceState at .\compiler\inferencestate.jl:497
typeinf_edge at .\compiler\typeinfer.jl:913
abstract_call_method at .\compiler\abstractinterpretation.jl:660
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:102
abstract_call_known at .\compiler\abstractinterpretation.jl:2200
abstract_call at .\compiler\abstractinterpretation.jl:2282
abstract_call at .\compiler\abstractinterpretation.jl:2275
abstract_call at .\compiler\abstractinterpretation.jl:2423
abstract_eval_call at .\compiler\abstractinterpretation.jl:2438
abstract_eval_statement_expr at .\compiler\abstractinterpretation.jl:2454
abstract_eval_statement at .\compiler\abstractinterpretation.jl:2752
abstract_eval_basic_statement at .\compiler\abstractinterpretation.jl:3068
typeinf_local at .\compiler\abstractinterpretation.jl:3331
typeinf_nocycle at .\compiler\abstractinterpretation.jl:3413
_typeinf at .\compiler\typeinfer.jl:244
typeinf at .\compiler\typeinfer.jl:215
typeinf_ext at .\compiler\typeinfer.jl:1101
typeinf_ext_toplevel at .\compiler\typeinfer.jl:1139
typeinf_ext_toplevel at .\compiler\typeinfer.jl:1135
jfptr_typeinf_ext_toplevel_41140.1 at C:\Users\OMEN\.julia\juliaup\julia-1.11.5+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
_jl_invoke at C:/workdir/src\gf.c:2948 [inlined]
ijl_apply_generic at C:/workdir/src\gf.c:3125 [inlined]
jl_apply at C:/workdir/src\julia.h:2157 [inlined]
jl_type_infer at C:/workdir/src\gf.c:390
jl_generate_fptr_impl at C:/workdir/src\jitlayers.cpp:519
jl_compile_method_internal at C:/workdir/src\gf.c:2536
jl_compile_method_internal at C:/workdir/src\gf.c:2946 [inlined]
_jl_invoke at C:/workdir/src\gf.c:2940 [inlined]
ijl_apply_generic at C:/workdir/src\gf.c:3125
#solve#43 at D:\Julia\packages\packages\DiffEqBase\AfBQT\src\solve.jl:1083
Allocations: 225954686 (Pool: 225949721; Big: 4965); GC: 72

Environment (please complete the following information):

  • Output of using Pkg; Pkg.status()
  [82cc6244] DataInterpolations v8.6.0
  [0c46a032] DifferentialEquations v7.16.1
  [a0c0ee7d] DifferentiationInterface v0.7.7
  [7da242da] Enzyme v0.13.73
  [1ed8b502] SciMLSensitivity v7.89.0
  • Output of versioninfo()
Julia Version 1.11.5
Commit 760b2e5b73 (2025-04-14 06:53 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 24 × 12th Gen Intel(R) Core(TM) i9-12900HX
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 1 default, 0 interactive, 1 GC (on 24 virtual cores)
Environment:
  JULIA_DEPOT_PATH = D:\Julia\packages
  JULIA_EDITOR = code
  JULIA_VSCODE_REPL = 1
  JULIA_NUM_THREADS = 0

Additional context

Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions