See the discussion in https://discourse.julialang.org/t/automatic-differentiation-of-function-using-linearproblem/136063