Skip to content

Comments

Add Tikhonov regularization to dense solvers to fix GPU CI singular matrix errors#8

Open
robtaylor wants to merge 2 commits intomainfrom
fix/ci-singular-matrix
Open

Add Tikhonov regularization to dense solvers to fix GPU CI singular matrix errors#8
robtaylor wants to merge 2 commits intomainfrom
fix/ci-singular-matrix

Conversation

@robtaylor
Copy link
Contributor

Summary

  • Add small Tikhonov regularization (1e-14 * I) to dense solver factory functions to prevent "Singular matrix in linear solve" errors on GPU

Problem

GPU CI tests were failing with:

jax.errors.JaxRuntimeError: INTERNAL: Singular matrix in linear solve

This occurred because jax.scipy.linalg.solve raises 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.py to 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

  • GPU CI tests pass (particularly graetz benchmark)
  • Benchmark comparison passes without timeout

🤖 Generated with Claude Code

…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)
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.

1 participant