Skip to content

sci-solvers

CI Docs Python License

Selected configuration interaction (SCI) eigensolvers behind one interface. Given sampled electronic configurations (for example from a quantum computer, in sample-based quantum diagonalization), each solver diagonalizes the molecular Hamiltonian projected onto that subspace. The package wraps external diagonalizers, provides native CPU/GPU solvers, and ships build recipes for the external binaries. Every solver plugs into qiskit-addon-sqd's SQD loop as its sci_solver, or can be called standalone on CI-string batches.

⚡ TorchSCISolver is our native PyTorch/Triton solver for CPU, GPU and distributed diagonalization. Start with its feature examples, or browse the documentation and Python API reference. Please cite our paper if you use the library.

Installation

Dependencies are managed with uv, which is the supported install. From a clone of this repository:

uv sync

Optional backends are extras, e.g. uv sync --extra fulqrum, --extra sbd, or --extra external-solvers (PRIMME and SLEPc). torch-sci-solver (under packages/torch-sci-solver) is a workspace member installed by uv sync. Solvers that run an external binary (Dice, EVSL) need it built first; see scripts/energy_solvers/README.md.

Supported solvers

General-algebra solvers (multi-root)

Use create_solver(name, nroots=k, ...) to request the lowest k roots. Read all roots with sci_solver_callable_eigen_states(...); the SQD convenience interface returns the ground state of each batch.

Install all external backends at once with uv sync --extra external-solvers.

The general-algebra solvers share a Hamiltonian interface and support multi-root solving. See the guide for basis modes, spin projection and optional backends.

TorchSCISolver basis modes: TPB vs GDB

  • TPB (mode="tpb", default): independent alpha and beta string sets define their Cartesian product, of dimension len(strs_a) * len(strs_b).
  • GDB (mode="gdb"): parallel arrays define explicit determinant pairs (strs_a[i], strs_b[i]), of dimension len(strs_a) after deduplication.

For GDB, preserve the alpha/beta pairing. bitstring_matrix_to_ci_strs deduplicates spin sets independently and is intended for TPB. Use torch_sci_solver.diagonalize_fermionic_hamiltonian_pairs for a GDB SQD loop. See the solver guide for input formats and options.

TorchSCISolver distributed diagonalization (one subspace across GPUs)

With distributed=..., the GPUs cooperate on one large subspace: Davidson vectors and matrix-vector work are partitioned across ranks. This increases the size of an individual diagonalization. It differs from devices=[...], which assigns independent batches to separate GPUs.

Single-node size and runtime summary:

Basis Subspace dimension Runtime
TPB 1 billion ≈30 min
GDB 300 million ≈13 h

TPB uses a conservative rounded Davidson time; GDB reports the full solver call.

-Hardware and system: 8 NVIDIA A100-SXM4-80GB GPUs, ground state of transition-metal complex molecule 751 from the benchmark dataset: 60 spatial orbitals (120 bits), a real Hamiltonian and 41α + 41β electrons. Bases were generated from Hartree–Fock excitation levels. GDB used FP32 arithmetic and Davidson storage; TPB used FP64 arithmetic and FP32 Davidson storage. See the distributed guide for settings and memory guidance.

To distribute one TPB subspace across eight GPUs, save the following as solve.py and launch it with torchrun --standalone --nproc-per-node=8 solve.py. ci_strings.npz contains the alpha and beta arrays strs_a and strs_b.

import numpy as np
import torch

from sci_solvers.energy_solvers.factory import create_solver
from sci_solvers.hamiltonian import HamiltonianData

ham = HamiltonianData.from_fcidump("FCIDUMP")
basis = np.load("ci_strings.npz")
solver = create_solver(
    "torch_sci",
    symmetrize_spin=False,
    hamiltonian=ham,
    mode="tpb",
    dtype=torch.float32,
    davidson_dtype=torch.float32,
    davidson_block_size=4,
    distributed={"world_size": 8, "backend": "nccl"},
)
results = solver.compute_energy(ci_strs_batches=[(basis["strs_a"], basis["strs_b"])])

The solver uses the launcher's ranks; rank 0 receives the results.

TorchSCISolver multi-GPU (single node, batch-parallel)

Use devices to diagonalize independent batches on separate GPUs:

