Add Tikhonov regularization to dense solvers to fix GPU CI singular matrix errors#8
Open
Add Tikhonov regularization to dense solvers to fix GPU CI singular matrix errors#8
Conversation
…ix errors JAX's scipy.linalg.solve raises a hard error on singular matrices, unlike UMFPACK which can issue a warning and continue. This was causing GPU CI tests to fail with "INTERNAL: Singular matrix in linear solve" for circuits with high condition numbers (like graetz with 1GΩ grounding resistors). The fix adds small Tikhonov regularization (1e-14 * I) to the Jacobian before solving, matching the approach already used in jax_spice/analysis/solver.py. This prevents numerical singularity without meaningfully affecting results. Applied to both make_dense_full_mna_solver and make_dense_solver factory functions. Co-developed-by: Claude Code v2.1.19 (claude-opus-4-5-20251101)
Extend the regularization fix to sparse solvers (make_sparse_full_mna_solver and make_sparse_solver) which were still failing with "Singular matrix in linear solve" errors on GPU. For sparse matrices, regularization is added by: 1. Pre-computing CSR indices for all diagonal elements 2. Adding 1e-14 to those diagonal entries before spsolve This matches the dense solver fix but adapted for CSR sparse format. Co-developed-by: Claude Code v2.1.19 (claude-opus-4-5-20251101)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
GPU CI tests were failing with:
This occurred because
jax.scipy.linalg.solveraises a hard error on singular/near-singular matrices, unlike UMFPACK which can issue a warning and continue.Solution
Added the same regularization approach already used in
jax_spice/analysis/solver.pyto the factory functions:make_dense_full_mna_solver(line 230)make_dense_solver(line 694)The fix adds
reg = 1e-14 * jnp.eye(J.shape[0], dtype=J.dtype)before solving, making the Jacobian always invertible without meaningfully affecting simulation accuracy.Test plan
🤖 Generated with Claude Code