Skip to content

Commit 94ff612

Browse files
committed
Add test
1 parent 55e607b commit 94ff612

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/extensions/ad.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Zygote
44
using SymbolicIndexingInterface
55
using SciMLStructures
66
using OrdinaryDiffEq
7+
using NonlinearSolve
78
using SciMLSensitivity
89
using ForwardDiff
910
using ChainRulesCore
@@ -103,3 +104,22 @@ vals = (1.0f0, 3ones(Float32, 3))
103104
tangent = rand_tangent(ps)
104105
fwd, back = ChainRulesCore.rrule(remake_buffer, sys, ps, idxs, vals)
105106
@inferred back(tangent)
107+
108+
@testset "Dual type promotion in remake with dummy derivatives" begin # https://github.com/SciML/ModelingToolkit.jl/issues/3336
109+
# Throw ball straight up into the air
110+
@variables y(t)
111+
eqs = [D(D(y)) ~ -9.81]
112+
initialization_eqs = [y^2 ~ 0] # initialize y = 0 in a way that builds an initialization problem
113+
@named sys = ODESystem(eqs, t; initialization_eqs)
114+
sys = structural_simplify(sys)
115+
116+
# Find initial throw velocity that reaches exactly 10 m after 1 s
117+
dprob0 = ODEProblem(sys, [D(y) => NaN], (0.0, 1.0), []; guesses = [y => 0.0])
118+
nprob = NonlinearProblem((ics, _) -> begin
119+
dprob = remake(dprob0, u0 = Dict(D(y) => ics[1]))
120+
dsol = solve(dprob, Tsit5())
121+
return [dsol[y][end] - 10.0]
122+
end, [1.0])
123+
nsol = solve(nprob, NewtonRaphson())
124+
@test nsol[1] 10.0/1.0 + 9.81*1.0/2 # anal free fall solution is y = v0*t - g*t^2/2 -> v0 = y/t + g*t/2
125+
end

0 commit comments

Comments
 (0)