Skip to content

Commit a456d96

Browse files
Handle FIRK in-place Mooncake AD fallback
Route in-place FIRK Mooncake residual AD through ForwardDiff for the boundary-condition paths as well as collocation/full residual paths. This avoids the Julia pre-release Mooncake rule-generation failure while preserving sparse wrapper structure. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
1 parent 87ba290 commit a456d96

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/BoundaryValueDiffEqFIRK/src/BoundaryValueDiffEqFIRK.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module BoundaryValueDiffEqFIRK
22

3-
using ADTypes: ADTypes, AutoSparse, AutoForwardDiff, AutoEnzyme
3+
using ADTypes: ADTypes, AutoSparse, AutoForwardDiff, AutoEnzyme, AutoMooncake
44
using ArrayInterface: fast_scalar_indexing
55
using BandedMatrices: BandedMatrix, Ones
66
using BoundaryValueDiffEqCore: BoundaryValueDiffEqCore,

lib/BoundaryValueDiffEqFIRK/src/firk.jl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,14 @@ function __construct_problem(
657657
end
658658

659659
__firk_iip_ad_diffmode(::Val{true}, ::AutoEnzyme) = AutoForwardDiff()
660+
__firk_iip_ad_diffmode(::Val{true}, ::AutoMooncake) = AutoForwardDiff()
661+
function __firk_iip_ad_diffmode(iip, diffmode::AutoSparse)
662+
return AutoSparse(
663+
__firk_iip_ad_diffmode(iip, get_dense_ad(diffmode));
664+
sparsity_detector = __default_sparsity_detector(diffmode),
665+
coloring_algorithm = __default_coloring_algorithm(diffmode)
666+
)
667+
end
660668
__firk_iip_ad_diffmode(_, diffmode) = diffmode
661669

662670
__firk_iip_needs_diffcache(iip, diffmode::AutoSparse) = __firk_iip_needs_diffcache(
@@ -754,7 +762,7 @@ function __construct_problem(
754762
) where {iip, T, DC, tune_parameters, BC, C, LF}
755763
(; prob, alg, stage, bcresid_prototype, f_prototype) = cache
756764
(; jac_alg) = alg
757-
(; bc_diffmode) = jac_alg
765+
bc_diffmode = __firk_iip_ad_diffmode(Val(iip), jac_alg.bc_diffmode)
758766
N = length(cache.mesh)
759767

760768
resid_bc = cache.bcresid_prototype
@@ -844,7 +852,7 @@ function __construct_problem(
844852
) where {iip, T, DC, tune_parameters, BC, C, LF}
845853
(; prob, alg, stage, bcresid_prototype, f_prototype) = cache
846854
(; jac_alg) = alg
847-
(; bc_diffmode) = jac_alg
855+
bc_diffmode = __firk_iip_ad_diffmode(Val(iip), jac_alg.bc_diffmode)
848856
N = length(cache.mesh)
849857

850858
resid_bc = cache.bcresid_prototype
@@ -1110,7 +1118,7 @@ function __construct_problem(
11101118
loss::LF, ::StandardBVProblem, ::Val{true}
11111119
) where {iip, T, DC, tune_parameters, BC, C, LF}
11121120
(; jac_alg) = cache.alg
1113-
(; bc_diffmode) = jac_alg
1121+
bc_diffmode = __firk_iip_ad_diffmode(Val(iip), jac_alg.bc_diffmode)
11141122
(; bcresid_prototype, f_prototype) = cache
11151123
N = length(cache.mesh)
11161124
resid_bc = cache.bcresid_prototype
@@ -1196,7 +1204,7 @@ function __construct_problem(
11961204
loss::LF, ::StandardBVProblem, ::Val{false}
11971205
) where {iip, T, DC, tune_parameters, BC, C, LF}
11981206
(; jac_alg) = cache.alg
1199-
(; bc_diffmode) = jac_alg
1207+
bc_diffmode = __firk_iip_ad_diffmode(Val(iip), jac_alg.bc_diffmode)
12001208
(; bcresid_prototype, f_prototype, prob) = cache
12011209
N = length(cache.mesh)
12021210
resid_bc = cache.bcresid_prototype

0 commit comments

Comments
 (0)