-
Notifications
You must be signed in to change notification settings - Fork 82
Open
Description
I am on Enzyme 0.13.96 and Molly 0.23.0. The following works on Julia 1.11.7 but errors on Julia 1.10.10. I am trying to minimise the error, but struggling so posting here in case anyone has ideas.
If I use Enzyme.API.looseTypeAnalysis!(true) then I get a segfault. Using Enzyme.API.maxtypedepth!(12) and Enzyme.API.maxtypeoffset!(2048) gives the same error. The full error with Enzyme.Compiler.VERBOSE_ERRORS[] = true is attached as error.txt.
using Molly, Enzyme
const data_dir = joinpath(dirname(pathof(Molly)), "..", "data")
function f(params_dic, sys_ref, coords)
atoms, pis, sis, gis = Molly.inject_gradients(sys_ref, params_dic)
sys = System(
atoms=atoms,
coords=coords,
boundary=sys_ref.boundary,
pairwise_inters=pis,
specific_inter_lists=sis,
general_inters=gis,
neighbor_finder=sys_ref.neighbor_finder,
force_units=NoUnits,
energy_units=NoUnits,
)
return sys.coords[1][1]
end
params_dic = Dict("atom_N_ϵ" => 0.71128)
ff = MolecularForceField(
joinpath.(data_dir, "force_fields", ["ff99SBildn.xml", "his.xml"])...;
units=false,
)
sys_ref = System(
joinpath(data_dir, "6mrr_nowater.pdb"),
ff;
units=false,
)
grads_enzyme = Dict(k => 0.0 for k in keys(params_dic))
f(params_dic, sys_ref, sys_ref.coords) # Works
autodiff(
set_runtime_activity(Reverse),
f,
Active,
Duplicated(params_dic, grads_enzyme),
Const(sys_ref),
Duplicated(copy(sys_ref.coords), zero(sys_ref.coords)),
)ERROR: LoadError: Enzyme cannot statically prove the type of a value being differentiated and risks a correctness error if it gets it wrong.
Generally this shouldn't occur as Enzyme records type information from julia, but may be expected if you, for example copy untyped data.
or alternatively emit very large sized registers that exceed the maximum size of Enzyme's type analysis. If it seems reasonable to differentiate
this code, open an issue! If the cause of the error is too large of a register, you can request Enzyme increase the size (https://enzyme.mit.edu/julia/dev/api/#Enzyme.API.maxtypeoffset!-Tuple{Any})
or depth (https://enzyme.mit.edu/julia/dev/api/#Enzyme.API.maxtypedepth!-Tuple{Any}) of its type analysis.
Alternatively, you can tell Enzyme to take its best guess from context with (https://enzyme.mit.edu/julia/dev/api/#Enzyme.API.looseTypeAnalysis!-Tuple{Any})
All of these settings are global configurations that need to be set immeidately after loading Enzyme, before any differentiation occurs
To toggle more information for debugging (needed for bug reports), set Enzyme.Compiler.VERBOSE_ERRORS[] = true (default false)
Failure within method: MethodInstance for Molly.var"#System#4"(::Vector{Atom{Int64, Float64, Float64, Float64, Float64}}, ::Vector{SVector{3, Float64}}, ::CubicBoundary{3, Float64, Float64}, ::Nothing, ::Vector{Any}, ::Nothing, ::Tuple{LennardJones{DistanceCutoff{1, Float64}, typeof(Molly.lj_zero_shortcut), typeof(Molly.lorentz_σ_mixing), typeof(Molly.geometric_ϵ_mixing), Float64}, Coulomb{DistanceCutoff{1, Float64}, Float64, Float64}}, ::Tuple{InteractionList2Atoms{Vector{Int32}, Vector{HarmonicBond{Float64, Float64}}}, InteractionList3Atoms{Vector{Int32}, Vector{HarmonicAngle{Float64, Float64}}}, InteractionList4Atoms{Vector{Int32}, Vector{PeriodicTorsion{6, Float64, Float64}}}, InteractionList4Atoms{Vector{Int32}, Vector{PeriodicTorsion{6, Float64, Float64}}}}, ::Tuple{}, ::Tuple{}, ::CellListMapNeighborFinder{3, Float64}, ::Tuple{}, ::Unitful.FreeUnits{(), NoDims, nothing}, ::Unitful.FreeUnits{(), NoDims, nothing}, ::Float64, ::Nothing, ::Type{System})
Hint: catch this exception as `err` and call `code_typed(err)` to inspect the errornous code.
If you have Cthulu.jl loaded you can also use `code_typed(err; interactive = true)` to interactively introspect the code.
Stacktrace:
[1] iterate
@ ./range.jl:901 [inlined]
[2] fill!
@ ./array.jl:396 [inlined]
[3] zero
@ ./abstractarray.jl:1205 [inlined]
[4] #System#4
@ ~/.julia/dev/Molly/src/types.jl:576
[5] System
@ ~/.julia/dev/Molly/src/types.jl:540 [inlined]
[6] f
@ ~/dms/molly_dev/enzyme_err45.jl:18 [inlined]
[7] diffejulia_f_4405wrap
@ ~/dms/molly_dev/enzyme_err45.jl:0
[8] macro expansion
@ ~/.julia/dev/Enzyme/src/compiler.jl:5887 [inlined]
[9] enzyme_call
@ ~/.julia/dev/Enzyme/src/compiler.jl:5421 [inlined]
[10] CombinedAdjointThunk
@ ~/.julia/dev/Enzyme/src/compiler.jl:5307 [inlined]
[11] autodiff
@ ~/.julia/dev/Enzyme/src/Enzyme.jl:521 [inlined]
[12] autodiff(::ReverseMode{false, true, false, FFIABI, false, false}, ::typeof(f), ::Type{Active}, ::Duplicated{Dict{String, Float64}}, ::Const{System{3, Array, Float64, Vector{Atom{Int64, Float64, Float64, Float64, Float64}}, Vector{SVector{3, Float64}}, CubicBoundary{3, Float64, Float64}, Vector{SVector{3, Float64}}, Vector{AtomData}, MolecularTopology, Tuple{LennardJones{DistanceCutoff{1, Float64}, typeof(Molly.lj_zero_shortcut), typeof(Molly.lorentz_σ_mixing), typeof(Molly.geometric_ϵ_mixing), Float64}, Coulomb{DistanceCutoff{1, Float64}, Float64, Float64}}, Tuple{InteractionList2Atoms{Vector{Int32}, Vector{HarmonicBond{Float64, Float64}}}, InteractionList3Atoms{Vector{Int32}, Vector{HarmonicAngle{Float64, Float64}}}, InteractionList4Atoms{Vector{Int32}, Vector{PeriodicTorsion{6, Float64, Float64}}}, InteractionList4Atoms{Vector{Int32}, Vector{PeriodicTorsion{6, Float64, Float64}}}}, Tuple{}, Tuple{}, CellListMapNeighborFinder{3, Float64}, Tuple{}, Unitful.FreeUnits{(), NoDims, nothing}, Unitful.FreeUnits{(), NoDims, nothing}, Float64, Vector{Float64}, Float64, Nothing}}, ::Duplicated{Vector{SVector{3, Float64}}})
@ Enzyme ~/.julia/dev/Enzyme/src/Enzyme.jl:542
[13] top-level scope
@ ~/dms/molly_dev/enzyme_err45.jl:49
Metadata
Metadata
Assignees
Labels
No labels