Skip to content

torch_sci_solver.torch_impl.sbdiag

Top-level driver — torch analog of torch_sci_solver.sbd_ref.sbdiag.diag.

Builds the helpers and integrals on CPU once (cheap, ragged enumeration isn't worth GPU-vectorizing for the basis sizes SBD targets), then runs Davidson + matvec entirely on the target device.

The interface mirrors the scalar diag() so swapping the import line gets you the GPU version.

diag_torch

diag_torch(adets: List[int], bdets: List[int], n_orb: int, I0: float, I1: OneInt, I2: TwoInt, *, max_davidson_iters: int = 50, davidson_block_size: int = 30, eps: float = 1e-08, de_tol: float | None = None, init: int = 0, n_roots: int = 1, device: device | str = 'cpu', dtype: dtype = float64, chunk_size: int = 2000000, matvec_impl: str = 'torch', verbose: bool = False, mode: Literal['tpb', 'gdb'] = 'tpb', pair_budget_bytes: int | None = None, block_matvec: str = 'off') -> Tuple[float | Tensor, Tensor, dict]

Lowest eigenpairs — torch port of diag().

Parameters:

Name Type Description Default
adets, bdets

In TPB mode (mode="tpb", default), sorted α and β bitmask lists (Python ints), each over n_orb bits, joined into an M_α · M_β Cartesian product basis. adets[0] = HF reference. In GDB mode (mode="gdb"), interpreted as parallel length-N lists: index i defines pair (adets[i], bdets[i]) and the basis dimension is N after dedup by (α, β). See :mod:torch_sci_solver.torch_impl.pairs.

required
n_orb int

number of spatial orbitals.

required
I0, I1, I2

integrals from setup_integrals_from_pyscf_h1_eri.

required
max_davidson_iters int

outer Davidson restart count.

50
davidson_block_size int

subspace expansion per restart.

30
eps float

residual-norm convergence threshold.

1e-08
de_tol float | None

opt-in eigenvalue-stability check — see :func:~torch_sci_solver.torch_impl.davidson.davidson_torch. None (default) disables it (residual-only). Pass a value to enable it; the effective threshold is sqrt(de_tol) (recommended: de_tol=eps).

None
init int

0 = HF, 1 = random.

0
n_roots int

number of lowest eigenpairs to return (default 1). When > 1, returns (Tensor(n_roots,), Tensor(n_roots, N), info).

1
device device | str

torch device for tensors.

'cpu'
dtype dtype

float dtype.

float64
matvec_impl str

"torch" (default, portable), "triton" (fused GPU kernels; every TPB channel except the diagonal is tiled, as are the GDB doubles channels/tables — the block-mode GDB singles and the diagonal stay batched) or "auto". "auto" resolves here — to "torch" on CPU and always in GDB mode, and to "triton" on a CUDA device when Triton imports — so the product kernel never receives "auto". "batched" is a deprecated alias for "torch" and logs a warning.

'torch'
verbose bool

per-iteration prints.

False
mode Literal['tpb', 'gdb']

See :class:~torch_sci_solver.torch_impl.qiskit_adapter.TorchSCISolver. "gdb" routes to :func:_diag_torch_pair, which diagonalizes over the explicit pair basis.

'tpb'
pair_budget_bytes int | None

GDB only. Peak workspace per excitation- enumeration chunk; None uses the default. See :func:~torch_sci_solver.torch_impl.pair_helpers.resolve_budget_bytes.

None
block_matvec str

GDB only. "off" (default) keeps the streamed pair tables; "auto" builds the Cartesian block decomposition when its usefulness gates pass; "on" forces it. See :func:~torch_sci_solver.torch_impl.pair_helpers.generate_pair_helpers.

'off'

Returns:

Type Description
float | Tensor

For n_roots == 1: (energy, eigvec, info) — energy is a

Tensor

Python float, eigvec is a (N,) torch tensor on device.

dict

For n_roots > 1: (energies, eigvecs, info) — energies is

Tuple[float | Tensor, Tensor, dict]

a (n_roots,) float64 Tensor on CPU, eigvecs is a

Tuple[float | Tensor, Tensor, dict]

(n_roots, N) Tensor on device.