src: add AutoSparseDI option for jacobian based on DI - #22
Conversation
| # we use the following instead of TracerSparsityDetector | ||
| # because of searchsortedfirst in POSolution | ||
| # sparsity_detector = TracerLocalSparsityDetector(), | ||
| sparsity_detector = DI.DenseSparsityDetector(backend, atol = 1e-8), |
There was a problem hiding this comment.
Note that this makes the sparsity pattern dependent on the actual values inside the vector, which may not be a good idea?
There was a problem hiding this comment.
I am mostly trying to get this to work for now. Nothing of the above works...
The corresponding test is in test_DI.jl
There was a problem hiding this comment.
Can you paste the error messages you get?
There was a problem hiding this comment.
When using TracerLocalSparsityDetector in SparseDIExt, I get
ERROR: PreparationMismatchError (inconsistent types between preparation and execution):
- f!: ✅
- y: ✅
- backend: ✅
- x: ✅
- contexts: ❌
- prep: Tuple{Constant{PeriodicOrbitOCollProblem{ConstantDDEBifProblem{BifFunction{typeof(Hutchinson), Nothing, Nothing, Nothing, typeof(JacHutchinson), Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Float64, BifurcationKit.Jet{Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing}}, typeof(delaysF), Vector{Float64}, Vector{Float64}, @NamedTuple{a::Float64, d::Int64, τ::Float64, Δ::SparseMatrixCSC{Float64, Int64}, N::Int64}, PropertyLens{:a}, typeof(BifurcationKit.plot_default), typeof(BifurcationKit.record_sol_default), typeof(BifurcationKit.save_solution_default), Float64}, DDEBifurcationKit.AutoSparseDI, Float64, Vector{Float64}, Matrix{Float64}, Nothing}}, Constant{@NamedTuple{a::Float64, d::Int64, τ::Float64, Δ::SparseMatrixCSC{Float64, Int64}, N::Int64}}}
- exec: Tuple{Constant{@NamedTuple{a::Float64, d::Int64, τ::Float64, Δ::SparseMatrixCSC{Float64, Int64}, N::Int64}}}
If you are confident that this check is superfluous, you can disable it by running preparation with the keyword argument `strict=Val(false)` inside DifferentiationInterface.
There was a problem hiding this comment.
Sounds like you're trying to detect sparsity through another differentiation operation?
There was a problem hiding this comment.
No, the function is not.
And for TracerSparsityDetector, I get:
ERROR: TypeError: non-boolean (SparseConnectivityTracer.GradientTracer{Int64, BitSet}) used in boolean context
Stacktrace:
[1] searchsortedfirst
@ ./sort.jl:177 [inlined]
[2] searchsortedfirst
@ ./sort.jl:290 [inlined]
[3] searchsortedfirst
@ ./sort.jl:292 [inlined]
[4] __interpolate_posolution(coll::PeriodicOrbitOCollProblem{…}, t0::SparseConnectivityTracer.GradientTracer{…}, x::Vector{…}, period::Int64)
@ BifurcationKit ~/work/prog_gd/julia/dev/dev1/bkorg/BifurcationKitGITHUB/src/periodicorbit/PeriodicOrbitCollocation.jl:1173
[5] functional_coll!(coll::PeriodicOrbitOCollProblem{…}, outc::Base.ReshapedArray{…}, uc::Base.ReshapedArray{…}, period::SparseConnectivityTracer.GradientTracer{…}, ::Tuple{…}, pars::@NamedTuple{…}, u::Vector{…})
@ DDEBifurcationKit ~/work/prog_gd/julia/dev/dev1/bkorg/DDEBifurcationKit.jl/src/periodicorbit/PeriodicOrbitCollocation.jl:70
[6] residual!(coll::PeriodicOrbitOCollProblem{…}, result::Vector{…}, u::Vector{…}, pars::@NamedTuple{…})
@ DDEBifurcationKit ~/work/prog_gd/julia/dev/dev1/bkorg/DDEBifurcationKit.jl/src/periodicorbit/PeriodicOrbitCollocation.jl:10
[7] coll_residual_for_di!
@ ~/work/prog_gd/julia/dev/dev1/bkorg/DDEBifurcationKit.jl/ext/SparseDIExt.jl:8 [inlined]There was a problem hiding this comment.
| function BK._generate_jacobian(coll::PeriodicOrbitOCollProblem{Tprob}, ::AutoSparseDI, orbitguess, pars; k...) where {Tprob <: AbstractDDEBifurcationProblem} | ||
| error("You need to import `DifferentiationInterface, SparseConnectivityTracer, SparseMatrixColorings` in order to use this jacobian") | ||
| end |
There was a problem hiding this comment.
I find it more idiomatic to throw a MethodError instead, perhaps with an error hint like this one https://github.com/JuliaDiff/DifferentiationInterface.jl/blob/main/DifferentiationInterface/src/init.jl
| DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63" | ||
| SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5" | ||
| SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35" |
No description provided.