We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
When using Enzyme to autodiff complex Bessel functions (a new feature for Enzyme), I'm getting the following error stack in Julia 1.10.6 and 1.11.1:
ERROR: LoadError: LLVM error: Duplicate definition of symbol 'libname_zbesy__3764' Stacktrace: [1] macro expansion @ ~/.julia/packages/LLVM/wMjUU/src/executionengine/utils.jl:28 [inlined] [2] add! @ ~/.julia/packages/LLVM/wMjUU/src/orc.jl:433 [inlined] [3] add!(mod::LLVM.Module) @ Enzyme.Compiler.JIT ~/.julia/packages/Enzyme/6C71q/src/compiler/orcv2.jl:264 [4] _link(job::GPUCompiler.CompilerJob{…}, mod::LLVM.Module, adjoint_name::String, primal_name::Union{…}, TapeType::Any, prepost::String) @ Enzyme.Compiler ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:5239 [5] cached_compilation @ ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:5325 [inlined] [6] thunkbase(mi::Core.MethodInstance, World::UInt64, FA::Type{…}, A::Type{…}, TT::Type, Mode::Enzyme.API.CDerivativeMode, width::Int64, ModifiedBetween::Tuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool) @ Enzyme.Compiler ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:5434 [7] thunk_generator(world::UInt64, source::LineNumberNode, FA::Type, A::Type, TT::Type, Mode::Enzyme.API.CDerivativeMode, Width::Int64, ModifiedBetween::Tuple{…} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, self::Any, fakeworld::Any, fa::Type, a::Type, tt::Type, mode::Type, width::Type, modifiedbetween::Type, returnprimal::Type, shadowinit::Type, abi::Type, erriffuncwritten::Type, runtimeactivity::Type) @ Enzyme.Compiler ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:5601 [8] runtime_generic_augfwd(activity::Type{…}, runtimeActivity::Val{…}, width::Val{…}, ModifiedBetween::Val{…}, RT::Val{…}, f::typeof(enzSL_0f0), df::Nothing, primal_1::Matrix{…}, shadow_1_1::Matrix{…}, primal_2::Int64, shadow_2_1::Nothing, primal_3::Float64, shadow_3_1::Nothing, primal_4::Float64, shadow_4_1::Nothing, primal_5::Vector{…}, shadow_5_1::Nothing, primal_6::Float64, shadow_6_1::Nothing) @ Enzyme.Compiler ~/.julia/packages/Enzyme/6C71q/src/rules/jitrules.jl:465 [9] #17 @ ~/nuclear-diffprog/MWEs/coreloop_enz.jl:132 [inlined] [10] augmented_julia__17_2308wrap @ ~/nuclear-diffprog/MWEs/coreloop_enz.jl:0 [11] macro expansion @ ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:5204 [inlined] [12] enzyme_call @ ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:4750 [inlined] [13] (::Enzyme.Compiler.AugmentedForwardThunk{…})(fn::Const{…}, args::Duplicated{…}) @ Enzyme.Compiler ~/.julia/packages/Enzyme/6C71q/src/compiler.jl:4686 [14] #130 @ ~/.julia/packages/Enzyme/6C71q/src/sugar.jl:928 [inlined] [15] ntuple @ ./ntuple.jl:49 [inlined] [16] jacobian(mode::ReverseMode{…}, f::var"#17#18", x::Matrix{…}; n_outs::Val{…}, chunk::Nothing) @ Enzyme ~/.julia/packages/Enzyme/6C71q/src/sugar.jl:924 [17] jacobian @ ~/.julia/packages/Enzyme/6C71q/src/sugar.jl:841 [inlined] [18] #jacobian#129 @ ~/.julia/packages/Enzyme/6C71q/src/sugar.jl:856 [inlined] [19] jacobian(mode::ReverseMode{false, false, FFIABI, false, false}, f::var"#17#18", x::Matrix{Float32}) @ Enzyme ~/.julia/packages/Enzyme/6C71q/src/sugar.jl:841 [20] top-level scope @ ~/nuclear-diffprog/MWEs/coreloop_enz.jl:132 [21] include(fname::String) @ Base.MainInclude ./client.jl:494 [22] top-level scope @ REPL[3]:1 in expression starting at /vast/home/daningburg/nuclear-diffprog/MWEs/coreloop_enz.jl:132 Some type information was truncated. Use `show(err)` to see complete types.
My full runnable code:
# Test coreloop diff with Enzyme begin # Packages using SpecialFunctions using BenchmarkTools using SphericalHarmonics using Enzyme end begin # Functions # Coulomb funcs function GL(k, r, L) return -k*r*sphericalbessely(L, k*r) end function FL(k, r, L) return k*r*sphericalbesselj(L, k*r) end # Spherical Hankel functions function Hminus(k, r, L) return complex(GL(k, r, L), -FL(k, r, L)) end function Hplus(k, r, L) return complex(GL(k, r, L), FL(k, r, L)) end # Derivatives enzR_Hminusprime(k, r, L) = complex(Enzyme.gradient(Reverse, x -> GL(k, x, L), r)[1], -Enzyme.gradient(Reverse, x -> FL(k, x, L), r)[1]) enzR_Hplusprime(k, r, L) = complex(Enzyme.gradient(Reverse, x -> GL(k, x, L), r)[1], Enzyme.gradient(Reverse, x -> FL(k, x, L), r)[1]) enzF_Hminusprime(k, r, L) = complex(Enzyme.gradient(Forward, x -> GL(k, x, L), r)[1], -Enzyme.gradient(Forward, x -> FL(k, x, L), r)[1]) enzF_Hplusprime(k, r, L) = complex(Enzyme.gradient(Forward, x -> GL(k, x, L), r)[1], Enzyme.gradient(Forward, x -> FL(k, x, L), r)[1]) function enzSL_0f0(U, L, μ, k, r, Ecm) dr = r[2] - r[1] len = size(r)[1]-1 ur1, ur2, ur3 = 0.0, 0.0, 0.0 ui1, ui2, ui3 = 0.0, 0.0, 0.0 dur1, dur2, dur3 = 0.0, 0.0, 0.0 dui1, dui2, dui3 = 0.0, 0.0, 0.0 a = r[end-2] ur2 = 1e-6 ui1 = 1e-12 # ideally these are all always Float32, or all always Float64 ui2 = 1e-6 for i in 3:len vreal = Ecm - U[i,1] vimag = -U[i,2] w = 2*μ/ħ^2*complex(vreal, vimag) - L*(L+1)/r[i]^2 vreal = Ecm -U[i-1,1] vimag = -U[i-1,2] wmo = 2*μ/ħ^2*complex(vreal, vimag) - L*(L+1)/r[i]^2 vreal = Ecm - U[i+1,1] vimag = -U[i+1,2] wpo = 2*μ/ħ^2*complex(vreal, vimag) - L*(L+1)/r[i]^2 uval = (2*complex(ur2,ui2)-complex(ur1,ui1)-(dr^2/12)*(10*w*complex(ur2,ui2)+wmo*complex(ur1,ui1)))/(1+(dr^2/12)*wpo) ur3 = real.(uval) dur3 = 0.5*(ur3-ur1)/dr ui3 = imag.(uval) dui3 = 0.5*(ui3-ui1)/dr ur1, ur2 = ur2, ur3 dur1, dur2 = dur2, dur3 ui1, ui2 = ui2, ui3 dui1, dui2 = dui2, dui3 end ua = complex(ur2,ui2) dua = complex(dur3,dui3) RL = ua / dua SLtop = Hminus(k, a, L) - RL*enzR_Hminusprime(k, a, L) SLbot = Hplus(k, a, L) - RL*enzR_Hplusprime(k, a, L) # SLtop = Hminus(k, a, L) - RL*enzF_Hminusprime(k, a, L) # SLbot = Hplus(k, a, L) - RL*enzF_Hplusprime(k, a, L) SL = SLtop/SLbot return [real(SL), imag(SL)] end # Koning-Delaroche Potential function kd_params(A, Z, E) N = A - Z Ef = -11.23814 + 0.02646*A v1 = 59.3 - 21.0*(N-Z)/A - 0.024*A v2 = 0.007228 - (1.48e-6)*A v3 = 1.994e-5 - (2.e-8)*A v4 = 7.e-9 Vo = v1*(1-v2*(E-Ef)+v3*(E-Ef)^2-v4*(E-Ef)^3) ro = (1.3039 - 0.4054/A^(1/3))*A^(1/3) ao = 0.6778 - (1.487e-4)*A w1 = 12.195 + 0.0167*A w2 = 73.55 + 0.0795*A Wro = w1*(E-Ef)^2/((E-Ef)^2+w2^2) d1 = 16 - 16*(N-Z)/A d2 = 0.0180 + 0.003802/(1+exp((A-156.)/8.)) d3 = 11.5 rw = (1.3424 - 0.01585*A^(1/3))*A^(1/3) aw = 0.5446 - (1.656e-4)*A Wso = d1*(E-Ef)^2*exp(-d2*(E-Ef))/((E-Ef)^2+d3^2) return Vo, ro, ao, Wro, Wso, rw, aw end function kd_pots(A, Z, E, r) Vo, ro, ao, Wro, Wso, rw, aw = kd_params(A, Z, E) Vr = -Vo ./(1 .+ exp.(-(ro.-r)./ao)) W = -Wro ./(1 .+ exp.(-(ro.-r)./ao)) Ws = -4 .* Wso .* exp.(-(rw.-r)./aw) ./(1 .+exp.(-(rw.-r)./aw)).^2 return Vr, W, Ws end end # Set up particular scattering problem A = 65 Z = 29 N = A - Z E = 10 L = 14 Ecm = 9.848393154293218 μ = 925.3211722114523 k = 0.6841596644044445 r = Vector(LinRange(0, 20, 2000)) dr = r[2] - r[1] const global ħ = 197.3269804 # General a potential from K-D Vreal, Wv, Ws = kd_pots(A, Z, E, r); U = Float32.(hcat(Vreal, Wv + Ws);) reshape(Enzyme.jacobian(Reverse, U -> enzSL_0f0(U, L, μ, k, r, Ecm), U)[1], 2, :) reshape(Enzyme.jacobian(Reverse, U -> enzSL_0f0(U, L, μ, k, r, Ecm), Float64.(U))[1], 2, :) # all the rest is Float64
The text was updated successfully, but these errors were encountered:
can you test if #2201 resolves this for you?
Sorry, something went wrong.
No branches or pull requests
When using Enzyme to autodiff complex Bessel functions (a new feature for Enzyme), I'm getting the following error stack in Julia 1.10.6 and 1.11.1:
My full runnable code:
The text was updated successfully, but these errors were encountered: