Skip to content

Commit 4078145

Browse files
authored
Merge branch 'master' into qqy/merge_kwargs
2 parents 7ed5704 + 4e5a359 commit 4078145

File tree

11 files changed

+135
-39
lines changed

11 files changed

+135
-39
lines changed

.github/workflows/Downstream.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: IntegrationTest
2+
on:
3+
push:
4+
branches: [master]
5+
tags: [v*]
6+
pull_request:
7+
concurrency:
8+
# Skip intermediate builds: always.
9+
# Cancel intermediate builds: only if it is a pull request build.
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
12+
jobs:
13+
test:
14+
name: ${{ matrix.package.repo }}/${{ matrix.package.group }}/${{ matrix.julia-version }}
15+
runs-on: ${{ matrix.os }}
16+
env:
17+
GROUP: ${{ matrix.package.group }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
julia-version: [1]
22+
os: [ubuntu-latest]
23+
package:
24+
- {user: SciML, repo: ModelingToolkit.jl, group: All}
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: julia-actions/setup-julia@v2
28+
with:
29+
version: ${{ matrix.julia-version }}
30+
arch: x64
31+
- name: "Install Dependencies"
32+
run: |
33+
import Pkg
34+
Pkg.Registry.update()
35+
# Install packages present in subdirectories
36+
dev_pks = Pkg.PackageSpec[]
37+
for path in ("lib/BoundaryValueDiffEqCore", "lib/BoundaryValueDiffEqMIRK", "lib/BoundaryValueDiffEqMIRKN", "lib/BoundaryValueDiffEqFIRK", "lib/BoundaryValueDiffEqShooting", "lib/BoundaryValueDiffEqAscher")
38+
push!(dev_pks, Pkg.PackageSpec(; path))
39+
end
40+
Pkg.develop(dev_pks)
41+
Pkg.instantiate()
42+
shell: julia --color=yes --code-coverage=user --depwarn=yes --project=. {0}
43+
- name: Clone Downstream
44+
uses: actions/checkout@v4
45+
with:
46+
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }}
47+
path: downstream
48+
- name: Load this and run the downstream tests
49+
shell: julia --color=yes --project=downstream {0}
50+
run: |
51+
using Pkg
52+
try
53+
# force it to use this PR's version of the package
54+
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
55+
Pkg.update()
56+
Pkg.test(coverage="user") # resolver may fail with test time deps
57+
catch err
58+
err isa Pkg.Resolve.ResolverError || rethrow()
59+
# If we can't resolve that means this is incompatible by SemVer and this is fine
60+
# It means we marked this as a breaking change, so we don't need to worry about
61+
# Mistakenly introducing a breaking change, as we have intentionally made one
62+
@info "Not compatible with this release. No problem." exception=err
63+
exit(0) # Exit immediately, as a success
64+
end
65+
- uses: julia-actions/julia-processcoverage@v1
66+
with:
67+
directories: src,ext
68+
- uses: codecov/codecov-action@v5
69+
with:
70+
file: lcov.info
71+
token: ${{ secrets.CODECOV_TOKEN }}
72+
fail_ci_if_error: false

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BoundaryValueDiffEq"
22
uuid = "764a87c0-6b3e-53db-9096-fe964310641d"
3-
version = "5.16.1"
3+
version = "5.17.0"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
@@ -48,7 +48,7 @@ Hwloc = "3.3"
4848
InteractiveUtils = "<0.0.1, 1"
4949
JET = "0.9.18"
5050
LinearAlgebra = "1.10"
51-
LinearSolve = "3.9"
51+
LinearSolve = "3.12"
5252
NonlinearSolveFirstOrder = "1.3"
5353
ODEInterface = "0.5"
5454
OrdinaryDiffEqLowOrderRK = "1.2"

lib/BoundaryValueDiffEqCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "BoundaryValueDiffEqCore"
22
uuid = "56b672f2-a5fe-4263-ab2d-da677488eb3a"
33
authors = ["Qingyu Qu <[email protected]>"]
4-
version = "1.8.1"
4+
version = "1.9.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

