Skip to content

Avoid ambiguous reverse promotion in DiffCache - #201

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:agent/fix-sct-bigfloat-cache
Aug 27, 2026
Merged

Avoid ambiguous reverse promotion in DiffCache#201
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:agent/fix-sct-bigfloat-cache

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Ignore until reviewed by @ChrisRackauckas.

What changed

get_tmp now asks the requested element type's public Base.promote_rule first. When that type has no rule, it falls back to the existing symmetric promote_type check. This preserves the primal buffer selection for ordinary inputs while avoiding an ambiguous reverse promotion rule for BigFloat and SparseConnectivityTracer.Dual.

The regression test covers both DiffCache and FixedSizeDiffCache through SparseConnectivityTracer's public jacobian_eltype API. No SparseConnectivityTracer dependency or internal API is added.

Root cause

PreallocationTools v1.5.0 moved sparse-tracer handling into the generic cache path. promote_type(BigFloat, SparseConnectivityTracer.Dual{BigFloat, ...}) asks both promotion directions; its reverse query is ambiguous between Base's BigFloat rule and SparseConnectivityTracer's Dual rule.

The boundary bisects to a032da6 (the merge of #198). PreallocationTools v1.4.1 passes the standalone control; v1.5.0 fails.

Failing before

$ env JULIA_DEPOT_PATH=$DEPOT JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
BigFloat cache: Error During Test
MethodError: promote_rule(::Type{BigFloat}, ::Type{SparseConnectivityTracer.Dual{BigFloat, ...}}) is ambiguous.
Test Summary:             | Pass  Error  Total
Sparse Connectivity Tests |   22      1     23
ERROR: Package PreallocationTools errored during testing

The unmodified BoundaryValueDiffEq master Misc group reproduces the downstream failure with PreallocationTools v1.5.0 and SparseConnectivityTracer v1.2.2:

$ env JULIA_DEPOT_PATH=$DEPOT JULIA_PKG_PRECOMPILE_AUTO=0 GROUP=Misc julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
Test Summary:  | Pass  Error  Total
BigFloat Tests |    3      2      5
ERROR: Package BoundaryValueDiffEq errored during testing

Passing after

$ env JULIA_DEPOT_PATH=$DEPOT JULIA_PKG_PRECOMPILE_AUTO=0 julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
Test Summary:                           | Pass  Total   Time
DiffCache with SparseConnectivityTracer |   26     26  11.6s
Test Summary:  | Pass  Total     Time
Enzyme Support |   26     26  3m46.3s
Test Summary:               | Pass  Total  Time
Allocation Regression Tests |   27     27  3.3s
Testing PreallocationTools tests passed

The full Core group also passed Developer Interface (16/16), DiffCache Dispatch (82 pass, 10 existing broken), ODE (7/7), Resizing (64/64), Nested Duals (4/4), Sparsity Support (4/4), LazyBufferCache (2/2), GeneralLazyBufferCache (11/11), and Zero/Copy/Fill Dispatches (66/66).

The same full downstream group passes with the branch developed into BoundaryValueDiffEq:

$ env JULIA_DEPOT_PATH=$DEPOT JULIA_PKG_PRECOMPILE_AUTO=0 GROUP=Misc julia +1.12 --project=. -e 'using Pkg; Pkg.develop(path="../prealloc"); Pkg.test()'
Test Summary:    | Pass  Total      Time
Adaptivity Tests |   19     19  12m48.5s
Test Summary:          | Pass  Broken  Total     Time
Non-Vector Input Tests |   24       4     28  9m01.8s
Test Summary:  | Pass  Total     Time
BigFloat Tests |    7      7  6m09.7s
Test Summary: | Pass  Total     Time
Verbose Tests |   78     78  8m59.7s
Test Summary:   | Pass  Total     Time
Manifolds Tests |   11     11  4m22.8s
Testing BoundaryValueDiffEq tests passed

Initial Guess (6/6), Scalar BVP (4/4), Default Solvers (2/2), Public API Package Splits (12/12), and the zero-assertion Type Stability run also completed successfully.

Other checks

$ env JULIA_DEPOT_PATH=$DEPOT JULIA_PKG_PRECOMPILE_AUTO=0 GROUP=QA julia +1.12 --project=. -e 'using Pkg; Pkg.test()'
Test Summary: | Pass  Total     Time
QA            |   27     27  1m18.9s
Testing PreallocationTools tests passed

$ julia +1.12 --project=/home/crackauc/.julia/environments/runic -m Runic --check .
$ git diff | typos -
$ git diff --check

Runic, typos, and git diff --check exit successfully with no output.

Documentation was not built because this changes no public API, docstring, or documentation. GPU-specific paths were not run. The BoundaryValueDiffEq Misc group is the downstream integration coverage.

CI context

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>

Copy link
Copy Markdown
Member Author

Current-master revalidation update (upstream 329c9716174728758fd4c8d4e3ec506a5c4ea5ca):

  • The existing patch applies cleanly with an exact range-diff.
  • Clean current master still reproduces the promote_rule(BigFloat, SparseConnectivityTracer.Dual{BigFloat, ...}) ambiguity; the patched MWE succeeds for both cache types and preserves shared storage.
  • The focused SparseConnectivityTracer test is 26/26.
  • Full current GROUP=Core passes, including ODE 7/7, resizing 64/64, nested duals 4/4, sparsity support 4/4, Enzyme 26/26, lazy caches 13/13, zero/copy/fill dispatches 66/66, and allocation regressions 27/27.
  • Runic, typos, and git diff --check pass.

Current-master GROUP=QA is blocked by an unrelated clean-base public-doc rendering regression (26 pass/1 fail). That regression is now fixed and fully validated in the separate draft #205. I have not force-updated this branch onto current master while its exact QA tree is red; once the docs fix lands, this branch can be rebased and QA rerun without mixing the changes.

Copy link
Copy Markdown
Member Author

A fresh SciMLBase integration run on current dependency heads reproduces this exact downstream failure twice in BoundaryValueDiffEq.jl/All:

MethodError: promote_rule(::Type{BigFloat},
  ::Type{SparseConnectivityTracer.Dual{BigFloat, ...}}) is ambiguous
BigFloat compatibility with Multi-point BVP: Error
BigFloat compatibility: Error

This matches the current-master standalone reproduction and is additional evidence that the focused promotion fix in this PR is still needed.

CI job: https://github.com/SciML/SciMLBase.jl/actions/runs/32365988822/job/96415493078

Copy link
Copy Markdown
Member Author

Fresh full-source NonlinearSolve integration CI reproduces the same ambiguity through BoundaryValueDiffEq BigFloat tests: 3 passed / 2 errored, both at promote_rule(BigFloat, SparseConnectivityTracer.Dual{BigFloat,...}) in PreallocationTools.get_tmp. Job: https://github.com/SciML/NonlinearSolve.jl/actions/runs/32368371688/job/96422960783. This is additional downstream evidence for refreshing this draft after #205 lands.

@ChrisRackauckas
ChrisRackauckas marked this pull request as ready for review August 27, 2026 18:24
@ChrisRackauckas
ChrisRackauckas merged commit 20ee120 into SciML:master Aug 27, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants