Skip to content

Commit 24a0225

Browse files
Fix FIRK v7 precompile: DI strict + VectorOfArray iteration
The `BoundaryValueDiffEqFIRK` precompile workload fails against `OrdinaryDiffEq.jl` v7 / SciMLBase v3 / RecursiveArrayTools v4 in two distinct places. Both are fixed here. 1. `DifferentiationInterface.prepare_jacobian` strict-mode mismatch in `firk.jl`. Preparation is done with `y = copy(cache.y₀)` (a `VectorOfArray`-wrapping `Base.ReshapedArray`), but execution inside the nonlinear solve is called with a plain `Vector{Float64}`. DI's strict check rejects this as a `PreparationMismatchError` (x type prep vs exec). Match `BoundaryValueDiffEqShooting`, which already passes `strict = Val(false)` to every `DI.prepare_jacobian` call. 2. `recursive_unflatten!(::AbstractVectorOfArray, ::AbstractVector)` in `BoundaryValueDiffEqCore/src/utils.jl` iterates `for yᵢ in y`. With RecursiveArrayTools v4, a 2D `VectorOfArray{T,2,...}` is an `AbstractArray` with scalar linear-indexing iteration — so `yᵢ` is a `Float64`, not the inner timestep vector, and the body `copyto!(yᵢ, x[range])` dispatches to `copyto!(::Float64, ::SubArray)` (no such method). Iterate `y.u` instead, which is the vector-of-vectors backing store. This is the counterpart to the other `sol`/`sol.u` migrations that landed in the SciMLBase v3 compat commit. Verified locally: ``` julia +1.11 -e 'using Pkg; Pkg.activate(temp=true); Pkg.develop(path=".../BoundaryValueDiffEqFIRK"); Pkg.develop(path=".../BoundaryValueDiffEqCore"); using BoundaryValueDiffEqFIRK' # ✓ BoundaryValueDiffEqFIRK precompiles (115 s) julia +1.12 (same) # ✓ BoundaryValueDiffEqFIRK precompiles (200 s) ``` Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent fb3a3d5 commit 24a0225

2 files changed

Lines changed: 61 additions & 25 deletions

File tree

lib/BoundaryValueDiffEqCore/src/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ end
4242

4343
@views function recursive_unflatten!(y::AbstractVectorOfArray, x::AbstractVector)
4444
i = 0
45-
for yᵢ in y
45+
for yᵢ in y.u
4646
copyto!(yᵢ, x[(i + 1):(i + length(yᵢ))])
4747
i += length(yᵢ)
4848
end

lib/BoundaryValueDiffEqFIRK/src/firk.jl

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,13 @@ function __construct_problem(
702702
resid_collocation = safe_similar(y, L_f_prototype * (N - 1) * (stage + 1))
703703

704704
cache_bc = if iip
705-
DI.prepare_jacobian(loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p))
705+
DI.prepare_jacobian(
706+
loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
707+
)
706708
else
707-
DI.prepare_jacobian(loss_bc, bc_diffmode, y, Constant(cache.p))
709+
DI.prepare_jacobian(
710+
loss_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
711+
)
708712
end
709713

710714
nonbc_diffmode = AutoSparse(
@@ -715,10 +719,13 @@ function __construct_problem(
715719

716720
cache_collocation = if iip
717721
DI.prepare_jacobian(
718-
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p)
722+
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p);
723+
strict = Val(false)
719724
)
720725
else
721-
DI.prepare_jacobian(loss_collocation, nonbc_diffmode, y, Constant(cache.p))
726+
DI.prepare_jacobian(
727+
loss_collocation, nonbc_diffmode, y, Constant(cache.p); strict = Val(false)
728+
)
722729
end
723730

724731
J_bc = if iip
@@ -784,9 +791,13 @@ function __construct_problem(
784791
resid_collocation = safe_similar(y, cache.M * (N - 1) * (stage + 1))
785792

786793
cache_bc = if iip
787-
DI.prepare_jacobian(loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p))
794+
DI.prepare_jacobian(
795+
loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
796+
)
788797
else
789-
DI.prepare_jacobian(loss_bc, bc_diffmode, y, Constant(cache.p))
798+
DI.prepare_jacobian(
799+
loss_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
800+
)
790801
end
791802

792803
nonbc_diffmode = if jac_alg.nonbc_diffmode isa AutoSparse
@@ -821,10 +832,13 @@ function __construct_problem(
821832

822833
cache_collocation = if iip
823834
DI.prepare_jacobian(
824-
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p)
835+
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p);
836+
strict = Val(false)
825837
)
826838
else
827-
DI.prepare_jacobian(loss_collocation, nonbc_diffmode, y, Constant(cache.p))
839+
DI.prepare_jacobian(
840+
loss_collocation, nonbc_diffmode, y, Constant(cache.p); strict = Val(false)
841+
)
828842
end
829843

