Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrixpfn-0.1.7.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matrixpfn-0.1.7-py3-none-any.whl (45.4 kB view details)

Uploaded Python 3

File details

Details for the file matrixpfn-0.1.7.tar.gz.

File metadata

  • Download URL: matrixpfn-0.1.7.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for matrixpfn-0.1.7.tar.gz
Algorithm Hash digest
SHA256 cadb9da18f1ae75996cebe6f5b0bc96a4349af777c496f1aaa5855e8ccd7b5b0
MD5 0ab280c9494cd249aa577db8ffd92ca4
BLAKE2b-256 0df32be83b9c596cd08a5489515043e53d71eaeb1f0aa5086e8f2c84c9801c95

See more details on using hashes here.

File details

Details for the file matrixpfn-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: matrixpfn-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 45.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for matrixpfn-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 8b224ef38b4edbb28640760464c7b53e8029090c8ac154b28bfbfe95d4048ce1
MD5 c6bd7987e8d71f8f7a042bbcb9fe6e49
BLAKE2b-256 5eb1a108d2e68d32d8c73c36fd7717f13461dc95c966b99e7105d8a5156d0c37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page