lib/BoundaryValueDiffEqFIRK/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2323
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2424
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2525

26-
[sources]
27-
BoundaryValueDiffEqCore = {path = "../BoundaryValueDiffEqCore"}
26+
[sources.BoundaryValueDiffEqCore]
27+
path = "../BoundaryValueDiffEqCore"
2828

2929
[compat]
3030
ADTypes = "1.14"
@@ -35,7 +35,7 @@ BoundaryValueDiffEqCore = "1"
3535
ConcreteStructs = "0.2.3"
3636
DiffEqBase = "6.167"
3737
DiffEqDevTools = "2.44"
38-
DifferentiationInterface = "0.6.42"
38+
DifferentiationInterface = "0.6.42, 0.7"
3939
Enzyme = "0.13.33"
4040
FastAlmostBandedMatrices = "0.1.4"
4141
FastClosures = "0.3.2"

lib/BoundaryValueDiffEqMIRK/Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2323
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2424
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2525

26-
[sources]
27-
BoundaryValueDiffEqCore = {path = "../BoundaryValueDiffEqCore"}
26+
[sources.BoundaryValueDiffEqCore]
27+
path = "../BoundaryValueDiffEqCore"
2828

2929
[compat]
3030
ADTypes = "1.14"
@@ -35,7 +35,7 @@ BoundaryValueDiffEqCore = "1"
3535
ConcreteStructs = "0.2.3"
3636
DiffEqBase = "6.167"
3737
DiffEqDevTools = "2.44"
38-
DifferentiationInterface = "0.6.42"
38+
DifferentiationInterface = "0.6.42, 0.7"
3939
Enzyme = "0.13.33"
4040
FastAlmostBandedMatrices = "0.1.4"
4141
FastClosures = "0.3.2"

lib/BoundaryValueDiffEqMIRK/src/BoundaryValueDiffEqMIRK.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ using BoundaryValueDiffEqCore: AbstractBoundaryValueDiffEqAlgorithm,
1515
safe_similar, __vec, __vec_f, __vec_f!, __vec_bc, __vec_bc!,
1616
recursive_flatten_twopoint!, __internal_nlsolve_problem,
1717
__extract_mesh, __extract_u0, __has_initial_guess,
18-
__initial_guess_length, __cache_trait,
19-
__initial_guess_on_mesh, __flatten_initial_guess,
20-
__build_solution, __Fix3, get_dense_ad, _sparse_like,
21-
AbstractErrorControl, DefectControl, GlobalErrorControl,
22-
SequentialErrorControl, HybridErrorControl, HOErrorControl,
23-
__use_both_error_control, __default_coloring_algorithm,
24-
DiffCacheNeeded, NoDiffCacheNeeded, __split_kwargs
18+
__initial_guess_length, __initial_guess_on_mesh,
19+
__flatten_initial_guess, __build_solution, __Fix3,
20+
get_dense_ad, _sparse_like, AbstractErrorControl,
21+
DefectControl, GlobalErrorControl, SequentialErrorControl,
22+
HybridErrorControl, HOErrorControl, __use_both_error_control,
23+
__default_coloring_algorithm, DiffCacheNeeded,
24+
NoDiffCacheNeeded, __split_kwargs
2525

2626
using ConcreteStructs: @concrete
2727
using DiffEqBase: DiffEqBase