from sci_solvers.energy_solvers.factory import create_solver
from sci_solvers.hamiltonian import HamiltonianData

ham = HamiltonianData.from_fcidump("FCIDUMP")
solver = create_solver(
    "torch_sci", symmetrize_spin=False, devices=["cuda:0", "cuda:1"], hamiltonian=ham
)

Each subspace must fit on one GPU. This setting parallelizes batches; use distributed to share a single large subspace across GPUs.

Example usage

See src/examples for runnable scripts, and docs/solvers for a guide to every solver. A minimal SQD run with the torch_sci solver:

from qiskit_addon_sqd.fermion import diagonalize_fermionic_hamiltonian
from torch_sci_solver.shots import load_shots_bit_array

from sci_solvers.energy_solvers.factory import create_solver
from sci_solvers.hamiltonian import HamiltonianData

ham = HamiltonianData.from_fcidump("path/to/FCIDUMP")
solver = create_solver("torch_sci", symmetrize_spin=True, device="cuda", hamiltonian=ham)
bit_array = load_shots_bit_array("path/to/shots.pkl")

result = diagonalize_fermionic_hamiltonian(
    one_body_tensor=ham.hcore,
    two_body_tensor=ham.eri,
    bit_array=bit_array,
    samples_per_batch=512,
    norb=ham.num_orbitals,
    nelec=(ham.num_elec_a, ham.num_elec_b),
    max_iterations=3,
    sci_solver=solver.sci_solver_callable,
    max_dim=2000,
    num_batches=1,
    symmetrize_spin=True,
)

print(f"electronic energy: {result.energy:.8f} Ha")
print(f"total energy:      {result.energy + ham.e_nuc:.8f} Ha")

Development

Install the dev dependencies and the pre-commit hooks once after cloning:

uv sync
uv run pre-commit install

Run the tests (the top-level tests/ and packages/torch-sci-solver/tests/):

uv run pytest -v
# skip slow tests:
uv run pytest -v -m "not slow"

Tests that need an external binary, a GPU, or an optional extra skip when it is missing. The FCIDUMPs and samples of SqDRIFT hardware shots of methane and benzoic acid (IDs 001 and 182 of the SQD molecules dataset) used by some tests are bundled (see packages/torch-sci-solver/torch_sci_solver/data/README.md).

Lint, format, and type-check:

uv run ruff check --fix
uv run ruff format
uv run mypy

scripts/local_ci.sh runs the same checks and tests as CI (.github/workflows/ci.yml); scripts/local_ci.sh --gpu also runs the GPU, sbd and slow tests that CI skips (it needs an NVIDIA GPU and the NVIDIA HPC SDK).

Preview the documentation locally (only the docs dependencies are installed):

uv run --project docs python scripts/build_docs.py --serve

Commit messages follow conventional commits (feat:, fix:, test:, ...). Contributions are accepted under the Developer's Certificate of Origin: sign off each commit with git commit -s.

License

Apache License 2.0. Every source file carries the header in LICENSE.tmpl.

Parts of torch-sci-solver are modified Python ports of RIKEN's SBD (Apache-2.0); see NOTICE for the copyright holders. The bundled test data is from the SQD molecules dataset (CDLA-Permissive-2.0); see packages/torch-sci-solver/torch_sci_solver/data/README.md.

Citation

If you use sci-solvers in your work, please cite our benchmark paper:

Alex Golts et al., Eigensolvers for sample-based quantum diagonalization: a controlled benchmark (2026). Manuscript last updated November 21, 2026.

@unpublished{golts2026eigensolvers,
  title = {Eigensolvers for sample-based quantum diagonalization: a controlled benchmark},
  author = {Golts, Alex and
            Shoshan, Yoel and
            Levine, Yishai and
            Hamri, May and
            Born, Jannis and
            Ruch, Patrick and
            Ratner, Vadim and
            Raboh, Moshiko and
            Van Elst, Anna and
            Zipoli, Federico and
            Cadow-Gossweiler, Joris and
            Kosugi, Akihiro and
            Schaller, Joris and
            Hexter, Efrat and
            Manica, Matteo},
  year = {2026},
  note = {Manuscript}
}

Also cite the external methods you use; their papers and code are linked in Supported solvers.