Distributed diagonalization¶
Use distributed when one subspace is too large for a single GPU. Each rank stores
part of the Davidson vectors and computes part of the matrix-vector product.
TPB, GDB and spinless bases support distributed solving with real or complex
integrals and single or multiple roots.
This differs from devices=[...], which assigns independent batches to GPUs.
Run on one node¶
Save this example as solve.py and launch it on eight GPUs:
torchrun --standalone --nproc-per-node=8 solve.py
The FCIDUMP contains the Hamiltonian; ci_strings.npz contains alpha and beta
integer arrays named 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"])])
Every rank runs the same call. The solver initializes the process group from the
launcher environment and returns the solved states on rank 0. For GDB, set
mode="gdb" and pass parallel alpha/beta arrays, one pair per determinant.
For CPU ranks, set device="cpu" and backend="gloo". Multi-node launches use torchrun;
input files and any result or checkpoint directories must be visible to all ranks.
Layout and memory¶
The default matvec="local" partitions output work across ranks. tile="auto"
selects a two-dimensional grid when the memory policy calls for it. An explicit
tile=[2, 4] selects a 2×4 grid on eight ranks.
Option inside distributed |
Purpose |
|---|---|
world_size |
Number of ranks. |
backend |
"nccl" for CUDA; "gloo" for CPU. |
tile |
"auto", "force", an explicit grid, or None. |
budget_bytes |
Per-rank budget used by automatic tiling. |
exchange_bytes |
Bound on each staged tile exchange. |
hand_back |
"auto", "memory" or "memmap" for returning amplitudes. |
hand_back_dir |
Shared directory for memory-mapped results. |
The vector partition reduces per-rank storage, but integrals and some lookup data
remain replicated. Capacity therefore does not scale directly with GPU count.
memory_budget_bytes also guides workspace and automatic Davidson sizing; it is
not a cap on total process memory. Full RDMs require additional work and storage.
Use solver.preflight(ci_strings, nelec, norb=norb) to inspect the planned layout
and estimated memory before solving. Estimates exclude some transient allocations;
measure peak memory for the intended workload.
Precision and convergence¶
dtype controls Hamiltonian arithmetic; davidson_dtype controls Davidson storage.
Set both to torch.float32 for a full FP32 solve. To retain FP64 arithmetic with
smaller Davidson vectors, use dtype=torch.float64, davidson_dtype=torch.float32.
The corresponding complex types are complex128 and complex64.
Choose a residual tolerance appropriate to the precision. Reducing storage precision changes numerical accuracy and can affect convergence. Warm starts, multiple roots and spin penalties are supported; see the solver options for their input contracts.
Checkpoint and resume¶
Checkpointing saves each subspace's Davidson state to a shared directory.
Add these entries to distributed:
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,
hamiltonian=ham,
distributed={
"world_size": 8,
"backend": "nccl",
"checkpoint_dir": "/shared/checkpoints",
"checkpoint_every": 50,
"checkpoint_resume": "auto",
},
)
Use this configuration in the torchrun example above. "auto" resumes a matching
checkpoint or starts cold when none exists. "require" requires a complete
checkpoint; "off" ignores existing state. A checkpoint for a different basis or
Hamiltonian is rejected.
Capacity and memory¶
| 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 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, Davidson size 20, residual tolerance 5e-3, a 2×4 grid, an 8 GiB scratch budget per rank, and 800 GiB host RAM allocated to the job. Full RDMs, S² diagnostics and alpha–beta projection were disabled. Wall-clock time includes input loading, basis generation, setup, connectivity, Davidson and result return; scheduling and installation are excluded. TPB used FP64 arithmetic and FP32 Davidson storage, Davidson size 9 and residual tolerance 1e-5.
The 300M runtime was reported separately; its memory peaks are not recorded here.
See the engine API for complete option definitions and return types.