Skip to content

TracerSparsityDetector + in-place RHS cache fails #737

@SouthEndMusic

Description

@SouthEndMusic

I would expect DifferentiationInterface.jl to internally make a copy of p with the right type for SCT.

MWE:

using ADTypes: AutoForwardDiff
using DifferentiationInterface: AutoSparse, Cache, prepare_jacobian
using SparseConnectivityTracer: TracerSparsityDetector
using SparseMatrixColorings: GreedyColoringAlgorithm
using ForwardDiff

function f!(du, u, p)
    p[1] = u[1]
    du[1] = -3.0 * p[1]
end

backend = AutoSparse(
    AutoForwardDiff();
    sparsity_detector=TracerSparsityDetector(),
    coloring_algorithm=GreedyColoringAlgorithm(),
)

du = zeros(1)
u = ones(1)
p = [3.0]

prep = prepare_jacobian(f!, du, backend, u, Cache(p))

Stacktrace:

ERROR: TypeError: in typeassert, expected Float64, got a value of type SparseConnectivityTracer.GradientTracer{SparseConnectivityTracer.IndexSetGradientPattern{Int64, BitSet}}
Stacktrace:
 [1] setindex!(A::Vector{…}, x::SparseConnectivityTracer.GradientTracer{…}, i::Int64)
   @ Base .\array.jl:987
 [2] f!(du::Vector{…}, u::Vector{…}, p::Vector{…})
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions