Skip to main content

Linear solvers and eigendecomposition for AWS Trainium via NKI

Project description

trnsolver

CI PyPI Python License Docs

Linear solvers and eigendecomposition for AWS Trainium via NKI.

Eigenvalue problems, matrix factorizations, and iterative solvers for scientific computing on Trainium. The Jacobi eigensolver is the primary NKI acceleration target — each Givens rotation maps to a 2-row matmul on the Tensor Engine.

Part of the trnsci scientific computing suite (github.com/trnsci).

Install

pip install trnsolver

# With Neuron hardware support
pip install trnsolver[neuron]

Usage

import torch
import trnsolver

# Symmetric eigenvalue decomposition (Jacobi on NKI)
eigenvalues, eigenvectors = trnsolver.eigh(A)

# Generalized eigenproblem: A x = λ B x (the SCF problem)
eigenvalues, eigenvectors = trnsolver.eigh_generalized(F, S)

# Factorizations
L = trnsolver.cholesky(A)
P, L, U = trnsolver.lu(A)
Q, R = trnsolver.qr(A)

# Direct solvers
x = trnsolver.solve(A, b)
x = trnsolver.solve_spd(A, b)        # Cholesky-based (faster for SPD)
A_inv_sqrt = trnsolver.inv_sqrt_spd(A)  # A^{-1/2} for density fitting

# Iterative solvers
x, iters, residual = trnsolver.cg(A, b, tol=1e-8)
x, iters, residual = trnsolver.gmres(A, b, tol=1e-6)

SCF Example

python examples/scf_eigen.py --demo
python examples/scf_eigen.py --nbasis 50 --nocc 10

Demonstrates the self-consistent field iteration: build Fock matrix → solve generalized eigenproblem FC = SCε → build density → check convergence.

Operations

Category Operation Description
Eigen eigh Symmetric eigendecomposition (Jacobi / torch)
Eigen eigh_generalized Generalized: Ax = λBx via Cholesky reduction
Factor cholesky A = LL^T
Factor lu PA = LU
Factor qr A = QR
Solve solve Ax = b (LU-based)
Solve solve_spd Ax = b (Cholesky, A is SPD)
Solve inv_spd A^{-1} for SPD A
Solve inv_sqrt_spd A^{-1/2} for density fitting metric
Iterative cg Conjugate Gradient (SPD systems)
Iterative gmres GMRES (general systems)

Status

  • Jacobi eigensolver with PyTorch backend
  • Generalized eigenvalue problem (Cholesky reduction)
  • Cholesky, LU, QR factorizations
  • Direct and SPD solvers
  • CG and GMRES iterative solvers
  • SCF example (quantum chemistry use case)
  • NKI Jacobi rotation kernel validation
  • Newton-Schulz A^{-1/2} via trnblas GEMM
  • Benchmarks vs LAPACK/cuSOLVER

Related Projects

Project What
trnfft FFT + complex ops
trnblas BLAS operations
trnsolver This repo

License

Apache 2.0 — Copyright 2026 Scott Friedman

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

trnsolver-0.3.0.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

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

trnsolver-0.3.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file trnsolver-0.3.0.tar.gz.

File metadata

  • Download URL: trnsolver-0.3.0.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trnsolver-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c641c3e6458d0175f179f9a1a63da8f5a03d49772f6444f786a89cec08b9ba1c
MD5 cbc10fcef4c86cd6cc242096c08d3d71
BLAKE2b-256 67bbc812189c675add3148b6ed14cd1af016d1b1af528cedaf476a370e7408b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for trnsolver-0.3.0.tar.gz:

Publisher: publish.yml on trnsci/trnsolver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trnsolver-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: trnsolver-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trnsolver-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc9e6ccf823552cc6095a0e56e7cbed6862667938e41e63aad273c2f45d12750
MD5 4883c797f14119c8d844bbc6cd538c71
BLAKE2b-256 716a794a0031606be0c9f1d76de8aa5f30908d208e9d67e051a1a18e823f5b26

See more details on using hashes here.

Provenance

The following attestation bundles were made for trnsolver-0.3.0-py3-none-any.whl:

Publisher: publish.yml on trnsci/trnsolver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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