Closed m-bossart closed 2 months ago
Can you narrow this down further to a simpler MWE?
Ok I've narrowed it to remove the application specific packages built on top of the differential equation ecosystem. The problem is related to the order in which ProgressLogging
and Enzyme
are loaded (the failure only happens when ProgressLogging
is loaded after Enzyme
).
#This order works:
using ProgressLogging
using Enzyme
#This order fails:
#using Enzyme
#using ProgressLogging
using OrdinaryDiffEq
using ComponentArrays
using LinearAlgebra
function dq_ri(δ::T) where {T <: Number}
return T[
sin(δ) cos(δ)
-cos(δ) sin(δ)
]
end
function ri_dq(δ::T) where {T <: Number}
return T[
sin(δ) -cos(δ)
cos(δ) sin(δ)
]
end
function f!(dx, x, p, t)
vr_1, vr_2, vi_1, vi_2, ir_1_2, ii_1_2, δ, ω = x
L = p[:BUS1BUS2][:params][:L]
R = p[:BUS1BUS2][:params][:R]
c_1 = p[:BUS1BUS2][:params][:c_1]
c_2 = p[:BUS1BUS2][:params][:c_2]
R_th = p[:InfBus][:params][:R_th]
X_th = p[:InfBus][:params][:X_th]
vm_internal = p[:InfBus][:refs][:V_ref]
θ_internal = p[:InfBus][:refs][:θ_ref]
R_gen = p[:generator_102_1][:params][:Machine][:R]
Xd_p = p[:generator_102_1][:params][:Machine][:Xd_p]
eq_p = p[:generator_102_1][:params][:Machine][:eq_p]
Sbase = p[:generator_102_1][:params][:Sbase]
H = p[:generator_102_1][:params][:Shaft][:H]
D = p[:generator_102_1][:params][:Shaft][:D]
τm = p[:generator_102_1][:refs][:P_ref]
ω_sys = 1.0
ω_b = 60 * 2 * pi
basepower = 100.0
V_R_internal = vm_internal * cos(θ_internal)
V_I_internal = vm_internal * sin(θ_internal)
Zmag = R_th^2 + X_th^2
i_r_source = R_th * (V_R_internal - vr_1) / Zmag + X_th * (V_I_internal - vi_1) / Zmag
i_i_source = R_th * (V_I_internal - vi_1) / Zmag - X_th * (V_R_internal - vr_1) / Zmag
i_ri_source = [i_r_source; i_i_source]
#Generator Model
V_dq = ri_dq(δ) * [vr_2; vi_2]
i_d = (1.0 / (R_gen^2 + Xd_p^2)) * (Xd_p * (eq_p - V_dq[2]) - R_gen * V_dq[1]) #15.36
i_q = (1.0 / (R_gen^2 + Xd_p^2)) * (Xd_p * V_dq[1] + R_gen * (eq_p - V_dq[2])) #15.36
Pe = (V_dq[1] + R_gen * i_d) * i_d + (V_dq[2] + R_gen * i_q) * i_q
τe = Pe
i_ri_gen = (basepower / Sbase) * dq_ri(δ) * [i_d; i_q]
#Bus models (voltages); time constants in Mass Matrix; for bus currents, positive is going into bus.
ir_1 = -ir_1_2 + i_ri_source[1]
ii_1 = -ii_1_2 + i_ri_source[2]
ir_2 = ir_1_2 + i_ri_gen[1]
ii_2 = ii_1_2 + i_ri_gen[2]
dx[1] = (ir_1 + vi_1 * c_1)
dx[3] = (ii_1 - vr_1 * c_1)
dx[2] = (ir_2 + vi_2 * c_2)
dx[4] = (ii_2 - vr_2 * c_2)
dx[5] = (ω_b / L) * ((vr_1 - vr_2) - (R * ir_1_2 - L * ii_1_2))
dx[6] = (ω_b / L) * ((vi_1 - vi_2) - (R * ii_1_2 + L * ir_1_2))
dx[7] = 2 * π * 60 * (ω - ω_sys) #15.5
dx[8] = (1 / (2 * H)) * (τm - τe - D * (ω - 1.0) / ω) #15.5
return
end
p = ComponentVector{Float64}(
BUS1BUS2 = (
params = (L = 0.1, R = 0.0, c_1 = 0.0, c_2 = 0.0),
refs = Float64[]
),
InfBus = (
params = (R_th = 0.0, X_th = 5.0e-6),
refs = (V_ref = 1.0500005545402755, θ_ref = -2.267572498565851e-6)
),
generator_102_1 = (
params = (Machine = (R = 0.0, Xd_p = 0.5, eq_p = 1.0241178412217837), Shaft = (H = 2.0, D = 2.0), Sbase = 100.0),
refs = (;P_ref = 1.0)
)
)
M = Diagonal(vcat(zeros(4), ones(4)))
x0 = [
1.0499999999999878
1.0389092482347253
2.690377732797622e-20
0.047619047619048165
-0.47619047619048166
-0.11090751765262562
0.28273776304747733
1.0
]
f_ode = ODEFunction{true}(f!; mass_matrix = M)
prob = ODEProblem{true}(f_ode, x0, (0.0, 5.0), p)
u0 = prob.u0
p = prob.p
tmp2 = Enzyme.make_zero(p)
t = prob.tspan[1]
du = zero(u0)
_f = prob.f
_tmp6 = Enzyme.make_zero(_f)
tmp3 = zero(u0)
tmp4 = zero(u0)
ytmp = zero(u0)
tmp1 = zero(u0)
Enzyme.autodiff(Enzyme.Reverse, Enzyme.Duplicated(_f, _tmp6),
Enzyme.Const, Enzyme.Duplicated(tmp3, tmp4),
Enzyme.Duplicated(ytmp, tmp1),
Enzyme.Duplicated(p, tmp2),
Enzyme.Const(t))
Unfortunately when I load Enzyme last in the original MWE, Julia crashes with the following:
GC error (probable corruption)
Allocations: 247118948 (Pool: 246816324; Big: 302624); GC: 160
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 0x7ff8c5ad04c8 -- jl_static_is_function_ at C:/workdir/src\rtutils.c:696 [inlined]
jl_static_show_x_ at C:/workdir/src\rtutils.c:1113
in expression starting at c:\Users\Matt Bossart\OneDrive - UCB-O365\Desktop\temp_for_mwe\mwe_aug_forward\mwe_enzymevjp.jl:69
jl_static_is_function_ at C:/workdir/src\rtutils.c:696 [inlined]
jl_static_show_x_ at C:/workdir/src\rtutils.c:1113
jl_static_show_next_ at C:/workdir/src\rtutils.c:1262
jl_static_show_x at C:/workdir/src\rtutils.c:1207 [inlined]
ijl_static_show at C:/workdir/src\rtutils.c:1268 [inlined]
jl_ at C:/workdir/src\rtutils.c:1358
gc_dump_queue_and_abort at C:/workdir/src\gc.c:1808
gc_mark_outrefs at C:/workdir/src\gc.c:2528 [inlined]
gc_mark_loop_serial_ at C:/workdir/src\gc.c:2697
gc_mark_loop_serial at C:/workdir/src\gc.c:2720
gc_mark_loop at C:/workdir/src\gc.c:2901 [inlined]
_jl_gc_collect at C:/workdir/src\gc.c:3234
ijl_gc_collect at C:/workdir/src\gc.c:3531
maybe_collect at C:/workdir/src\gc.c:937 [inlined]
jl_gc_pool_alloc_inner at C:/workdir/src\gc.c:1300
jl_gc_pool_alloc_noinline at C:/workdir/src\gc.c:1357 [inlined]
jl_gc_alloc_ at C:/workdir/src\julia_internal.h:476 [inlined]
jl_gc_alloc at C:/workdir/src\gc.c:3583
_new_array_ at C:/workdir/src\array.c:134
_new_array at C:/workdir/src\array.c:198 [inlined]
ijl_alloc_array_1d at C:/workdir/src\array.c:436
Array at .\boot.jl:477 [inlined]
Array at .\boot.jl:486 [inlined]
similar at .\abstractarray.jl:877 [inlined]
similar at .\abstractarray.jl:876 [inlined]
_array_for at .\array.jl:723 [inlined]
_array_for at .\array.jl:726 [inlined]
InferenceState at .\compiler\inferencestate.jl:270
InferenceState at .\compiler\inferencestate.jl:433
const_prop_call at .\compiler\abstractinterpretation.jl:1201
abstract_call_method_with_const_args at .\compiler\abstractinterpretation.jl:818
abstract_call_method_with_const_args at .\compiler\abstractinterpretation.jl:788
abstract_call_gf_by_type at .\compiler\abstractinterpretation.jl:103
abstract_call_known at .\compiler\abstractinterpretation.jl:2087
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:2889
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:219
typeinf_edge at .\compiler\typeinfer.jl:930
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
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:219
typeinf_edge at .\compiler\typeinfer.jl:930
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
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:219
typeinf_edge at .\compiler\typeinfer.jl:930
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
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:219
typeinf_edge at .\compiler\typeinfer.jl:930
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
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:219
typeinf_edge at .\compiler\typeinfer.jl:930
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
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:219
typeinf_edge at .\compiler\typeinfer.jl:930
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
unknown function (ip: 000001e50bed2fb3)
unknown function (ip: 000001e527908d4d)
unknown function (ip: 000001e527908cc2)
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:219 [inlined]
typeinf_ext at .\compiler\typeinfer.jl:1051
typeinf_ext_toplevel at .\compiler\typeinfer.jl:1082
ci_cache_populate at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\jlgen.jl:523
compile_method_instance at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\jlgen.jl:599
macro expansion at C:\Users\Matt Bossart\.julia\packages\TimerOutputs\Lw5SP\src\TimerOutput.jl:253 [inlined]
irgen at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\irgen.jl:4
macro expansion at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\driver.jl:208 [inlined]
macro expansion at C:\Users\Matt Bossart\.julia\packages\TimerOutputs\Lw5SP\src\TimerOutput.jl:253 [inlined]
macro expansion at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\driver.jl:207 [inlined]
#emit_llvm#158 at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\utils.jl:103
emit_llvm at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\utils.jl:97 [inlined]
#codegen#156 at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\driver.jl:136
codegen at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\driver.jl:115 [inlined]
#codegen#28546 at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:5164
codegen at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:5132 [inlined]
_thunk at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:6661
_thunk at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:6661 [inlined]
cached_compilation at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:6699 [inlined]
#28593 at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:6768
#JuliaContext#154 at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\driver.jl:52
unknown function (ip: 000001e51a8fff6c)
JuliaContext at C:\Users\Matt Bossart\.julia\packages\GPUCompiler\05oYT\src\driver.jl:42
#s2010#28592 at C:\Users\Matt Bossart\.julia\packages\Enzyme\x1vcV\src\compiler.jl:6719 [inlined]
#s2010#28592 at .\none:0
GeneratedFunctionStub at .\boot.jl:602
jl_call_staged at C:/workdir/src\method.c:540
ijl_code_for_staged at C:/workdir/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_38981.1 at C:\Users\Matt Bossart\.julia\juliaup\julia-1.10.4+0.x64.w64.mingw32\lib\julia\sys.dll (unknown line)
_jl_invoke at C:/workdir/src\gf.c:2895 [inlined]
ijl_apply_generic at C:/workdir/src\gf.c:3077 [inlined]
jl_apply at C:/workdir/src\julia.h:1982 [inlined]
jl_type_infer at C:/workdir/src\gf.c:394
jl_generate_fptr_impl at C:/workdir/src\jitlayers.cpp:504
jl_compile_method_internal at C:/workdir/src\gf.c:2481
jl_compile_method_internal at C:/workdir/src\gf.c:2372 [inlined]
_jl_invoke at C:/workdir/src\gf.c:2887 [inlined]
ijl_apply_generic at C:/workdir/src\gf.c:3077
unknown function (ip: 000001e5138637ad)
Allocations: 247118948 (Pool: 246816324; Big: 302624); GC: 160
@m-bossart on latest Enzyme and julia 1.10.5, this doesn't err for me. Reopen if it persists?
I'm getting the following error when using
EnzymeVJP()
option for the sensitivity of anODEProblem
. I've isolated the error to an Enzyme autodiff call per the instructions here: https://docs.sciml.ai/SciMLSensitivity/stable/faq/The example below should reproduce the error. I only get the error when using the ODEProblem that comes from the application specific code. I can work to minimize further if needed.
Environment details: