From a75048054c1467624382e0d355f3286ceccbc581 Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Mon, 5 May 2025 09:24:48 +0530 Subject: [PATCH 01/17] chore: rebase --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 6891c4fc4..f681662c1 100644 --- a/Project.toml +++ b/Project.toml @@ -135,4 +135,4 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["AlgebraicMultigrid", "Aqua", "Calculus", "ComponentArrays", "DelayDiffEq", "Distributed", "Lux", "ModelingToolkit", "ModelingToolkitStandardLibrary", "Mooncake", "NLsolve", "NonlinearSolve", "Optimization", "OptimizationOptimisers", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "SparseArrays", "SteadyStateDiffEq", "StochasticDiffEq", "Test"] +test = ["AlgebraicMultigrid", "Aqua", "Calculus", "ComponentArrays", "DelayDiffEq", "Distributed", "Lux", "ModelingToolkit", "ModelingToolkitStandardLibrary", "Mooncake", "NLsolve", "NonlinearSolve", "Optimization", "OptimizationOptimisers", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "SparseArrays", "SteadyStateDiffEq", "StochasticDiffEq", "Test"] \ No newline at end of file From e5c9515c2b043aa4c6c373f7dca74ffa78504f25 Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Mon, 5 May 2025 09:25:29 +0530 Subject: [PATCH 02/17] chore: remove literal_getproperty(sol, Val{:u}) --- src/adjoint_common.jl | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/adjoint_common.jl b/src/adjoint_common.jl index 01838ae70..d96cd16a2 100644 --- a/src/adjoint_common.jl +++ b/src/adjoint_common.jl @@ -748,17 +748,3 @@ function out_and_ts(_ts, duplicate_iterator_times, sol) end return out, ts end - -if !hasmethod(Zygote.adjoint, - Tuple{Zygote.AContext, typeof(Zygote.literal_getproperty), - SciMLBase.AbstractTimeseriesSolution, Val{:u}}) - Zygote.@adjoint function Zygote.literal_getproperty(sol::AbstractTimeseriesSolution, - ::Val{:u}) - function solu_adjoint(Δ) - zerou = zero(sol.prob.u0) - _Δ = @. ifelse(Δ === nothing, (zerou,), Δ) - (SciMLBase.build_solution(sol.prob, sol.alg, sol.t, _Δ),) - end - sol.u, solu_adjoint - end -end From 8985fd94e9cd0d7d6ff29630144525bedb4fcf4a Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Mon, 5 May 2025 15:33:52 +0530 Subject: [PATCH 03/17] chore: ybar can be a tangent --- src/concrete_solve.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/concrete_solve.jl b/src/concrete_solve.jl index ba6e0a1bc..621631e1b 100644 --- a/src/concrete_solve.jl +++ b/src/concrete_solve.jl @@ -1581,6 +1581,8 @@ function DiffEqBase._concrete_solve_adjoint( Array(ybar) elseif eltype(ybar) <: AbstractArray Array(VectorOfArray(ybar)) + elseif ybar isa Tangent + Array(VectorOfArray(ybar.u)) else ybar end From 9803adb4f7350715b24a64937e0231ca3e80002d Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 5 May 2025 08:33:46 -0400 Subject: [PATCH 04/17] Fix and validate problems before first call --- test/mtk.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/mtk.jl b/test/mtk.jl index 1f2e3d237..ca89a2ff0 100644 --- a/test/mtk.jl +++ b/test/mtk.jl @@ -70,17 +70,19 @@ tspan = (0.0, 100.0) # and with the initialization corrected to satisfy the algebraic equation prob_incorrectu0 = ODEProblem(sys, u0_incorrect, tspan, p, jac = true, guesses = [w2 => 0.0]) mtkparams_incorrectu0 = SciMLSensitivity.parameter_values(prob_incorrectu0) +test_sol = solve(prob_incorrectu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_timedep = [D(x) => 2.0, x => 1.0, y => t, z => 0.0, - w2 => 0.0,] + w2 => -1.0,] # this ensures that `y => t` is not applied in the adjoint equation # If the MTK init is called for the reverse, then `y0` in the backwards # pass will be extremely far off and cause an incorrect gradient prob_timedepu0 = ODEProblem(sys, u0_timedep, tspan, p, jac = true, guesses = [w2 => 0.0]) mtkparams_timedepu0 = SciMLSensitivity.parameter_values(prob_incorrectu0) +test_sol = solve(prob_timedepu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_correct = [D(x) => 2.0, x => 1.0, @@ -90,6 +92,7 @@ u0_correct = [D(x) => 2.0, prob_correctu0 = ODEProblem(sys, u0_correct, tspan, p, jac = true, guesses = [w2 => -1.0]) mtkparams_correctu0 = SciMLSensitivity.parameter_values(prob_correctu0) prob_correctu0.u0[5] = -1.0 +test_sol = solve(prob_correctu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_overdetermined = [D(x) => 2.0, x => 1.0, From 7f9227b86d6f27f97a8629a4f048d1bfcc0bc7a9 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 5 May 2025 08:46:21 -0400 Subject: [PATCH 05/17] add missing init --- src/concrete_solve.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/concrete_solve.jl b/src/concrete_solve.jl index ba6e0a1bc..55b3ea734 100644 --- a/src/concrete_solve.jl +++ b/src/concrete_solve.jl @@ -677,12 +677,14 @@ function DiffEqBase._concrete_solve_adjoint( dgdu_discrete = df_iip, sensealg = sensealg, callback = cb2, + initializealg = BrownFullBasicInit(), kwargs_init...) else du0, dp = adjoint_sensitivities(sol, alg, args...; t = ts, dgdu_discrete = df_oop, sensealg = sensealg, callback = cb2, + initializealg = BrownFullBasicInit(), kwargs_init...) end From 2f2a94330794ad75a31c625ecd30e9256ab5086b Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 5 May 2025 09:06:45 -0400 Subject: [PATCH 06/17] do not reinit in the extra solve --- src/concrete_solve.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/concrete_solve.jl b/src/concrete_solve.jl index 55b3ea734..2f9873cbe 100644 --- a/src/concrete_solve.jl +++ b/src/concrete_solve.jl @@ -408,7 +408,7 @@ function DiffEqBase._concrete_solve_adjoint( end # Remove callbacks, saveat, etc. from kwargs since it's handled separately - kwargs_fwd = NamedTuple{Base.diff_names(Base._nt_names(values(kwargs)), (:callback,))}(values(kwargs)) + kwargs_fwd = NamedTuple{Base.diff_names(Base._nt_names(values(kwargs)), (:callback, :initializealg))}(values(kwargs)) # Capture the callback_adj for the reverse pass and remove both callbacks kwargs_adj = NamedTuple{ @@ -454,10 +454,11 @@ function DiffEqBase._concrete_solve_adjoint( end igs = back(one(iy))[1] .- one(eltype(tunables)) - igs, new_u0, new_p, SciMLBase.NoInit() + igs, new_u0, new_p, SciMLBase.CheckInit() else nothing, u0, p, initializealg end + _prob = remake(_prob, u0 = new_u0, p = new_p) if sensealg isa BacksolveAdjoint From 9179097d7e04660353e6dad151f55a0e6d20e2a0 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Mon, 5 May 2025 09:12:01 -0400 Subject: [PATCH 07/17] make most tests not overdetermined --- test/mtk.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/mtk.jl b/test/mtk.jl index ca89a2ff0..fbba831f4 100644 --- a/test/mtk.jl +++ b/test/mtk.jl @@ -75,8 +75,7 @@ test_sol = solve(prob_incorrectu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_timedep = [D(x) => 2.0, x => 1.0, y => t, - z => 0.0, - w2 => -1.0,] + z => 0.0] # this ensures that `y => t` is not applied in the adjoint equation # If the MTK init is called for the reverse, then `y0` in the backwards # pass will be extremely far off and cause an incorrect gradient @@ -87,11 +86,9 @@ test_sol = solve(prob_timedepu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_correct = [D(x) => 2.0, x => 1.0, y => 0.0, - z => 0.0, - w2 => -1.0,] + z => 0.0] prob_correctu0 = ODEProblem(sys, u0_correct, tspan, p, jac = true, guesses = [w2 => -1.0]) mtkparams_correctu0 = SciMLSensitivity.parameter_values(prob_correctu0) -prob_correctu0.u0[5] = -1.0 test_sol = solve(prob_correctu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_overdetermined = [D(x) => 2.0, @@ -101,6 +98,7 @@ u0_overdetermined = [D(x) => 2.0, w2 => -1.0,] prob_overdetermined = ODEProblem(sys, u0_overdetermined, tspan, p, jac = true) mtkparams_overdetermined = SciMLSensitivity.parameter_values(prob_overdetermined) +test_sol = solve(prob_overdetermined, Rodas5P(), abstol = 1e-6, reltol = 1e-3) sensealg = GaussAdjoint(; autojacvec = SciMLSensitivity.ZygoteVJP()) From 1567c8d93bec76aa3223efdec95e3b79d0c566e7 Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Mon, 5 May 2025 20:34:47 +0530 Subject: [PATCH 08/17] chore: include getproperty adjoint in there --- src/adjoint_common.jl | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/adjoint_common.jl b/src/adjoint_common.jl index d96cd16a2..609d26528 100644 --- a/src/adjoint_common.jl +++ b/src/adjoint_common.jl @@ -748,3 +748,17 @@ function out_and_ts(_ts, duplicate_iterator_times, sol) end return out, ts end + +if !hasmethod(Zygote.adjoint, + Tuple{Zygote.AContext, typeof(Zygote.literal_getproperty), + SciMLBase.AbstractTimeseriesSolution, Val{:u}}) + Zygote.@adjoint function Zygote.literal_getproperty(sol::AbstractTimeseriesSolution, + ::Val{:u}) + function solu_adjoint(Δ) + zerou = zero(sol.prob.u0) + _Δ = @. ifelse(Δ === nothing, (zerou,), Δ) + (SciMLBase.build_solution(sol.prob, sol.alg, sol.t, _Δ),) + end + sol.u, solu_adjoint + end +end \ No newline at end of file From a94eee2c6963ad6d02be075b6f9436fe655b6fa4 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 6 May 2025 01:31:26 -0400 Subject: [PATCH 09/17] Only BrownBasic ODE and DAE --- Project.toml | 4 ++-- src/concrete_solve.jl | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Project.toml b/Project.toml index f681662c1..bb778d96f 100644 --- a/Project.toml +++ b/Project.toml @@ -77,7 +77,7 @@ LinearAlgebra = "1.10" LinearSolve = "2, 3" Lux = "1" Markdown = "1.10" -ModelingToolkit = "9.74" +ModelingToolkit = "9.77" ModelingToolkitStandardLibrary = "2" Mooncake = "0.4.52" NLsolve = "4.5.1" @@ -135,4 +135,4 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["AlgebraicMultigrid", "Aqua", "Calculus", "ComponentArrays", "DelayDiffEq", "Distributed", "Lux", "ModelingToolkit", "ModelingToolkitStandardLibrary", "Mooncake", "NLsolve", "NonlinearSolve", "Optimization", "OptimizationOptimisers", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "SparseArrays", "SteadyStateDiffEq", "StochasticDiffEq", "Test"] \ No newline at end of file +test = ["AlgebraicMultigrid", "Aqua", "Calculus", "ComponentArrays", "DelayDiffEq", "Distributed", "Lux", "ModelingToolkit", "ModelingToolkitStandardLibrary", "Mooncake", "NLsolve", "NonlinearSolve", "Optimization", "OptimizationOptimisers", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "SparseArrays", "SteadyStateDiffEq", "StochasticDiffEq", "Test"] diff --git a/src/concrete_solve.jl b/src/concrete_solve.jl index 4b716a333..51b99809c 100644 --- a/src/concrete_solve.jl +++ b/src/concrete_solve.jl @@ -673,20 +673,20 @@ function DiffEqBase._concrete_solve_adjoint( else cb2 = cb end - if ArrayInterface.ismutable(eltype(state_values(sol))) + + if prob isa Union{ODEProblem, DAEProblem} du0, dp = adjoint_sensitivities(sol, alg, args...; t = ts, - dgdu_discrete = df_iip, - sensealg = sensealg, - callback = cb2, - initializealg = BrownFullBasicInit(), - kwargs_init...) + dgdu_discrete = ArrayInterface.ismutable(eltype(state_values(sol))) ? df_iip : df_oop, + sensealg = sensealg, + callback = cb2, + initializealg = BrownFullBasicInit(), + kwargs_init...) else du0, dp = adjoint_sensitivities(sol, alg, args...; t = ts, - dgdu_discrete = df_oop, - sensealg = sensealg, - callback = cb2, - initializealg = BrownFullBasicInit(), - kwargs_init...) + dgdu_discrete = ArrayInterface.ismutable(eltype(state_values(sol))) ? df_iip : df_oop, + sensealg = sensealg, + callback = cb2 + kwargs_init...) end du0 = reshape(du0, size(u0)) @@ -1774,7 +1774,8 @@ function DiffEqBase._concrete_solve_adjoint( @. _out[_save_idxs] = Δ.u[_save_idxs] end end - dp = adjoint_sensitivities(sol, alg; sensealg = sensealg, dgdu = df, initializealg = BrownFullBasicInit()) + + dp = adjoint_sensitivities(sol, alg; sensealg = sensealg, dgdu = df) dp, Δtunables = if Δ isa AbstractArray || Δ isa Number # if Δ isa AbstractArray, the gradients correspond to `u` From f60c800830586e467d511ab3853646269ae868ff Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Tue, 6 May 2025 14:41:20 +0530 Subject: [PATCH 10/17] chore: typo --- src/concrete_solve.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/concrete_solve.jl b/src/concrete_solve.jl index 51b99809c..2bc4d65be 100644 --- a/src/concrete_solve.jl +++ b/src/concrete_solve.jl @@ -685,7 +685,7 @@ function DiffEqBase._concrete_solve_adjoint( du0, dp = adjoint_sensitivities(sol, alg, args...; t = ts, dgdu_discrete = ArrayInterface.ismutable(eltype(state_values(sol))) ? df_iip : df_oop, sensealg = sensealg, - callback = cb2 + callback = cb2, kwargs_init...) end From 3d849da703e61a60e272c670636fb3f4ba24e183 Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Tue, 6 May 2025 16:19:31 +0530 Subject: [PATCH 11/17] chore: qualify DAEProblem --- src/SciMLSensitivity.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SciMLSensitivity.jl b/src/SciMLSensitivity.jl index a3569f384..c239f871a 100644 --- a/src/SciMLSensitivity.jl +++ b/src/SciMLSensitivity.jl @@ -33,7 +33,7 @@ using SciMLBase: SciMLBase, AbstractOverloadingSensitivityAlgorithm, AbstractNonlinearProblem, AbstractSensitivityAlgorithm, AbstractDiffEqFunction, AbstractODEFunction, unwrapped_f, CallbackSet, ContinuousCallback, DESolution, NonlinearFunction, NonlinearProblem, - DiscreteCallback, LinearProblem, ODEFunction, ODEProblem, + DiscreteCallback, LinearProblem, ODEFunction, ODEProblem, DAEProblem, RODEFunction, RODEProblem, ReturnCode, SDEFunction, SDEProblem, VectorContinuousCallback, deleteat!, get_tmp_cache, has_adjoint, isinplace, reinit!, remake, From 9bacce8293a2b20222237a9cd9e55c3d4c54f897 Mon Sep 17 00:00:00 2001 From: DhairyaLGandhi Date: Tue, 6 May 2025 17:41:30 +0530 Subject: [PATCH 12/17] test: get grads for ps, mark NoInit as buggy --- test/mtk.jl | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/test/mtk.jl b/test/mtk.jl index fbba831f4..ba30c1c0c 100644 --- a/test/mtk.jl +++ b/test/mtk.jl @@ -86,11 +86,24 @@ test_sol = solve(prob_timedepu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) u0_correct = [D(x) => 2.0, x => 1.0, y => 0.0, - z => 0.0] + z => 0.0,] prob_correctu0 = ODEProblem(sys, u0_correct, tspan, p, jac = true, guesses = [w2 => -1.0]) mtkparams_correctu0 = SciMLSensitivity.parameter_values(prob_correctu0) test_sol = solve(prob_correctu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) +u0_gt = [D(x) => 2.0, + x => 1.0, + y => 0.0, + z => 0.0, + w2 => -1.0,] +# The initialization might be over determined, but that is necessary as we +# will force DAE initialization to not run via CheckInit. CheckInit will +# still need to check that the algebraic equations are satisfied, so we need to +# make sure that the initialization is correct +prob_gtu0 = ODEProblem(sys, u0_gt, tspan, p, jac = true) +mtkparams_gtu0 = SciMLSensitivity.parameter_values(prob_gtu0) +test_sol = solve(prob_gtu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) + u0_overdetermined = [D(x) => 2.0, x => 1.0, y => 0.0, @@ -103,7 +116,7 @@ test_sol = solve(prob_overdetermined, Rodas5P(), abstol = 1e-6, reltol = 1e-3) sensealg = GaussAdjoint(; autojacvec = SciMLSensitivity.ZygoteVJP()) setups = [ - (prob_correctu0, mtkparams_correctu0, CheckInit()), # Source of truth first + (prob_gtu0, mtkparams_gtu0, CheckInit()), # Source of truth first (prob_incorrectu0, mtkparams_incorrectu0, BrownFullBasicInit()), (prob_incorrectu0, mtkparams_incorrectu0, OrdinaryDiffEqCore.DefaultInit()), @@ -116,7 +129,7 @@ setups = [ (prob_correctu0, mtkparams_correctu0, BrownFullBasicInit()), (prob_correctu0, mtkparams_correctu0, OrdinaryDiffEqCore.DefaultInit()), - (prob_correctu0, mtkparams_correctu0, NoInit()), + # (prob_correctu0, mtkparams_correctu0, NoInit()), (prob_correctu0, mtkparams_correctu0, nothing), (prob_overdetermined, mtkparams_overdetermined, BrownFullBasicInit()), @@ -124,17 +137,18 @@ setups = [ (prob_overdetermined, mtkparams_overdetermined, NoInit()), (prob_overdetermined, mtkparams_overdetermined, nothing), -] +]; grads = map(setups) do setup prob, ps, init = setup @show init u0 = prob.u0 Zygote.gradient(u0, ps) do u0,p + new_prob = remake(prob, u0 = u0, p = p) if init === nothing - new_sol = solve(prob, Rodas5P(); u0 = u0, p = ps, sensealg, abstol = 1e-6, reltol = 1e-3) + new_sol = solve(new_prob, Rodas5P(); sensealg, abstol = 1e-6, reltol = 1e-3) else - new_sol = solve(prob, Rodas5P(); u0 = u0, p = ps, initializealg = init, sensealg, abstol = 1e-6, reltol = 1e-3) + new_sol = solve(new_prob, Rodas5P(); initializealg = init, sensealg, abstol = 1e-6, reltol = 1e-3) end gt = Zygote.ChainRules.ChainRulesCore.ignore_derivatives() do @test new_sol.retcode == SciMLBase.ReturnCode.Success @@ -149,5 +163,5 @@ end u0grads = getindex.(grads,1) pgrads = getproperty.(getindex.(grads, 2), (:tunable,)) -@test all(x ≈ u0grads[1] for x in grads) -@test all(x ≈ pgrads[1] for x in grads) +@test all(x ≈ u0grads[1] for x in u0grads) +@test all(x ≈ pgrads[1] for x in pgrads) From 6fcfe7bf91e42e1a60de4b69fddc22dd12dcafad Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 6 May 2025 08:48:26 -0400 Subject: [PATCH 13/17] Update test/mtk.jl --- test/mtk.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mtk.jl b/test/mtk.jl index ba30c1c0c..936ce6b97 100644 --- a/test/mtk.jl +++ b/test/mtk.jl @@ -129,7 +129,7 @@ setups = [ (prob_correctu0, mtkparams_correctu0, BrownFullBasicInit()), (prob_correctu0, mtkparams_correctu0, OrdinaryDiffEqCore.DefaultInit()), - # (prob_correctu0, mtkparams_correctu0, NoInit()), + (prob_correctu0, mtkparams_correctu0, NoInit()), (prob_correctu0, mtkparams_correctu0, nothing), (prob_overdetermined, mtkparams_overdetermined, BrownFullBasicInit()), From f78be3ff00edc6241ddbad5055c93160f7529b84 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 6 May 2025 08:49:09 -0400 Subject: [PATCH 14/17] Update test/mtk.jl --- test/mtk.jl | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/test/mtk.jl b/test/mtk.jl index 936ce6b97..8c8852d86 100644 --- a/test/mtk.jl +++ b/test/mtk.jl @@ -90,20 +90,6 @@ u0_correct = [D(x) => 2.0, prob_correctu0 = ODEProblem(sys, u0_correct, tspan, p, jac = true, guesses = [w2 => -1.0]) mtkparams_correctu0 = SciMLSensitivity.parameter_values(prob_correctu0) test_sol = solve(prob_correctu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) - -u0_gt = [D(x) => 2.0, - x => 1.0, - y => 0.0, - z => 0.0, - w2 => -1.0,] -# The initialization might be over determined, but that is necessary as we -# will force DAE initialization to not run via CheckInit. CheckInit will -# still need to check that the algebraic equations are satisfied, so we need to -# make sure that the initialization is correct -prob_gtu0 = ODEProblem(sys, u0_gt, tspan, p, jac = true) -mtkparams_gtu0 = SciMLSensitivity.parameter_values(prob_gtu0) -test_sol = solve(prob_gtu0, Rodas5P(), abstol = 1e-6, reltol = 1e-3) - u0_overdetermined = [D(x) => 2.0, x => 1.0, y => 0.0, From 2deb8f796d4780197012875e07ab0a379d3935c2 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 6 May 2025 08:49:34 -0400 Subject: [PATCH 15/17] Update test/mtk.jl --- test/mtk.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/mtk.jl b/test/mtk.jl index 8c8852d86..fbd088dbf 100644 --- a/test/mtk.jl +++ b/test/mtk.jl @@ -102,7 +102,7 @@ test_sol = solve(prob_overdetermined, Rodas5P(), abstol = 1e-6, reltol = 1e-3) sensealg = GaussAdjoint(; autojacvec = SciMLSensitivity.ZygoteVJP()) setups = [ - (prob_gtu0, mtkparams_gtu0, CheckInit()), # Source of truth first + (prob_correctu0, mtkparams_correctu0, CheckInit()), # Source of truth first (prob_incorrectu0, mtkparams_incorrectu0, BrownFullBasicInit()), (prob_incorrectu0, mtkparams_incorrectu0, OrdinaryDiffEqCore.DefaultInit()), From 69f2938c163f1bb7d7d18cbbbac10b1febba0239 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Tue, 6 May 2025 11:32:31 -0400 Subject: [PATCH 16/17] Update desauty_dae_mwe.jl --- test/desauty_dae_mwe.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/desauty_dae_mwe.jl b/test/desauty_dae_mwe.jl index 68baa0277..c40539675 100644 --- a/test/desauty_dae_mwe.jl +++ b/test/desauty_dae_mwe.jl @@ -36,7 +36,7 @@ desauty_model = create_model() sys = structural_simplify(desauty_model) -prob = ODEProblem(sys, [], (0.0, 0.1), guesses = [sys.resistor1.v => 1.]) +prob = ODEProblem(sys, [sys.resistor1.v => 1.], (0.0, 0.1)) iprob = prob.f.initialization_data.initializeprob isys = iprob.f.sys From 93d97c8d64b86992e55bd67407408610186ca150 Mon Sep 17 00:00:00 2001 From: Dhairya Gandhi Date: Wed, 7 May 2025 01:39:34 +0530 Subject: [PATCH 17/17] Update Project.toml Co-authored-by: Aayush Sabharwal --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index bb778d96f..5207a51ce 100644 --- a/Project.toml +++ b/Project.toml @@ -77,7 +77,7 @@ LinearAlgebra = "1.10" LinearSolve = "2, 3" Lux = "1" Markdown = "1.10" -ModelingToolkit = "9.77" +ModelingToolkit = "9.78" ModelingToolkitStandardLibrary = "2" Mooncake = "0.4.52" NLsolve = "4.5.1"