Skip to content

Avoid hashconsing ForwardDiff dual constants in remakes#4716

Draft
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:agent/fix-remake-dual-hashcons-ordering
Draft

Avoid hashconsing ForwardDiff dual constants in remakes#4716
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:agent/fix-remake-dual-hashcons-ordering

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Contributor

Ignore until reviewed by @ChrisRackauckas.

This fixes the downstream Optimization.jl IntegrationTest failure in ModelingToolkit initialization tests where SciMLBase.remake could throw Cannot determine ordering of Dual tags ... and Nothing. The failure is triggered after ForwardDiff-tagged symbolic constants enter SymbolicUtils hashconsing state, then initialization remake varmaps convert ForwardDiff dual values through the normal BasicSymbolic constant path.

The change keeps normal symbolic varmap conversion for ordinary values, but uses an unsafe symbolic constant wrapper for varmap values that contain ForwardDiff.Dual, avoiding tag-order comparisons during hashconsing. The same helper is used by build_operating_point and initialization remake data conversion.

Local verification:

  • Before the patch, a direct reproducer that first seeds ForwardDiff through an ODEProblem constructor and then remakes ODE/SDE/DDE initialization data failed with Cannot determine ordering of Dual tags ForwardDiff.Tag{...} and Nothing.
  • After the patch, the same direct reproducer completed all ODE/SDE/DDE remake blocks.
  • Ran GROUP=Initialization timeout 3600 /home/crackauc/.juliaup/bin/julia +1.12 --project=/home/crackauc/sandbox/tmp_20260708_165240_11300/repro/ModelingToolkit -e 'using Pkg; Pkg.test(coverage=false)' with local JULIA_DEPOT_PATH and Optimization.jl e535903bf0ed6ca3aeedeafeee2879beb2dd2fd1 developed.
    Result: Test Summary: Initialization | 794 pass | 12 broken | 806 total | 43m34.8s; Testing ModelingToolkit tests passed.
  • Ran Runic check on all changed files: passed with exit 0.

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

Copy link
Copy Markdown
Member

unsafe = true is evil and should not be used outside of SU. If this unsafe constant makes it inside another symbolic expression it can cause untold havoc.

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.

3 participants