Skip to content

Conversation

ChrisRackauckas-Claude
Copy link
Contributor

Summary

Fixes inconsistency in Enzyme extension where forward rule threw an error for Krylov methods while reverse rule properly supported them.

Problem

Issue #766 reported Enzyme differentiation failing with KrylovJL_GMRES. Investigation revealed:

  • Forward rule (line 61): Threw "Algorithm ... is currently not supported" error for AbstractKrylovSubspaceMethod
  • Reverse rule (lines 244-250): Had proper implementation for the same methods
  • This inconsistency caused Enzyme compilation to fail

Solution

Implemented proper forward differentiation for Krylov methods in the forward rule:

  • For equation y = A⁻¹b, computes dy/dt = A⁻¹(db/dt - dA/dt * y)
  • Creates new LinearProblem with original A and modified RHS: db - dA * res
  • Solves using same algorithm and tolerance settings
  • Maintains consistent structure with existing forward rule patterns

Changes

  • Fixed: Forward rule now handles AbstractKrylovSubspaceMethod instead of throwing error
  • Added: Test to verify forward rule no longer throws the specific "not supported" error
  • Improved: Consistency between forward and reverse rules for Krylov methods

Testing

  • ✅ Forward rule no longer throws "Algorithm not supported" error
  • ✅ Test added to prevent regression
  • ✅ Existing functionality preserved

Notes

This fixes the specific inconsistency in LinearSolve.jl's Enzyme extension. The broader issue in #766 involving constant variable handling may require additional work, but this addresses the immediate compilation error with Krylov methods.

🤖 Generated with Claude Code

- Implement proper forward differentiation for AbstractKrylovSubspaceMethod algorithms
- Previously, forward rule threw 'Algorithm not supported' error for Krylov methods
- Reverse rule already had correct implementation for these methods
- Add test to verify forward rule no longer throws the specific error

Addresses issue SciML#766 where KrylovJL_GMRES failed with Enzyme differentiation.
The forward rule now computes dy/dt = A^(-1)(db/dt - dA/dt * y) for Krylov methods.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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