ForwardDiff.jl Jacobian with NonlinearSolve.jl

Hello,
I am new to Julia, so let me know if i’m missing any basics.
I am using NonlinearSolve.jl to solve a nonlinear system, and I wish to take the jacobian of this solution with respect to input parameters. The code I have is of the form:

nonlinear_problem = NonlinearProblem(nl_fun, u0, (p1, p2, x0)
function f(x)
    remake(nonlinear_problem,u0,(p1,p2,x)
    sol = solve(nonlinear_problem, NewtonRaphson())
    return sol.u
end

x = x0
y = f(x0)
dy = ForwardDiff.jacobian(f,x0)

This yields a correct solution for y, but dy is all zero. I can verify with finite differencing that the jacobian should not be zero, so I imagine this is some sort of compatibility issue with ForwardDiff.jl and NonlinearSolve.jl, or an issue in how I set up my problem that is failing to allow them to interact in the way I’m intending.

Hi, welcome to the community!
Can you post a complete reproducible example?