lib/BoundaryValueDiffEqMIRK/src/adaptivity.jl

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ After we construct an interpolant, we use interp_eval to evaluate it.
77
i = interval(mesh, t)
88
dt = mesh_dt[i]
99
τ = (t - mesh[i]) / dt
10-
w, w′ = interp_weights(τ, cache.alg)
10+
w, _ = interp_weights(τ, cache.alg)
1111
sum_stages!(y, cache, w, i, dt)
1212
return y
1313
end
@@ -624,32 +624,35 @@ function sum_stages!(cache::MIRKCache{iip, T, use_both, NoDiffCacheNeeded}, w,
624624
sum_stages!(cache.fᵢ_cache, cache.fᵢ₂_cache, cache, w, w′, i, dt)
625625
end
626626

627+
# Here we should not directly in-place change z in several steps
628+
# because in final step we actually need to use the original z(which is cache.y₀.u[i])
629+
# we use fᵢ₂_cache to avoid additional allocations.
627630
function sum_stages!(z::AbstractArray, cache::MIRKCache{iip, T, use_both, DiffCacheNeeded},
628631
w, i::Int, dt = cache.mesh_dt[i]) where {iip, T, use_both}
629-
(; stage, k_discrete, k_interp) = cache
632+
(; stage, k_discrete, k_interp, fᵢ₂_cache) = cache
630633
(; s_star) = cache.ITU
631634

632-
z .= zero(z)
633-
__maybe_matmul!(z, k_discrete[i].du[:, 1:stage], w[1:stage])
635+
fᵢ₂_cache .= zero(z)
636+
__maybe_matmul!(fᵢ₂_cache, k_discrete[i].du[:, 1:stage], w[1:stage])
634637
__maybe_matmul!(
635-
z, k_interp.u[i][:, 1:(s_star - stage)], w[(stage + 1):s_star], true, true)
636-
z .= z .* dt .+ cache.y₀.u[i]
638+
fᵢ₂_cache, k_interp.u[i][:, 1:(s_star - stage)], w[(stage + 1):s_star], true, true)
639+
z .= fᵢ₂_cache .* dt .+ cache.y₀.u[i]
637640

638-
return z
641+
return nothing
639642
end
640643
function sum_stages!(
641644
z::AbstractArray, cache::MIRKCache{iip, T, use_both, NoDiffCacheNeeded},
642645
w, i::Int, dt = cache.mesh_dt[i]) where {iip, T, use_both}
643-
(; stage, k_discrete, k_interp) = cache
646+
(; stage, k_discrete, k_interp, fᵢ₂_cache) = cache
644647
(; s_star) = cache.ITU
645648

646-
z .= zero(z)
647-
__maybe_matmul!(z, k_discrete[i][:, 1:stage], w[1:stage])
649+
fᵢ₂_cache .= zero(z)
650+
__maybe_matmul!(fᵢ₂_cache, k_discrete[i][:, 1:stage], w[1:stage])
648651
__maybe_matmul!(
649-
z, k_interp.u[i][:, 1:(s_star - stage)], w[(stage + 1):s_star], true, true)
650-
z .= z .* dt .+ cache.y₀.u[i]
652+
fᵢ₂_cache, k_interp.u[i][:, 1:(s_star - stage)], w[(stage + 1):s_star], true, true)
653+
z .= fᵢ₂_cache .* dt .+ cache.y₀.u[i]
651654

652-
return z
655+
return nothing
653656
end
654657

655658
@views function sum_stages!(z, z′, cache::MIRKCache{iip, T, use_both, DiffCacheNeeded}, w,

lib/BoundaryValueDiffEqMIRK/test/mirk_basic_tests.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,23 @@ end
381381
prob, MIRK4(), dt = 0.05, abstol = 1e-5, controller = error_control)
382382
end
383383
end
384+
385+
# https://github.com/SciML/BoundaryValueDiffEq.jl/issues/319
386+
@testitem "Test interpolant evaluation with big defect" setup=[MIRKConvergenceTests] begin
387+
function lotka!(du, u, p, t)
388+
x = u[1]
389+
y = u[2]
390+
du[1] = p[1] * x - p[2] * x * y
391+
du[2] = -p[3] * y + p[4] * x * y
392+
end
393+
394+
function bc!(resid, u, p, t)
395+
resid[1] = u(0.0)[1] - 1.0
396+
resid[2] = u(0.0)[2] - 2.0
397+
end
398+
bvp = BVProblem(lotka!, bc!, [1.0, 2.0], (0, 10), [7.5, 4.0, 8, 5])
399+
for order in (4, 5, 6)
400+
sol = solve(bvp, mirk_solver(Val(order)), dt = 0.01)
401+
@test SciMLBase.successful_retcode(sol)
402+
end
403+
end

