GNN-based learned preconditioner for sparse linear systems
Project description
MatrixPFN
GNN-based learned preconditioner for sparse linear systems. A Graph Neural Network learns to approximate the inverse matrix application $A^{-1}r$, then serves as a preconditioner inside an FGMRES solver.
Based on the GNP paper (Graph Neural Preconditioner), extended with context-based learning to generalize across unseen matrices at runtime.
Method
Sparse Matrix A
│
▼
ContextResGCN ◄── context pairs (x, Ax)
│
▼
MatrixPFN.apply(r) ≈ A⁻¹r
│
▼
FGMRES(A, b, preconditioner=MatrixPFN)
│
▼
Solution x
The key contribution over GNP is ContextResGCN: the GCN receives context pairs $(x, Ax)$ that encode information about the current matrix, enabling a single trained model to precondition unseen matrices via set_matrix() at runtime. FGMRES (Flexible GMRES) is required because the neural preconditioner is nonlinear.
Requirements
- Python 3.13
- CUDA-capable GPU (recommended)
Setup
uv sync
Training
uv run python experiments/poc_experiment.py
Evaluation
SuiteSparse Matrices
Download the 867 evaluation matrices (square, real, non-SPD, 1K–100K rows, <2M nnz) matching the GNP paper:
uv run python ../data/download_suitesparse.py
Offline Dataset Generation
Generate synthetic training matrices and save to disk:
from matrixpfn.generator import GeneratorConfig, build_training_registry
from matrixpfn.generator.offline import OfflineGenerationRunner
config = GeneratorConfig(grid_size=32)
registry = build_training_registry(config, device)
runner = OfflineGenerationRunner(registry, output_dir, num_matrices_per_domain=1000, num_context_pairs=10)
runner.run()
Architecture
src/matrixpfn/
├── nn/ # ContextResGCN — the core GNN
├── solver/ # FGMRES + Arnoldi decomposition
├── precond/ # Preconditioner implementations
│ ├── matrix_pfn.py # Neural preconditioner (wraps ContextResGCN)
│ ├── jacobi.py # Diagonal scaling
│ ├── ilu.py # Incomplete LU factorization
│ ├── amg.py # Algebraic Multigrid (SA + AIR)
│ ├── block_jacobi.py # Block-diagonal LU
│ └── gmres_preconditioner.py # Inner-outer GMRES
└── generator/ # Synthetic matrix generators (13 domains)
├── base.py # MatrixDomain enum, BatchMatrixData, MatrixGenerator protocol
├── registry.py # MatrixGeneratorRegistry + factory functions
└── offline/ # Save-to-disk generation pipeline
Matrix Domains
| Domain | Type | Source |
|---|---|---|
| Diffusion | 5-point stencil PDE | Synthetic |
| Diffusion-Advection | PDE with convection | Synthetic |
| Graph Laplacian | Barabási-Albert model | Synthetic |
| Elasticity | 2D plane stress | Synthetic |
| Stokes | Saddle-point block structure | Synthetic |
| SBM | Stochastic Block Model | Synthetic |
| Spectral Stress | Condition number scaling | Synthetic |
| Variable Diffusion | Multi-grid-size, material jumps | Synthetic |
| Variable Advection | Variable grid + advection | Synthetic |
| Enhanced Diffusion | Anisotropic, holes, permutation | Synthetic |
| Enhanced Advection | Enhanced diffusion + advection | Synthetic |
| Fast Graph Laplacian | igraph-based Barabási-Albert | Synthetic |
| SuiteSparse | Real-world sparse matrices | SuiteSparse Collection |
Reference
@article{chen2024gnp,
title={Graph Neural Preconditioners for Iterative Solutions of Sparse Linear Systems},
author={Chen, Jie and Hua, Yousef and Mukherjee, Subhadeep and Bai, Yu},
journal={arXiv preprint arXiv:2406.00809},
year={2024}
}
License
This project is part of a bachelor's thesis and is not licensed for redistribution.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file matrixpfn-0.2.0.tar.gz.
File metadata
- Download URL: matrixpfn-0.2.0.tar.gz
- Upload date:
- Size: 30.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4178773a6f08de32f874e0ce0326b55c8bf3736699360c2cab69b5877d8cd1c
|
|
| MD5 |
4363b93f4ebdb3edfd0d5da82eb32706
|
|
| BLAKE2b-256 |
cc1eb1fcf386f839ee971996c50817bbb8a91ab1062575f156eee1fca6ae5127
|
Provenance
The following attestation bundles were made for matrixpfn-0.2.0.tar.gz:
Publisher:
publish.yml on Csed-dev/MatrixPFN
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matrixpfn-0.2.0.tar.gz -
Subject digest:
c4178773a6f08de32f874e0ce0326b55c8bf3736699360c2cab69b5877d8cd1c - Sigstore transparency entry: 1101870773
- Sigstore integration time:
-
Permalink:
Csed-dev/MatrixPFN@f9b7e0a9aa07fa3b33918b3a92809ff60c40f692 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Csed-dev
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f9b7e0a9aa07fa3b33918b3a92809ff60c40f692 -
Trigger Event:
push
-
Statement type:
File details
Details for the file matrixpfn-0.2.0-py3-none-any.whl.
File metadata
- Download URL: matrixpfn-0.2.0-py3-none-any.whl
- Upload date:
- Size: 50.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6a3cfb26fa3377ca28cab6a62aa43e3c6c8fd2bc4b35c33bd631fc300a54dd9
|
|
| MD5 |
aefe5ce400f54b2b68248371ea5840d5
|
|
| BLAKE2b-256 |
1f81c0e23dbfc1d190922f5655aea485dceaf5c7b47dd5530b696626c28f1e15
|
Provenance
The following attestation bundles were made for matrixpfn-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Csed-dev/MatrixPFN
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matrixpfn-0.2.0-py3-none-any.whl -
Subject digest:
a6a3cfb26fa3377ca28cab6a62aa43e3c6c8fd2bc4b35c33bd631fc300a54dd9 - Sigstore transparency entry: 1101870819
- Sigstore integration time:
-
Permalink:
Csed-dev/MatrixPFN@f9b7e0a9aa07fa3b33918b3a92809ff60c40f692 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Csed-dev
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f9b7e0a9aa07fa3b33918b3a92809ff60c40f692 -
Trigger Event:
push
-
Statement type: