Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]
4 changes: 2 additions & 2 deletions lib/OrdinaryDiffEqDifferentiation/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "OrdinaryDiffEqDifferentiation"
version = "3.4.0"
version = "3.4.1"
uuid = "4302a76b-040a-498a-8c04-15b101fed76b"
authors = ["Chris Rackauckas <accounts@chrisrackauckas.com>", "Yingbo Ma <mayingbo5@gmail.com>"]

Expand Down Expand Up @@ -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"
Expand Down
25 changes: 10 additions & 15 deletions lib/StochasticDiffEq/test/utility_tests.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -44,36 +44,31 @@ 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,
#=repeat_step=#
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

Expand Down
24 changes: 10 additions & 14 deletions test/InterfaceIII/utility_tests.jl
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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
Expand Down
Loading