Skip to content

sundials4py: expose optional KLU SUNLinearSolver bindings#966

Open
balos1 with Copilot wants to merge 18 commits into
developfrom
copilot/expose-klu-sunlinear-solver
Open

sundials4py: expose optional KLU SUNLinearSolver bindings#966
balos1 with Copilot wants to merge 18 commits into
developfrom
copilot/expose-klu-sunlinear-solver

Conversation

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor
  • Change summary
    • Problem: sundials4py exposed SUNLINEARSOLVER_KLU in enums but did not expose the KLU constructor/configuration APIs.
    • Bindings: Added KLU binding unit (sunlinsol_klu.cpp) and generated binding surface (sunlinsol_klu_generated.hpp) for SUNLinSol_KLU, SUNLinSol_KLUReInit, SUNLinSol_KLUSetOrdering, and SUNKLU_* constants.
    • Module registration: Registered KLU bindings in sundials4py.cpp behind #if defined(SUNDIALS_KLU_ENABLED).
    • Build wiring: Updated bindings/sundials4py/CMakeLists.txt to compile/link KLU bindings only when SUNDIALS_ENABLE_SUNLINSOL_KLU is enabled.
    • Generator metadata: Added sunlinsol_klu entry to bindings/sundials4py/sunlinsol/generate.yaml.
    • Python coverage: Added optional KLU creation test in test_sunlinearsolver.py with runtime skip when KLU is unavailable.
    • Python example: Added examples/python/arkode/ark_brusselator1D_klu.py, a Python port of the C KLU example (examples/arkode/C_klu/ark_brusselator1D_klu.c) demonstrating SUNLinSol_KLU in an ARKODE solve.
    • Documentation: Updated doc/shared/Python/Usage.rst with instructions for building sundials4py with KLU enabled via CMAKE_ARGS (including SuiteSparse discovery) and referenced the new KLU Python example.
from sundials4py.core import *
A = SUNSparseMatrix(n, n, n, SUN_CSC_MAT, sunctx)
LS = SUNLinSol_KLU(y, A, sunctx)
SUNLinSol_KLUSetOrdering(LS, SUNKLU_ORDERING_DEFAULT)

Copilot AI changed the title Python: expose optional SUNLinSol_KLU in sundials4py sundials4py: expose optional KLU SUNLinearSolver bindings Jun 24, 2026
Copilot AI requested a review from balos1 June 24, 2026 18:07
@balos1 balos1 changed the base branch from main to develop June 24, 2026 18:16

@balos1 balos1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a python example that uses the KLU SUNLinearSolver too. A python version of https://github.com/llnl/sundials/blob/main/examples/arkode/C_klu/ark_brusselator1D_klu.c would be good.

We also need to add to the docs how one can build sundials4py with KLU enabled.

Copilot AI requested a review from balos1 June 25, 2026 06:13
@balos1 balos1 added this to the SUNDIALS v7.9.0 milestone Jun 25, 2026
@balos1

balos1 commented Jun 25, 2026

Copy link
Copy Markdown
Member

@copilot the format_check is failing, apply the formatting

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot the format_check is failing, apply the formatting

Applied the formatting fix in commit 6ee9d1c. I ran ruff format on examples/python/arkode/ark_brusselator1D_klu.py and verified it now passes the formatting check.

@balos1 balos1 marked this pull request as ready for review July 1, 2026 00:11
@balos1 balos1 requested a review from drreynolds as a code owner July 1, 2026 00:11
@balos1 balos1 added the python label Jul 1, 2026
Comment thread bindings/sundials4py/sunlinsol/sunlinsol_klu_generated.hpp
Comment thread doc/shared/Python/Usage.rst Outdated
Comment thread doc/shared/Python/Usage.rst Outdated
Comment thread doc/shared/Python/Usage.rst Outdated
Comment thread examples/python/arkode/ark_brusselator1D_klu.py
Co-authored-by: Daniel R. Reynolds <dreynolds@umbc.edu>
Co-authored-by: Cody Balos <cjbalos@gmail.com>
Comment thread doc/shared/Python/Usage.rst Outdated
Comment thread doc/shared/Python/Usage.rst Outdated
balos1 and others added 4 commits July 6, 2026 11:47
Co-authored-by: Cody Balos <cjbalos@gmail.com>
#966 (comment)
#966 (comment)
#966 (comment)
#966 (comment)
#966 (comment)

Keep the KLU example mention removed from the Python usage text while preserving the examples role target so the documentation link remains valid.

Signed-off-by: Cody Balos <balos1@llnl.gov>
#966 (comment)

Add Python unit-test coverage for the KLU solver constructor, reinit, ordering, and factorization accessors. Register the opaque KLU accessor types so the getter bindings can return Python objects by reference.

Signed-off-by: Cody Balos <balos1@llnl.gov>
#966 (comment)

Use NumPy reshape in the KLU Brusselator example so N_Vector data is handled as (N, 3) arrays for state, residual, Jacobian, masks, and output.

Signed-off-by: Cody Balos <balos1@llnl.gov>
@balos1

balos1 commented Jul 7, 2026

Copy link
Copy Markdown
Member

@copilot apply the changes in the diff produced by the failing litgen_check

Copilot AI commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@copilot apply the changes in the diff produced by the failing litgen_check

Applied the litgen_check diff in commit 286a0e4.

Copilot finished work on behalf of balos1 July 7, 2026 16:08
Copilot AI requested a review from balos1 July 7, 2026 16:08
Comment thread bindings/sundials4py/sunlinsol/sunlinsol_klu_generated.hpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants