Enzyme.jl icon indicating copy to clipboard operation
Enzyme.jl copied to clipboard

Define custom adjoint for `jl_f_getfield`

Open bgroenks96 opened this issue 3 years ago • 2 comments
trafficstars

Loss and sciml_train call (other stuff omitted for now):

function loss(p)
    u0_new = copyto!(similar(u0, eltype(p)), u0)
    prob = CryoGridProblem(model, u0_new, tspan, p, savevars=(:T,))
    sol = solve(prob, Euler(), dt=10*60.0)
    return log(abs(sum(sum(sol.u))))
end

@time res = DiffEqFlux.sciml_train(loss, p, maxiters=1)

Trace (reeeealllly long... wouldn't fit here): https://gist.github.com/bgroenks96/501f30e34724ad7e243b4aee14db726a

Julia version info:

Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-9700K CPU @ 3.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

Enzyme:

(@v1.6) pkg> status Enzyme
      Status `~/.julia/environments/v1.6/Project.toml`
  [7da242da] Enzyme v0.8.1

Edit: Probably not relevant to this issue, but there was an error in the loss function as written. It should be scalar and sum(sol.u) is a vector.

bgroenks96 avatar Jan 23 '22 18:01 bgroenks96

declare nonnull {} addrspace(10)* @jl_f_getfield({} addrspace(10)*, {} addrspace(10)**, i32)

We should add the adjoint for this

wsmoses avatar Jan 23 '22 18:01 wsmoses

getfield?

bgroenks96 avatar Jan 23 '22 18:01 bgroenks96

Fixed by https://github.com/EnzymeAD/Enzyme.jl/pull/806

wsmoses avatar May 03 '23 21:05 wsmoses