diff --git a/Project.toml b/Project.toml index 176c2a4065..aa3b5b44f9 100644 --- a/Project.toml +++ b/Project.toml @@ -121,6 +121,7 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd" RecursiveFactorization = "f2c3362d-daeb-58d1-803e-2bc74f2840b4" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283" +SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961" StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SparseConnectivityTracer = "9f842d2f-2579-4b1d-911e-f412cf18a3f5" @@ -133,4 +134,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [targets] -test = ["ADTypes", "ArrayInterface", "ComponentArrays", "AlgebraicMultigrid", "DiffEqBase", "DiffEqCallbacks", "DifferentiationInterface", "DiffEqDevTools", "ExplicitImports", "ForwardDiff", "IncompleteLU", "InteractiveUtils", "LinearAlgebra", "LinearSolve", "ODEProblemLibrary", "OrdinaryDiffEqAdamsBashforthMoulton", "OrdinaryDiffEqDifferentiation", "OrdinaryDiffEqExplicitRK", "OrdinaryDiffEqExplicitTableaus", "OrdinaryDiffEqExponentialRK", "OrdinaryDiffEqExtrapolation", "OrdinaryDiffEqFIRK", "OrdinaryDiffEqFeagin", "OrdinaryDiffEqFunctionMap", "OrdinaryDiffEqHighOrderRK", "OrdinaryDiffEqIMEXMultistep", "OrdinaryDiffEqLinear", "OrdinaryDiffEqLowOrderRK", "OrdinaryDiffEqLowStorageRK", "NonlinearSolve", "OrdinaryDiffEqNonlinearSolve", "OrdinaryDiffEqNordsieck", "OrdinaryDiffEqPDIRK", "OrdinaryDiffEqPRK", "OrdinaryDiffEqQPRK", "OrdinaryDiffEqRKN", "OrdinaryDiffEqSDIRK", "OrdinaryDiffEqSSPRK", "OrdinaryDiffEqStabilizedIRK", "OrdinaryDiffEqStabilizedRK", "OrdinaryDiffEqSymplecticRK", "ElasticArrays", "JLArrays", "Random", "SafeTestsets", "SciMLTesting", "StableRNGs", "StructArrays", "Test", "Unitful", "Pkg", "RecursiveArrayTools", "RecursiveFactorization", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings", "StaticArrays", "Statistics"] +test = ["ADTypes", "ArrayInterface", "ComponentArrays", "AlgebraicMultigrid", "DiffEqBase", "DiffEqCallbacks", "DifferentiationInterface", "DiffEqDevTools", "ExplicitImports", "ForwardDiff", "IncompleteLU", "InteractiveUtils", "LinearAlgebra", "LinearSolve", "ODEProblemLibrary", "OrdinaryDiffEqAdamsBashforthMoulton", "OrdinaryDiffEqDifferentiation", "OrdinaryDiffEqExplicitRK", "OrdinaryDiffEqExplicitTableaus", "OrdinaryDiffEqExponentialRK", "OrdinaryDiffEqExtrapolation", "OrdinaryDiffEqFIRK", "OrdinaryDiffEqFeagin", "OrdinaryDiffEqFunctionMap", "OrdinaryDiffEqHighOrderRK", "OrdinaryDiffEqIMEXMultistep", "OrdinaryDiffEqLinear", "OrdinaryDiffEqLowOrderRK", "OrdinaryDiffEqLowStorageRK", "NonlinearSolve", "OrdinaryDiffEqNonlinearSolve", "OrdinaryDiffEqNordsieck", "OrdinaryDiffEqPDIRK", "OrdinaryDiffEqPRK", "OrdinaryDiffEqQPRK", "OrdinaryDiffEqRKN", "OrdinaryDiffEqSDIRK", "OrdinaryDiffEqSSPRK", "OrdinaryDiffEqStabilizedIRK", "OrdinaryDiffEqStabilizedRK", "OrdinaryDiffEqSymplecticRK", "ElasticArrays", "JLArrays", "Random", "SafeTestsets", "SciMLOperators", "SciMLTesting", "StableRNGs", "StructArrays", "Test", "Unitful", "Pkg", "RecursiveArrayTools", "RecursiveFactorization", "SparseArrays", "SparseConnectivityTracer", "SparseMatrixColorings", "StaticArrays", "Statistics"] diff --git a/lib/OrdinaryDiffEqDifferentiation/Project.toml b/lib/OrdinaryDiffEqDifferentiation/Project.toml index eceac847db..6c9adfa3b0 100644 --- a/lib/OrdinaryDiffEqDifferentiation/Project.toml +++ b/lib/OrdinaryDiffEqDifferentiation/Project.toml @@ -1,5 +1,5 @@ name = "OrdinaryDiffEqDifferentiation" -version = "3.4.0" +version = "3.4.1" uuid = "4302a76b-040a-498a-8c04-15b101fed76b" authors = ["Chris Rackauckas ", "Yingbo Ma "] @@ -40,7 +40,7 @@ julia = "1.10" ADTypes = "1.22.0" DiffEqBase = "7" SafeTestsets = "0.1.0" -SciMLOperators = "1.24.3" +SciMLOperators = "1.24.4" [weakdeps] SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" diff --git a/lib/StochasticDiffEq/test/utility_tests.jl b/lib/StochasticDiffEq/test/utility_tests.jl index 0ff9166333..c0290a5abd 100644 --- a/lib/StochasticDiffEq/test/utility_tests.jl +++ b/lib/StochasticDiffEq/test/utility_tests.jl @@ -1,6 +1,6 @@ using StochasticDiffEq, LinearAlgebra, SparseArrays, Random, LinearSolve, Test using OrdinaryDiffEqDifferentiation: OrdinaryDiffEqDifferentiation, calc_W!, calc_W -using SciMLOperators: MatrixOperator, WOperator +using SciMLOperators: MatrixOperator using OrdinaryDiffEq #horid nasty hack to deal with temporary calc_W refactor @@ -44,16 +44,19 @@ end @test W \ u0 ≈ concrete_W \ u0 # In-place + jacobian_updates = Ref(0) + update_jacobian!(J, u, p, t) = (jacobian_updates[] += 1; copyto!(J, A)) _f = (du, u, p, t) -> mul!(du, A, u) _g = (du, u, p, t) -> mul!(du, σ, u) fun = SDEFunction( _f, _g; mass_matrix = mm, - jac_prototype = MatrixOperator(A) + jac_prototype = MatrixOperator(copy(A); update_func! = update_jacobian!) ) prob = SDEProblem(fun, u0, tspan) integrator = init(prob, ImplicitEM(theta = 1); adaptive = false, dt = dt) W = integrator.cache.nlsolver.cache.W + updates_before_calc_W = jacobian_updates[] calc_W!( W, integrator, integrator.cache.nlsolver, integrator.cache, dtgamma, @@ -61,19 +64,11 @@ end false ) - # Did not update because it's an array operator - # We don't want to build Jacobians when we have operators! - @test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) != concrete_W - ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0) - @test tmp != concrete_W \ u0 - - # But jacobian2W! will update the cache - OrdinaryDiffEqDifferentiation.jacobian2W!( - integrator.cache.nlsolver.cache.W._concrete_form, - mm, dtgamma, integrator.cache.nlsolver.cache.W.J.A - ) - @test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) == concrete_W - ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0) + # The operator already represents the Jacobian, so calc_W! only updates its + # coefficient and leaves the Jacobian callback untouched. + @test jacobian_updates[] == updates_before_calc_W + @test convert(AbstractMatrix, W) == concrete_W + ldiv!(tmp, lu!(W), u0) @test tmp == concrete_W \ u0 end diff --git a/test/InterfaceIII/utility_tests.jl b/test/InterfaceIII/utility_tests.jl index 51884647e3..b7a9918b87 100644 --- a/test/InterfaceIII/utility_tests.jl +++ b/test/InterfaceIII/utility_tests.jl @@ -1,7 +1,8 @@ -using OrdinaryDiffEq, LinearAlgebra, SparseArrays, Random, Test, LinearSolve +using OrdinaryDiffEq, LinearAlgebra, SparseArrays, Random, Test using OrdinaryDiffEqRosenbrock: OrdinaryDiffEqDifferentiation -using OrdinaryDiffEqDifferentiation: WOperator, calc_W, calc_W!, jacobian2W! +using OrdinaryDiffEqDifferentiation: calc_W, calc_W! using OrdinaryDiffEqSDIRK +using SciMLOperators: MatrixOperator @testset "calc_W and calc_W!" begin A = [-1.0 0.0; 0.0 -0.5] @@ -28,31 +29,26 @@ using OrdinaryDiffEqSDIRK @test W \ u0 ≈ concrete_W \ u0 # In-place + jacobian_updates = Ref(0) + update_jacobian!(J, u, p, t) = (jacobian_updates[] += 1; copyto!(J, A)) fun = ODEFunction( (du, u, p, t) -> mul!(du, A, u); mass_matrix = mm, - jac_prototype = MatrixOperator(A) + jac_prototype = MatrixOperator(copy(A); update_func! = update_jacobian!) ) integrator = init( ODEProblem(fun, u0, tspan), ImplicitEuler(); adaptive = false, dt = dt ) + updates_before_calc_W = jacobian_updates[] calc_W!( integrator.cache.nlsolver.cache.W, integrator, integrator.cache.nlsolver, integrator.cache, dtgamma, false ) - # Did not update because it's an array operator - # We don't want to build Jacobians when we have operators! - @test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) != concrete_W - ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0) - @test tmp != concrete_W \ u0 - - # But jacobian2W! will update the cache - jacobian2W!( - integrator.cache.nlsolver.cache.W._concrete_form, mm, - dtgamma, integrator.cache.nlsolver.cache.W.J.A - ) + # The operator already represents the Jacobian, so calc_W! only updates its + # coefficient and leaves the Jacobian callback untouched. + @test jacobian_updates[] == updates_before_calc_W @test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) == concrete_W ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0) @test tmp == concrete_W \ u0