Skip to content

Tagcount ordering across precompiled packages- expected behavior? #801

@AdityaPandeyCN

Description

@AdityaPandeyCN

I'm hitting a nested ForwardDiff issue where < returns the wrong tag ordering when NonlinearSolve (outer) differentiates through OrdinaryDiffEq's Rosenbrock23 (inner ForwardDiff Jacobian). Gives MethodError: no method matching Float64(::Dual{...}) from the Dual nesting being flipped.

using OrdinaryDiffEqRosenbrock, NonlinearSolve

function ode(du, u, p, t)
    du[1] = -p[1] * u[1]
    du[2] = -u[1] - p[2] * u[2]
end

ode_f = ODEFunction{true, SciMLBase.FullSpecialize}(ode)
function solve_ode(p)
    prob = ODEProblem(ode_f, [1.0, 1.0], (0.0, 10.0), p)
    solve(prob, Rosenbrock23())
end

experiment = solve_ode([1.5, 2.0])
function resid!(du, p, nlparams)
    sol = solve_ode(p)
    du .= sol.(experiment.t, idxs=1) .- experiment[1, :]
end

res_prototype = zeros(length(experiment.t))
resid!(res_prototype, [1.0, 1.0], nothing)
nls = NonlinearFunction{true, SciMLBase.FullSpecialize}(resid!, resid_prototype=res_prototype)
prob = NonlinearLeastSquaresProblem(nls, [1.0, 1.0])
solve(prob, LevenbergMarquardt())  # errors

< returns the wrong ordering when two different packages nest ForwardDiff calls. NonlinearSolve (outer) creates its tag first, OrdinaryDiffEq's Rosenbrock23 (inner) creates its tag second, but tagcount gives the inner tag a lower number than the outer tag. This flips the Dual nesting and causes Float64(::Dual{...}) errors.

Can anyone confirm this on their behalf?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions