Add low-level split-solve API for advanced users#18
Closed
Conversation
Exposes the following new FFI functions via pycapsule: - coo_to_csc: Convert COO format to CSC format (returns Bp, Bi, Bk) - solve_csc_f64: Solve using pre-computed CSC structure (float64) - solve_csc_c128: Solve using pre-computed CSC structure (complex128) This allows advanced users to reuse the COO->CSC conversion when solving multiple systems with the same sparsity pattern, which is useful for Newton-Raphson solvers in circuit simulation. Closes #16 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements handle-based caching to allow reusing symbolic analysis across multiple solves. This addresses the core request in issue #16 for Newton-Raphson optimization. New functions: - klu_analyze(Bp, Bi) -> symbolic_handle - klu_factor_f64/c128(sym_handle, Bp, Bi, Bx) -> numeric_handle - klu_solve_f64/c128(sym_handle, num_handle, b) -> x - klu_free_symbolic/numeric(handle) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
Hi @flaport Close, but not quite there yet :) I will try and find some time to dig through in more detail but the quick feedback is that these do not appear to be jit compatible (and I did not see it in the test suite either) All the tests use numpy and not jnp.numpy, is this intentional? For a non-linear+transitent solver the goal would be to pass jnp.arrays to a jitted function |
Owner
Author
|
Closing in favor of #19 |
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
Addresses #16 by exposing
klu_analyze,klu_factor, andklu_solveseparately for advanced users who need to optimize Newton-Raphson solvers by reusing symbolic analysis.New Functions in
klujax_cppTrue split-solve API (handle-based):
klu_analyze(Bp, Bi)- Symbolic analysis on CSC sparsity pattern. Returns a handle.klu_factor_f64(symbolic_handle, Bp, Bi, Bx)- Numeric factorization (float64). Returns a handle.klu_factor_c128(symbolic_handle, Bp, Bi, Bx)- Numeric factorization (complex128). Returns a handle.klu_solve_f64(symbolic_handle, numeric_handle, b)- Solve using pre-computed factorizations (float64).klu_solve_c128(symbolic_handle, numeric_handle, b)- Solve using pre-computed factorizations (complex128).klu_free_symbolic(handle)- Free a symbolic factorization handle.klu_free_numeric(handle)- Free a numeric factorization handle.FFI-based helpers:
coo_to_csc- Convert COO format (Ai, Aj) to CSC format (Bp, Bi, Bk)solve_csc_f64/solve_csc_c128- Solve using pre-computed CSC structureUsage Example (Newton-Raphson)
The key benefit is that
klu_analyze(the expensive symbolic analysis) only needs to be called once per sparsity pattern, whileklu_factorcan be called repeatedly with different values.Note: These are low-level functions accessible via
klujax_cppmodule. The high-levelklujax.solveAPI remains unchanged.Test plan
klujax_cppCloses #16
🤖 Generated with Claude Code