Enzyme gives 0 derivative when I use temporary array

Glad you were able to make it work! As a side note, your structs use abstract types for their fields (eg. Array instead of Array{T,N} with parametric T and N), which is a common caveat for performance. It may not be relevant for your use case, but if you go further, do check out the “performance tips” in the Julia manual to learn more!