Skip to content

Randomized numerical linear algebra ​

Module: sci_form::rand_nla (core since 2026-11-08; F93 validated) Feature flag: none — beta-randnla and experimental-randnla are compatibility aliases; sci_form::beta::rand_nla re-exports the core module.


Validation and limits ​

QuestionAnswer
Compared withexact symmetric eigensolver (NumPy/SciPy)
Measured separationrank-N/4 3.8e-4 with power iterations; N=600, k=160, 9.6e-4, ~80 ms vs ~143 ms
Confidence regionnear-identity or gapped EHT, k ≥ N/4, lowest four states
Main limitationthe full-spectrum path still relies on the exact fallback; clustered spectra degrade

The raw rows and the exact tolerances are in the full validation matrix.


Overview ​

Replaces the O(N3) EHT diagonalization with the Randomized Nyström Approximation, reducing cost to O(N2) or O(Nlog⁡N) for sparse matrices. This enables EHT calculations on systems of thousands of atoms where full diagonalization is impractical.


Theory ​

Nyström Approximation ​

Given a symmetric matrix S∈RN×N:

  1. Sketch: Generate Ω∈RN×k with Gaussian entries.
  2. Project: Compute Y=SΩ via sparse-dense multiplication
  3. Reconstruct: B=QTSQ and S≈QBQT, with Y=QR.

The rank parameter k=min(N,50+⌈log⁡N⌉) controls accuracy vs. speed.

Randomized S−1/2 ​

Via randomized SVD: S≈UΣVT, then S−1/2≈UΣ−1/2UT with truncated singular values.

Randomized Diagonalization ​

The transformed Hamiltonian H~=S−1/2HS−1/2 is diagonalized using a sketch + Rayleigh–Ritz projection. For N > 500, solve_eht_randnla_lowrank replaces the full N×N diagonalization with a reorthogonalized Lanczos iteration on a randomized start and returns only the requested lowest states.


API ​

The low-level interface works on the Hamiltonian and overlap matrices:

rust
use nalgebra::DMatrix;
use sci_form::rand_nla::{
    solve_eht_randnla, solve_eht_randnla_lowrank, RandNlaConfig,
};

let h: DMatrix<f64> = /* EHT Hamiltonian, eV */;
let s: DMatrix<f64> = /* overlap matrix */;
let config = RandNlaConfig {
    sketch_size: Some(50), // k; None = 50 + ceil(log2 N)
    seed: 42,
    max_error: 1e-3,
    fallback_enabled: true,
    power_iterations: 2,
};

// Full randomized generalized eigensolver (all N eigenpairs).
let (energies, c, info) = solve_eht_randnla(&h, &s, &config);

// N > 500 path: only the lowest `n_eigen` states, no N×N diagonalization.
let low = solve_eht_randnla_lowrank(&h, &s, &config, 4);
// low.eigenvalues, low.eigenvectors, low.info

The convenience wrapper that assembles the EHT matrices is eht::solve_eht_randnla(elements, positions, k, config), which returns (EhtResult, RandNlaInfo) — the usual EHT result plus rank/residual/fallback metadata. k is the optional Wolfsberg–Helmholtz constant (None = default).

The Nyström building block is public as NystromApprox::from_matrix_with_power_iterations(&s, &sketch, q) with GaussianSketch::new(&mut rng, n, k).


Error Control ​

The module includes automatic error estimation:

error=∥HC−SCE∥F∥SCE∥F

If the error exceeds 0.1%, the module falls back to exact diagonalization and reports in the rand_nla_error field.


Validation (F93, 2026-10-14) ​

External gate tests/beta_randnla_validation.rs vs scripts/validation/oracle_randnla.py (numpy/scipy, overlap spectra): single-shot rank-N/4 ~0.13, near-identity regime 3.9e-3 with fallback OFF, default config exact incl. exercised fallback at N=96.

Subspace iterations (2026-11-07): NystromApprox::from_matrix_with_power_iterations and RandNlaConfig::power_iterations add re-orthonormalised power iterations. With 384 iterations the same rank-N/4 sketches reach 3.8e-4 (F93a-bis), so the <1e-3 accuracy criterion is met for the fixture.

EHT backend (2026-11-07): eht::solve_eht_randnla assembles the EHT Hamiltonian/overlap exactly as solve_eht and routes the generalized eigenproblem through the randomized solver, returning the usual EhtResult plus the rank/residual/fallback metadata.

N>500 path (2026-11-08): solve_eht_randnla_lowrank uses Nyström for S^{-1/2} and a reorthogonalized Lanczos iteration on a randomized start, so it never forms or diagonalizes the full N × N transformed Hamiltonian. Measured on N = 600, k = 160: the four lowest states have 9.6e-4 relative error and the call takes ~80 ms versus ~143 ms for the exact symmetric diagonalization. The module is core; the full-spectrum path still uses the exact fallback, and that limitation is recorded in the validation report.

Tests ​

bash
cargo test --test experimental_gates -- test_randnla

8 integration tests (tests/experimental/test_randnla.rs) covering: sketch matrix statistics, Nyström reconstruction error, randomized SVD accuracy, and EHT eigenvalue comparison against exact diagonalization for benzene and naphthalene.

These tests live in the experimental_gates target — see Overview for the full command matrix.

Released under the MIT License.