lib/BoundaryValueDiffEqShooting/Project.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
2323
Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46"
2424
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
2525

26-
[sources]
27-
BoundaryValueDiffEqCore = {path = "../BoundaryValueDiffEqCore"}
26+
[sources.BoundaryValueDiffEqCore]
27+
path = "../BoundaryValueDiffEqCore"
2828

2929
[compat]
3030
ADTypes = "1.14"
@@ -35,7 +35,7 @@ BoundaryValueDiffEqCore = "1"
3535
ConcreteStructs = "0.2.3"
3636
DiffEqBase = "6.167"
3737
DiffEqDevTools = "2.44"
38-
DifferentiationInterface = "0.6.42"
38+
DifferentiationInterface = "0.6.42, 0.7"
3939
FastAlmostBandedMatrices = "0.1.4"
4040
FastClosures = "0.3.2"
4141
ForwardDiff = "0.10.38, 1"
@@ -69,9 +69,9 @@ Hwloc = "0e44f5e4-bd66-52a0-8798-143a42290a1d"
6969
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
7070
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
7171
OrdinaryDiffEqLowOrderRK = "1344f307-1e59-4825-a18e-ace9aa3fa4c6"
72+
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
7273
OrdinaryDiffEqTsit5 = "b1df2697-797e-41e3-8120-5422d3b24e4a"
7374
OrdinaryDiffEqVerner = "79d7bb75-1356-48c1-b8c0-6832512096c2"
74-
OrdinaryDiffEqRosenbrock = "43230ef6-c299-4910-a778-202eb28ce4ce"
7575
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
7676
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
7777
ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823"

lib/BoundaryValueDiffEqShooting/src/multiple_shooting.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ function __solve_nlproblem!(
111111
end
112112

113113
resid_prototype_cached = similar(resid_prototype)
114-
jac_cache = DI.prepare_jacobian(nothing, resid_prototype_cached, diffmode, u_at_nodes)
114+
jac_cache = DI.prepare_jacobian(
115+
nothing, resid_prototype_cached, diffmode, u_at_nodes; strict = Val(false))
115116

116117
ode_cache_jac_fn = __multiple_shooting_init_jacobian_odecache(
117118
ensemblealg, prob, jac_cache, diffmode, alg.ode_alg,
@@ -161,8 +162,8 @@ function __solve_nlproblem!(::StandardBVProblem, alg::MultipleShooting, bcresid_
161162
else
162163
alg.jac_alg.nonbc_diffmode
163164
end
164-
ode_jac_cache = DI.prepare_jacobian(
165-
nothing, similar(u_at_nodes, cur_nshoot * N), nonbc_diffmode, u_at_nodes)
165+
ode_jac_cache = DI.prepare_jacobian(nothing, similar(u_at_nodes, cur_nshoot * N),
166+
nonbc_diffmode, u_at_nodes; strict = Val(false))
166167
ode_cache_ode_jac_fn = __multiple_shooting_init_jacobian_odecache(
167168
ensemblealg, prob, ode_jac_cache, nonbc_diffmode,
168169
alg.ode_alg, cur_nshoot, u0; internal_ode_kwargs...)
@@ -175,7 +176,7 @@ function __solve_nlproblem!(::StandardBVProblem, alg::MultipleShooting, bcresid_
175176
bc_diffmode
176177
end
177178
bc_jac_cache = DI.prepare_jacobian(
178-
nothing, similar(bcresid_prototype), bc_diffmode, u_at_nodes)
179+
nothing, similar(bcresid_prototype), bc_diffmode, u_at_nodes; strict = Val(false))
179180
ode_cache_bc_jac_fn = __multiple_shooting_init_jacobian_odecache(
180181
ensemblealg, prob, bc_jac_cache, bc_diffmode,
181182
alg.ode_alg, cur_nshoot, u0; internal_ode_kwargs...)

0 commit comments

Comments
 (0)