Skip to content

Commit be97e6b

Browse files
test: test jacobian exactness
1 parent b6c67ba commit be97e6b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

test/jacobiansparsity.jl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = false)
8383
prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
8484
@test eltype(prob.f.jac_prototype) == Float32
8585

86+
t = ModelingToolkit.t_nounits
87+
D = ModelingToolkit.D_nounits
88+
8689
@testset "W matrix sparsity" begin
87-
t = ModelingToolkit.t_nounits
88-
D = ModelingToolkit.D_nounits
8990
@parameters g
9091
@variables x(t) y(t) λ(t)
9192
eqs = [D(D(x)) ~ λ * x
@@ -116,3 +117,20 @@ prob = ODEProblem(sys, u0, (0, 11.5), sparse = true, jac = true)
116117
@test W!(similar(W_prototype, Float64), u, p, γ, t) ==
117118
0.1 * M + jac!(similar(W_prototype, Float64), u, p, t)
118119
end
120+
121+
@testset "Issue#3556: Numerical accuracy" begin
122+
@parameters g
123+
@variables x(t) y(t) [state_priority = 10] λ(t)
124+
eqs = [D(D(x)) ~ λ * x
125+
D(D(y)) ~ λ * y - g
126+
x^2 + y^2 ~ 1]
127+
@mtkbuild pend = ODESystem(eqs, t)
128+
prob = ODEProblem(pend, [x => 0.0, D(x) => 1.0], (0.0, 1.0), [g => 1.0];
129+
guesses = [y => 1.0, λ => 1.0], jac = true, sparse = true)
130+
J = deepcopy(prob.f.jac_prototype)
131+
prob.f.jac(J, prob.u0, prob.p, 1.0)
132+
# this currently works but may not continue to do so
133+
# see https://github.com/SciML/ModelingToolkit.jl/pull/3556#issuecomment-2792664039
134+
@test J == prob.f.jac(prob.u0, prob.p, 1.0)
135+
@test J prob.f.jac(prob.u0, prob.p, 1.0)
136+
end

0 commit comments

Comments
 (0)