-
Notifications
You must be signed in to change notification settings - Fork 57
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
1.10 Forward mode segfault #948
Comments
Min segfault: using ElectrochemicalKinetics
using Enzyme
Enzyme.API.runtimeActivity!(true) # comment this out or not...
mhcd = MarcusHushChidseyDOS(10000, 0.3, string(dirname(pathof(ElectrochemicalKinetics)), "/../data/DOSes/Cu_111_dos.txt"))
function qintegrand(
mhcd::MarcusHushChidseyDOS,
V_dl,
ox::Val;
T = 298,
V_q = 0.0,
)
E -> mhcd.dos.interp_func.(V_q)
end
function myintegrand(km, V, a_r)
E -> a_r .* qintegrand(km, V, Val(true))(E)
end
f2(mhcd, V) = myintegrand(mhcd, V, 1.0)(0.0)
autodiff(Forward, f2, Duplicated, Const(mhcd), Duplicated(0.2, 1.0)) Guaranteed to error when primal is not: using ElectrochemicalKinetics
using Enzyme
Enzyme.API.runtimeActivity!(true) # comment this out or not...
mhcd = MarcusHushChidseyDOS(10000, 0.3, string(dirname(pathof(ElectrochemicalKinetics)), "/../data/DOSes/Cu_111_dos.txt"))
function qintegrand(
mhcd::MarcusHushChidseyDOS,
V_dl,
ox::Val;
T = 298,
V_q = 0.0,
)
E -> mhcd.dos.interp_func.(V_q)
end
function myintegrand(km, V, a_r)
E -> a_r .* mhcd.dos.interp_func.(V)
end
f2(mhcd, V) = myintegrand(mhcd, V, 1.0)(0.0)
f2(mhcd, 0.2)
autodiff(Forward, f2, Duplicated, Const(mhcd), Duplicated(0.2, 1.0)) |
|
Segfault minimization: using Enzyme
Enzyme.API.runtimeActivity!(true) # comment this out or not...
using Interpolations
struct DOSData
interp_func
end
(dd::DOSData)(E::Real) = dd.interp_func(E)
function get_dos()
dd = [2.9516809522939885e-11, 8.676719161498216e-11, 2.487891370172147e-10, 6.958201977049105e-10, 1.898245560200562e-9, 5.05123413215916e-9, 1.3110895325949973e-8, 3.319379790963994e-8, 8.197308610758888e-8, 1.9745828933791896e-7, 4.6394788513206215e-7, 1.0632925551022797e-6, 2.3769830855968095e-6, 5.183094822926701e-6, 1.102406998435485e-5, 2.2870966284360038e-5, 4.6282500063521246e-5, 9.135637360226178e-5, 0.00017589384325990786, 0.0003303331584502414, 0.0006051227028130094, 0.0010812458918077518, 0.0018844960924227201, 0.0032037289202538123, 0.005312586752500653, 0.008593024836576044, 0.01355738307784779, 0.020863898123823135, 0.03131878118179209, 0.045856838750532015, 0.06549276308638619, 0.09123733508170402, 0.1239773009662438, 0.16432455312533853, 0.21244870984446, 0.26791572595103424, 0.32956165114951136, 0.3954327898879993, 0.46281947759703546, 0.5283997972828794, 0.5884928005834497, 0.6394009131743121, 0.677802270771196, 0.7011402225530853, 0.7079528175990029, 0.6980914868568764, 0.6727944873031677, 0.6346036099078469, 0.5871371193345678]
dos_interp = interpolate(dd, BSpline(Linear()))
return dos_interp
end
function qintegrand(
mhcd,
V_dl;
V_q = 1.0,
)
E -> mhcd.interp_func.(V_q)
end
function myintegrand(km, V, a_r)
E -> qintegrand(km, V)(E)
end
f2(mhcd, V) = myintegrand(mhcd, V, 1.0)(0.0)
dos = DOSData(get_dos())
autodiff(Forward, f2, Duplicated, Const(dos), Duplicated(0.2, 1.0))
|
using Enzyme
Enzyme.API.runtimeActivity!(true) # comment this out or not...
using Interpolations
struct DOSData
interp_func
end
@inline function (itp)(x::Vararg{Number,N}) where {T,N}
wis = Interpolations.weightedindexes((Interpolations.value_weights,), (BSpline(Linear()),), (Base.OneTo(3),), x)
Interpolations.InterpGetindex(Interpolations.coefficients(itp))[wis...]
end
function get_dos()
dd = [2.9516809522939885e-11, 3.0, 6.0]
dos_interp = interpolate(dd, BSpline(Linear()))
return dos_interp
end
function qintegrand(
mhcd,
V_dl;
V_q = 1.0,
)
E -> mhcd.interp_func.(V_q)
end
function myintegrand(km, V, a_r)
E -> qintegrand(km, V)(E)
end
f2(mhcd, V) = myintegrand(mhcd, V, 1.0)(0.0)
dos = DOSData(get_dos())
f2(dos, 0.2)
autodiff(Forward, f2, Duplicated, Const(dos), Duplicated(0.2, 1.0)) |
using Enzyme, Interpolations
Enzyme.API.runtimeActivity!(true)
Enzyme.API.printall!(true)
fn = Base.Broadcast.broadcasted;
dd = [2.9516809522939885e-11, 3.0, 6.0]
dos_interp = interpolate(dd, BSpline(Linear()))
Enzyme.autodiff(Forward, Base.Broadcast.broadcasted, Const(dos_interp), Duplicated(1.0, 0.0)) |
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: