Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream #19

Merged
merged 23 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
4fe6c3a
Bump codecov/codecov-action from 4 to 5
dependabot[bot] Nov 18, 2024
34a49c1
Merge pull request #2536 from SciML/dependabot/github_actions/codecov…
ChrisRackauckas Nov 18, 2024
8cad990
Adopt KrylovSubspace Vtype to u
mcarmesin Nov 18, 2024
28313cd
Update Project.toml
ChrisRackauckas Nov 19, 2024
52bcf16
Merge pull request #2539 from Shreyas-Ekanathan/master
ChrisRackauckas Nov 19, 2024
9ab927b
Merge pull request #2538 from mcarmesin/master
ChrisRackauckas Nov 19, 2024
f86d0ea
refactor: generalize `_initialize_dae!` to use SciMLBase implementations
AayushSabharwal Nov 11, 2024
8f9a1b2
build: bump SciMLBase compat
AayushSabharwal Nov 19, 2024
349bfcd
test: fix `CheckInit` tests
AayushSabharwal Nov 20, 2024
c7b28ff
Update CI.yml
ChrisRackauckas Nov 20, 2024
4ecb539
Merge pull request #2521 from AayushSabharwal/as/rework-init
ChrisRackauckas Nov 20, 2024
e01d9c2
Update Project.toml
ChrisRackauckas Nov 20, 2024
7e4c005
Update Project.toml
ChrisRackauckas Nov 20, 2024
79ff531
Update Project.toml
ChrisRackauckas Nov 20, 2024
7fa3072
fix type stability for DefaultCache
oscardssmith Nov 21, 2024
64defc0
add test
oscardssmith Nov 21, 2024
9428251
fix: fix call to `get_initial_values`
AayushSabharwal Nov 21, 2024
b1bfed0
Merge pull request #2541 from AayushSabharwal/as/hotfix
ChrisRackauckas Nov 21, 2024
9799ee1
Update Project.toml
ChrisRackauckas Nov 21, 2024
1b537a0
Merge pull request #2540 from oscardssmith/os/fix-DefaultCache-type-s…
ChrisRackauckas Nov 21, 2024
c9cfa4f
Simplify RadauTableau Generation redux
oscardssmith Nov 21, 2024
2da1bca
fix ci
oscardssmith Nov 24, 2024
14e6cb6
Merge pull request #2543 from oscardssmith/os/radau-simplification2
ChrisRackauckas Nov 26, 2024
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
5 changes: 2 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
- OrdinaryDiffEqExponentialRK
- OrdinaryDiffEqExtrapolation
- OrdinaryDiffEqFIRK
- OrdinaryDiffEqFIRKGenerator
- OrdinaryDiffEqFeagin
- OrdinaryDiffEqFunctionMap
- OrdinaryDiffEqHighOrderRK
Expand Down Expand Up @@ -91,8 +90,8 @@ jobs:
env:
GROUP: ${{ matrix.group }}
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: lcov.info
fail_ci_if_error: true
fail_ci_if_error: false
2 changes: 1 addition & 1 deletion .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ --code-coverage=user docs/make.jl
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: lcov.info
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/Downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
exit(0) # Exit immediately, as a success
end
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v4
- uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: lcov.info
Expand Down
4 changes: 2 additions & 2 deletions lib/OrdinaryDiffEqCore/Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OrdinaryDiffEqCore"
uuid = "bbf590c4-e513-4bbe-9b18-05decba2e5d8"
authors = ["ParamThakkar123 <[email protected]>"]
version = "1.11.0"
version = "1.12.1"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down Expand Up @@ -70,7 +70,7 @@ Random = "<0.0.1, 1"
RecursiveArrayTools = "2.36, 3"
Reexport = "1.0"
SafeTestsets = "0.1.0"
SciMLBase = "2.60"
SciMLBase = "2.62"
SciMLOperators = "0.3"
SciMLStructures = "1"
SimpleUnPack = "1"
Expand Down
2 changes: 1 addition & 1 deletion lib/OrdinaryDiffEqCore/src/OrdinaryDiffEqCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ using DiffEqBase: check_error!, @def, _vec, _reshape

using FastBroadcast: @.., True, False

using SciMLBase: NoInit, CheckInit, _unwrap_val
using SciMLBase: NoInit, CheckInit, OverrideInit, AbstractDEProblem, _unwrap_val

import SciMLBase: alg_order

