Skip to main content

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

Metadata

Release files for trnsolver 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trnsolver 0.3.0
File Size Uploaded
trnsolver-0.3.0.tar.gz 40.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trnsolver 0.3.0
File Interpreter ABI Platform
trnsolver-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.0 kB

Release files / trnsolver-0.3.0.tar.gz

Download URL trnsolver-0.3.0.tar.gz
Size 40.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c641c3e6458d0175f179f9a1a63da8f5a03d49772f6444f786a89cec08b9ba1c
BLAKE2b-256 checksum
How to use checksums
67bbc812189c675add3148b6ed14cd1af016d1b1af528cedaf476a370e7408b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

Release files / trnsolver-0.3.0-py3-none-any.whl

Download URL trnsolver-0.3.0-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc9e6ccf823552cc6095a0e56e7cbed6862667938e41e63aad273c2f45d12750
BLAKE2b-256 checksum
How to use checksums
716a794a0031606be0c9f1d76de8aa5f30908d208e9d67e051a1a18e823f5b26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page