830844
J_bc = if iip
@@ -908,9 +922,11 @@ function __construct_problem(
908922
end
909923

910924
diffcache = if iip
911-
DI.prepare_jacobian(loss, resid, diffmode, y, Constant(cache.p))
925+
DI.prepare_jacobian(
926+
loss, resid, diffmode, y, Constant(cache.p); strict = Val(false)
927+
)
912928
else
913-
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p))
929+
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p); strict = Val(false))
914930
end
915931

916932
jac_prototype = if iip
@@ -988,9 +1004,11 @@ function __construct_problem(
9881004
end
9891005

9901006
diffcache = if iip
991-
DI.prepare_jacobian(loss, resid, diffmode, y, Constant(cache.p))
1007+
DI.prepare_jacobian(
1008+
loss, resid, diffmode, y, Constant(cache.p); strict = Val(false)
1009+
)
9921010
else
993-
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p))
1011+
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p); strict = Val(false))
9941012
end
9951013

9961014
jac_prototype = if iip
@@ -1038,9 +1056,13 @@ function __construct_problem(
10381056
L = length(resid_bc)
10391057
resid_collocation = safe_similar(y, cache.M * (N - 1))
10401058
cache_bc = if iip
1041-
DI.prepare_jacobian(loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p))
1059+
DI.prepare_jacobian(
1060+
loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
1061+
)
10421062
else
1043-
DI.prepare_jacobian(loss_bc, bc_diffmode, y, Constant(cache.p))
1063+
DI.prepare_jacobian(
1064+
loss_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
1065+
)
10441066
end
10451067

10461068
nonbc_diffmode = AutoSparse(
@@ -1051,10 +1073,13 @@ function __construct_problem(
10511073

10521074
cache_collocation = if iip
10531075
DI.prepare_jacobian(
1054-
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p)
1076+
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p);
1077+
strict = Val(false)
10551078
)
10561079
else
1057-
DI.prepare_jacobian(loss_collocation, nonbc_diffmode, y, Constant(cache.p))
1080+
DI.prepare_jacobian(
1081+
loss_collocation, nonbc_diffmode, y, Constant(cache.p); strict = Val(false)
1082+
)
10581083
end
10591084

10601085
J_bc = if iip
@@ -1117,9 +1142,13 @@ function __construct_problem(
11171142
L = length(resid_bc)
11181143
resid_collocation = safe_similar(y, cache.M * (N - 1))
11191144
cache_bc = if iip
1120-
DI.prepare_jacobian(loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p))
1145+
DI.prepare_jacobian(
1146+
loss_bc, resid_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
1147+
)
11211148
else
1122-
DI.prepare_jacobian(loss_bc, bc_diffmode, y, Constant(cache.p))
1149+
DI.prepare_jacobian(
1150+
loss_bc, bc_diffmode, y, Constant(cache.p); strict = Val(false)
1151+
)
11231152
end
11241153

11251154
nonbc_diffmode = if jac_alg.nonbc_diffmode isa AutoSparse
@@ -1150,10 +1179,13 @@ function __construct_problem(
11501179

11511180
cache_collocation = if iip
11521181
DI.prepare_jacobian(
1153-
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p)
1182+
loss_collocation, resid_collocation, nonbc_diffmode, y, Constant(cache.p);
1183+
strict = Val(false)
11541184
)
11551185
else
1156-
DI.prepare_jacobian(loss_collocation, nonbc_diffmode, y, Constant(cache.p))
1186+
DI.prepare_jacobian(
1187+
loss_collocation, nonbc_diffmode, y, Constant(cache.p); strict = Val(false)
1188+
)
11571189
end
11581190

11591191
J_bc = if iip
@@ -1234,9 +1266,11 @@ function __construct_problem(
12341266
end
12351267

12361268
diffcache = if iip
1237-
DI.prepare_jacobian(loss, resid, diffmode, y, Constant(cache.p))
1269+
DI.prepare_jacobian(
1270+
loss, resid, diffmode, y, Constant(cache.p); strict = Val(false)
1271+
)
12381272
else
1239-
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p))
1273+
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p); strict = Val(false))
12401274
end
12411275

12421276
jac_prototype = if iip
@@ -1302,9 +1336,11 @@ function __construct_problem(
13021336
end
13031337

13041338
diffcache = if iip
1305-
DI.prepare_jacobian(loss, resid, diffmode, y, Constant(cache.p))
1339+
DI.prepare_jacobian(
1340+
loss, resid, diffmode, y, Constant(cache.p); strict = Val(false)
1341+
)
13061342
else
1307-
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p))
1343+
DI.prepare_jacobian(loss, diffmode, y, Constant(cache.p); strict = Val(false))
13081344
end
13091345

13101346
jac_prototype = if iip

0 commit comments

Comments
 (0)