Skip to content

Conversation

@ChrisRackauckas-Claude
Copy link
Contributor

Summary

  • Adds ReactantCore.jl as a dependency to NonlinearSolveBase and SimpleNonlinearSolve
  • Introduces @trace macros to data-dependent control flow throughout the solver libraries, enabling proper compilation with Reactant.jl for XLA/GPU acceleration
  • Adds Reactant AD tests for SimpleNewtonRaphson, SimpleBroyden, and NewtonRaphson solvers

Details

The @trace macro from ReactantCore.jl is required for data-dependent control flow (if/else, while, for loops with data-dependent conditions) when compiling with Reactant to ensure proper tracing through XLA.

Files modified:

Dependencies:

  • lib/NonlinearSolveBase/Project.toml - Added ReactantCore dependency
  • lib/SimpleNonlinearSolve/Project.toml - Added ReactantCore dependency
  • Project.toml - Added Reactant to test dependencies

Core solve logic:

  • lib/NonlinearSolveBase/src/NonlinearSolveBase.jl - Import @trace
  • lib/NonlinearSolveBase/src/solve.jl - Added @trace to main solve loop and conditionals
  • lib/NonlinearSolveBase/src/termination_conditions.jl - Added @trace to convergence checks

SimpleNonlinearSolve solvers:

  • lib/SimpleNonlinearSolve/src/raphson.jl
  • lib/SimpleNonlinearSolve/src/broyden.jl
  • lib/SimpleNonlinearSolve/src/dfsane.jl
  • lib/SimpleNonlinearSolve/src/halley.jl
  • lib/SimpleNonlinearSolve/src/klement.jl
  • lib/SimpleNonlinearSolve/src/lbroyden.jl
  • lib/SimpleNonlinearSolve/src/trust_region.jl

Tests:

  • test/adjoint_tests.jl - Added Reactant AD tests using Enzyme Forward and Reverse modes

Test plan

  • Verify existing adjoint tests still pass
  • Verify new Reactant AD tests pass with @jit compilation
  • Test with different solvers (SimpleNewtonRaphson, SimpleBroyden, NewtonRaphson)

🤖 Generated with Claude Code

This PR adds ReactantCore.jl as a dependency and introduces `@trace` macros to
data-dependent control flow throughout the solver libraries, enabling proper
compilation with Reactant.jl for XLA/GPU acceleration.

Changes:
- Add ReactantCore.jl dependency to NonlinearSolveBase and SimpleNonlinearSolve
- Add `@trace` macros to main solve loops and termination conditions in:
  - NonlinearSolveBase/src/solve.jl
  - NonlinearSolveBase/src/termination_conditions.jl
  - All SimpleNonlinearSolve solvers (raphson, broyden, dfsane, halley,
    klement, lbroyden, trust_region)
- Add Reactant to test dependencies
- Add Reactant AD tests for SimpleNewtonRaphson, SimpleBroyden, and NewtonRaphson

The `@trace` macro is required for data-dependent control flow (if/else, while,
for loops with data-dependent conditions) when compiling with Reactant to
ensure proper tracing through XLA.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@ChrisRackauckas
Copy link
Member

While this could technically work, I assume this is never how we'd want to do this here? @avik-pal .

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