Expand Down
3 changes: 2 additions & 1 deletion lib/OrdinaryDiffEqCore/src/caches/basic_caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ function alg_cache(alg::CompositeAlgorithm{CS, Tuple{A1, A2, A3, A4, A5, A6}}, u
args = (u, rate_prototype, uEltypeNoUnits,
uBottomEltypeNoUnits, tTypeNoUnits, uprev, uprev2, f, t, dt,
reltol, p, calck, Val(V))
argT = map(typeof, args)
# Core.Typeof to turn uEltypeNoUnits into Type{uEltypeNoUnits} rather than DataType
argT = map(Core.Typeof, args)
T1 = Base.promote_op(alg_cache, A1, argT...)
T2 = Base.promote_op(alg_cache, A2, argT...)
T3 = Base.promote_op(alg_cache, A3, argT...)
Expand Down
18 changes: 16 additions & 2 deletions lib/OrdinaryDiffEqCore/src/dense/generic_dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ function default_ode_interpolant(
return ode_interpolant(Θ, integrator.dt, integrator.uprev,
integrator.u, integrator.k, cache.cache5, idxs,
deriv, integrator.differential_vars)
else # alg_choice == 6
elseif alg_choice == 6
return ode_interpolant(Θ, integrator.dt, integrator.uprev,
integrator.u, integrator.k, cache.cache6, idxs,
deriv, integrator.differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
end

Expand Down Expand Up @@ -227,6 +229,8 @@ end
ode_interpolant!(val, Θ, integrator.dt, integrator.uprev, integrator.u,
integrator.k, integrator.cache.cache6,
idxs, deriv, integrator.differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
else
ode_interpolant!(val, Θ, integrator.dt, integrator.uprev, integrator.u,
Expand Down Expand Up @@ -256,10 +260,12 @@ function default_ode_interpolant!(
return ode_interpolant!(val, Θ, integrator.dt, integrator.uprev,
integrator.u, integrator.k, cache.cache5, idxs,
deriv, integrator.differential_vars)
else # alg_choice == 6
elseif alg_choice == 6
return ode_interpolant!(val, Θ, integrator.dt, integrator.uprev,
integrator.u, integrator.k, cache.cache6, idxs,
deriv, integrator.differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
end

Expand Down Expand Up @@ -380,6 +386,8 @@ function default_ode_extrapolant!(
ode_interpolant!(val, Θ, integrator.t - integrator.tprev,
integrator.uprev2, integrator.uprev,
integrator.k, cache.cache6, idxs, deriv, integrator.differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
end

Expand Down Expand Up @@ -444,6 +452,8 @@ function default_ode_extrapolant(
ode_interpolant(Θ, integrator.t - integrator.tprev,
integrator.uprev2, integrator.uprev,
integrator.k, cache.cache6, idxs, deriv, integrator.differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
end

Expand Down Expand Up @@ -810,6 +820,8 @@ function ode_interpolation(tval::Number, id::I, idxs, deriv::D, p,
cache.cache6) # update the kcurrent
val = ode_interpolant(Θ, dt, timeseries[i₋], timeseries[i₊], ks[i₊],
cache.cache6, idxs, deriv, differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
else
_ode_addsteps!(ks[i₊], ts[i₋], timeseries[i₋], timeseries[i₊], dt, f, p,
Expand Down Expand Up @@ -892,6 +904,8 @@ function ode_interpolation!(out, tval::Number, id::I, idxs, deriv::D, p,
cache.cache6) # update the kcurrent
ode_interpolant!(out, Θ, dt, timeseries[i₋], timeseries[i₊], ks[i₊],
cache.cache6, idxs, deriv, differential_vars)
else
error("DefaultCache invalid alg_choice. File an issue.")
end
else
_ode_addsteps!(ks[i₊], ts[i₋], timeseries[i₋], timeseries[i₊], dt, f, p,
Expand Down
123 changes: 17 additions & 106 deletions lib/OrdinaryDiffEqCore/src/initialize_dae.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ function BrownFullBasicInit(; abstol = 1e-10, nlsolve = nothing)
end
BrownFullBasicInit(abstol) = BrownFullBasicInit(; abstol = abstol, nlsolve = nothing)

struct OverrideInit{T, F} <: DiffEqBase.DAEInitializationAlgorithm
abstol::T
nlsolve::F
end

function OverrideInit(; abstol = 1e-10, nlsolve = nothing)
OverrideInit(abstol, nlsolve)
end
OverrideInit(abstol) = OverrideInit(; abstol = abstol, nlsolve = nothing)

## Notes

#=
Expand Down Expand Up @@ -143,19 +133,15 @@ end

## NoInit

function _initialize_dae!(integrator, prob::Union{ODEProblem, DAEProblem},
function _initialize_dae!(integrator, prob::AbstractDEProblem,
alg::NoInit, x::Union{Val{true}, Val{false}})
end

## OverrideInit

function _initialize_dae!(integrator, prob::Union{ODEProblem, DAEProblem},
function _initialize_dae!(integrator, prob::AbstractDEProblem,
alg::OverrideInit, isinplace::Union{Val{true}, Val{false}})
initializeprob = prob.f.initializeprob

if SciMLBase.has_update_initializeprob!(prob.f)
prob.f.update_initializeprob!(initializeprob, prob)
end
initializeprob = prob.f.initialization_data.initializeprob

# If it doesn't have autodiff, assume it comes from symbolic system like ModelingToolkit
# Since then it's the case of not a DAE but has initializeprob
Expand All @@ -168,105 +154,30 @@ function _initialize_dae!(integrator, prob::Union{ODEProblem, DAEProblem},
true
end

alg = default_nlsolve(alg.nlsolve, isinplace, initializeprob.u0, initializeprob, isAD)
nlsol = solve(initializeprob, alg, abstol = integrator.opts.abstol, reltol = integrator.opts.reltol)
nlsolve_alg = default_nlsolve(alg.nlsolve, isinplace, initializeprob.u0, initializeprob, isAD)

u0, p, success = SciMLBase.get_initial_values(prob, integrator, prob.f, alg, isinplace; nlsolve_alg, abstol = integrator.opts.abstol, reltol = integrator.opts.reltol)

if isinplace === Val{true}()
integrator.u .= prob.f.initializeprobmap(nlsol)
integrator.u .= u0
elseif isinplace === Val{false}()
integrator.u = prob.f.initializeprobmap(nlsol)
integrator.u = u0
else
error("Unreachable reached. Report this error.")
end
if SciMLBase.has_initializeprobpmap(prob.f)
integrator.p = prob.f.initializeprobpmap(prob, nlsol)
sol = integrator.sol
@reset sol.prob.p = integrator.p
integrator.sol = sol
end
integrator.p = p
sol = integrator.sol
@reset sol.prob.p = integrator.p
integrator.sol = sol

if nlsol.retcode != ReturnCode.Success
if !success
integrator.sol = SciMLBase.solution_new_retcode(integrator.sol,
ReturnCode.InitialFailure)
end
end

## CheckInit
struct CheckInitFailureError <: Exception
normresid::Any
abstol::Any
end

function Base.showerror(io::IO, e::CheckInitFailureError)
print(io,
"CheckInit specified but initialization not satisifed. normresid = $(e.normresid) > abstol = $(e.abstol)")
end

function _initialize_dae!(integrator, prob::ODEProblem, alg::CheckInit,
isinplace::Val{true})
@unpack p, t, f = integrator
M = integrator.f.mass_matrix
tmp = first(get_tmp_cache(integrator))
u0 = integrator.u

algebraic_vars = [all(iszero, x) for x in eachcol(M)]
algebraic_eqs = [all(iszero, x) for x in eachrow(M)]
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return
update_coefficients!(M, u0, p, t)
f(tmp, u0, p, t)
tmp .= ArrayInterface.restructure(tmp, algebraic_eqs .* _vec(tmp))

normresid = integrator.opts.internalnorm(tmp, t)
if normresid > integrator.opts.abstol
throw(CheckInitFailureError(normresid, integrator.opts.abstol))
end
end

function _initialize_dae!(integrator, prob::ODEProblem, alg::CheckInit,
isinplace::Val{false})
@unpack p, t, f = integrator
u0 = integrator.u
M = integrator.f.mass_matrix

algebraic_vars = [all(iszero, x) for x in eachcol(M)]
algebraic_eqs = [all(iszero, x) for x in eachrow(M)]
(iszero(algebraic_vars) || iszero(algebraic_eqs)) && return
update_coefficients!(M, u0, p, t)
du = f(u0, p, t)
resid = _vec(du)[algebraic_eqs]

normresid = integrator.opts.internalnorm(resid, t)
if normresid > integrator.opts.abstol
throw(CheckInitFailureError(normresid, integrator.opts.abstol))
end
end

function _initialize_dae!(integrator, prob::DAEProblem,
alg::CheckInit, isinplace::Val{true})
@unpack p, t, f = integrator
u0 = integrator.u
resid = get_tmp_cache(integrator)[2]

f(resid, integrator.du, u0, p, t)
normresid = integrator.opts.internalnorm(resid, t)
if normresid > integrator.opts.abstol
throw(CheckInitFailureError(normresid, integrator.opts.abstol))
end
end

function _initialize_dae!(integrator, prob::DAEProblem,
alg::CheckInit, isinplace::Val{false})
@unpack p, t, f = integrator
u0 = integrator.u

nlequation_oop = u -> begin
f((u - u0) / dt, u, p, t)
end

nlequation = (u, _) -> nlequation_oop(u)

resid = f(integrator.du, u0, p, t)
normresid = integrator.opts.internalnorm(resid, t)
if normresid > integrator.opts.abstol
throw(CheckInitFailureError(normresid, integrator.opts.abstol))
end
function _initialize_dae!(integrator, prob::AbstractDEProblem, alg::CheckInit,
isinplace::Union{Val{true}, Val{false}})
SciMLBase.get_initial_values(prob, integrator, prob.f, alg, isinplace; abstol = integrator.opts.abstol)
end
4 changes: 4 additions & 0 deletions lib/OrdinaryDiffEqDefault/test/default_solver_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ end
prob_rober = ODEProblem(rober, [1.0, 0.0, 0.0], (0.0, 1e3), (0.04, 3e7, 1e4))
sol = solve(prob_rober)
rosensol = solve(prob_rober, AutoTsit5(Rosenbrock23(autodiff = false)))
#test that cache is type stable
@test typeof(sol.interp.cache.cache3) == typeof(rosensol.interp.cache.caches[2])
# test that default has the same performance as AutoTsit5(Rosenbrock23()) (which we expect it to use for this).
@test sol.stats.naccept == rosensol.stats.naccept
@test sol.stats.nf == rosensol.stats.nf
Expand All @@ -50,6 +52,8 @@ rosensol = solve(prob_rober, AutoTsit5(Rosenbrock23(autodiff = false)))
sol = solve(prob_rober, reltol = 1e-7, abstol = 1e-7)
rosensol = solve(
prob_rober, AutoVern7(Rodas5P(autodiff = false)), reltol = 1e-7, abstol = 1e-7)
#test that cache is type stable
@test typeof(sol.interp.cache.cache4) == typeof(rosensol.interp.cache.caches[2])
# test that default has the same performance as AutoTsit5(Rosenbrock23()) (which we expect it to use for this).
@test sol.stats.naccept == rosensol.stats.naccept
@test sol.stats.nf == rosensol.stats.nf
Expand Down
9 changes: 7 additions & 2 deletions lib/OrdinaryDiffEqFIRK/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
name = "OrdinaryDiffEqFIRK"
uuid = "5960d6e9-dd7a-4743-88e7-cf307b64f125"
authors = ["ParamThakkar123 <[email protected]>"]
version = "1.4.0"
version = "1.5.0"

[deps]
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
FastGaussQuadrature = "442a2c76-b920-505d-bb47-c5924d526838"
FastPower = "a4df4552-cc26-4903-aec0-212e50a0e84b"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
Expand All @@ -15,12 +16,14 @@ OrdinaryDiffEqDifferentiation = "4302a76b-040a-498a-8c04-15b101fed76b"
OrdinaryDiffEqNonlinearSolve = "127b3ac7-2247-4354-8eb6-78cf4e7c58e8"
RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
SciMLOperators = "c0aeaf25-5076-4817-a8d5-81caf7dfa961"

[compat]
DiffEqBase = "6.152.2"
DiffEqDevTools = "2.44.4"
FastBroadcast = "0.3.5"
FastGaussQuadrature = "1.0.2"
FastPower = "1"
LinearAlgebra = "<0.0.1, 1"
LinearSolve = "2.32.0"
Expand All @@ -33,16 +36,18 @@ Random = "<0.0.1, 1"
RecursiveArrayTools = "3.27.0"
Reexport = "1.2.2"
SafeTestsets = "0.1.0"
SciMLBase = "2.60.0"
SciMLOperators = "0.3.9"
Test = "<0.0.1, 1"
julia = "1.10"

[extras]
DiffEqDevTools = "f3b72e0c-5b89-59e1-b016-84e28bfd966d"
GenericSchur = "c145ed77-6b09-5dd9-b285-bf645a82121e"
ODEProblemLibrary = "fdc4e326-1af4-4b90-96e7-779fcce2daa5"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DiffEqDevTools", "Random", "SafeTestsets", "Test", "ODEProblemLibrary"]
test = ["DiffEqDevTools", "GenericSchur", "Random", "SafeTestsets", "Test", "ODEProblemLibrary"]
Loading
Loading