Skip to content

sci_solvers.energy_solvers.truncated_davidson_solver.solver

Truncated-Davidson sci_solver implementation.

Thin wrapper around truncated_davidson, called with the raw Hamiltonian data (ci_strings, one_body_tensor, two_body_tensor, norb, nelec) for each batch. Each requested root's result is wrapped as a separate :class:SCIResult, and all of them are packed into a single :class:~sci_solvers.eigen_states.EigenStates, following the same convention as the rest of this package.

TruncatedDavidsonSolver [source]

TruncatedDavidsonSolver(*, symmetrize_spin: bool, hamiltonian: HamiltonianData | str | PathLike[str] | None = None, verbose: bool = False, nroots: int = 1, n_extra_roots: int = 1, eps: float = 0.0001, tol_residual: float | None = None, max_cycle: int = 50, delta_max: float = 0.001, delta_min: float = 1e-07, growth_factor: float = 2.0, precomputed_diag: bool | None = None, lindep_cutoff: float = 1e-07, plateau_window: int = 3, plateau_rel_tol: float = 0.3, require_buffer_convergence: bool = True, davidson_block_size: int | None = None, ignore_res: bool | None = True, print_every: int = 5, add_reference_determinant: bool = True, backend: str = 'numba', device: 'str | torch.device' = 'cpu', dtype: dtype = float64, chunk_size: int = 2000000, **kwargs: Any)

Bases: EnergyCalculatorBase

sci_solver wrapping the truncated Davidson diagonalizer.

Passes raw Hamiltonian data directly to :func:truncated_davidson; no dense matrix or linear operator is ever formed. Truncation thresholds and convergence parameters are fixed at construction time.

NOTE: Doesn't support complex numbers yet NOTE: symmetrize_spin performs post-solve CI-vector symmetrization (c = (c + c.T) / 2) and singlet validation, applied independently to each returned root. It is a no-op for open-shell systems (non-square amplitude array). NOTE: restart is not currently supported by the underlying truncated_davidson solver, single-root or multi-root.

Parameters

symmetrize_spin : bool If True, symmetrize the CI vector after solving (c = (c + c.T) / 2) and warn if the result deviates from a singlet, applied independently to each returned root. No-op for open-shell systems (non-square amplitude array). hamiltonian : HamiltonianData or path, optional Pre-built Hamiltonian data or a path to load one from disk. If None, must be supplied per call. verbose : bool Print per-iteration diagnostics from the inner Davidson loop. nroots : int Number of lowest eigenstates to solve for. nroots=1 recovers the original ground-state-only behavior. n_extra_roots : int Buffer roots solved alongside nroots (GD+k). Improves subspace resolving power near degeneracies; output is always the true lowest nroots by energy. eps : float Energy-change convergence threshold (Hartree), applied per root. tol_residual : float or None Per-root residual-norm threshold. Both eps and tol_residual must be satisfied. Defaults to sqrt(eps). max_cycle : int Flat cap on Davidson iterations per batch — the loop here is flat (a restart collapses the subspace in place rather than starting an outer iteration), so this is a total budget, matching max_cycle on PySCFSolver / DavidsonSolver rather than the nested solvers' max_davidson_iters. Note an iteration here is not one matvec: this algorithm builds truncated residuals via PCR instead of forming H·x, so the cross-solver rule of thumb max_cycle ~= max_davidson_iters * davidson_block_size does not carry over — equal max_cycle means equal iteration counts, not equal work. delta_max : float Initial truncation threshold for the PCR step. delta_min : float Minimum truncation threshold; never lowered below this value. growth_factor : float Multiplier applied to each root's previous basis-vector size to set that root's target truncation size T each iteration. precomputed_diag : bool or None If True, precompute and cache the Hamiltonian diagonal. None auto-selects based on norb (True if norb <= 18). lindep_cutoff : float Relative S-eigenvalue cutoff inside the generalized eigensolver. plateau_window : int Residual-norm history length for stagnation detection. plateau_rel_tol : float Converge a root if its last plateau_window residual norms vary by less than this fraction (truncation-induced residual floor). require_buffer_convergence : bool If True, wait for all nroots_total slots to converge before stopping. davidson_block_size : int or None Davidson subspace size — basis vectors accumulated before the subspace is collapsed (restarted). Same role as davidson_block_size on the other solvers, but note two differences here: None (the default) disables restart entirely rather than selecting a default size, and the value maps straight through with no (nroots-1)*4 widening correction (that is a PySCF-davidson1 quirk this kernel does not share). Must be >= nroots + n_extra_roots, which the kernel validates. ignore_res : bool or None If True, skip the residual-norm check and converge on energy change alone. Defaults to True when nroots=1, False otherwise. print_every : int Print a detailed energy summary every this many iterations (verbose only). add_reference_determinant : bool If True (default), inject the Hartree-Fock reference determinant into a selected-CI space that lacks it, so seeding never fails when the space happens to exclude the reference. If False, the space is used verbatim and solving raises if the reference is needed but absent. No effect on a full FCI space. device : str or torch.device Reserved for future GPU support; currently unused. dtype : torch.dtype Reserved for future mixed-precision support; currently unused. chunk_size : int Reserved for future batched sigma-vector support; currently unused.

sci_solver_callable_eigen_states

sci_solver_callable_eigen_states(ci_strs_batches: List[Tuple[ndarray, ndarray]] | List[ndarray], hcore: ndarray, eri: ndarray, norb: int, nelec: Tuple[int, int] | int, *, spin_sq: float | None = None, max_cycle: int | None = None, compute_rdm1: bool = True, compute_rdm2: bool = True, **kwargs: Any) -> List[EigenStates]

Diagonalize the (single) batch via truncated Davidson.

Calls truncated_davidson on the first (and only supported) batch requesting self.nroots eigenpairs, then reshapes each returned root's vector to (na, nb) amplitudes and wraps it as an :class:SCIState / :class:SCIResult. All solver hyperparameters (nroots, eps, max_iter, delta_max, delta_min, growth_factor, dedup_overlap_threshold) are read from the constructor.

.. note:: Only a single batch is supported. Passing more than one batch raises a ValueError.

Parameters:

Name Type Description Default
ci_strs_batches List[Tuple[ndarray, ndarray]] | List[ndarray]

List containing exactly one (strs_a, strs_b) int64-array tuple.

required
hcore ndarray

One-electron integrals, shape (norb, norb).

required
eri ndarray

Two-electron repulsion integrals, shape (norb,)*4.

required
norb int

Number of spatial orbitals.

required
nelec Tuple[int, int] | int

(n_alpha, n_beta). A scalar nelec (the spinless flat spin-orbital path) is rejected with NotImplementedError — this solver does not implement it (it is also real-only, a separate reason the complex-only spinless path could never reach it).

required
spin_sq float | None

Accepted for API parity with other solvers; ignored.

None
max_cycle int | None

Flat cap on Davidson iterations for this call. None (default) uses the solver's own max_cycle set at construction — pass it only to override for a single call. This was previously accepted and silently ignored.

None
**kwargs Any

Any remaining kwargs are ignored.

{}

Returns:

Type Description
List[EigenStates]

A list with one :class:~sci_solvers.eigen_states.EigenStates

List[EigenStates]

holding self.nroots :class:SCIResult objects (fewer if the

List[EigenStates]

solver's subspace could not support the full request), ordered

List[EigenStates]

by ascending energy. Energies are electronic only (no nuclear

List[EigenStates]

repulsion).

compute_energy

compute_energy(ci_strs_batches: List[Tuple[ndarray, ndarray]] | None = None, bitstring_matrix_batches: List[ndarray] | None = None, sort_ci_strs: bool = True, **solver_call_kwargs: Any) -> List[SCIResult]

Compute energies for each batch of CI strs.

Note - to get from bitstrings into ci_strs you can use:

from qiskit_addon_sqd.fermion import bitstring_matrix_to_ci_strs
ci_strs = bitstring_matrix_to_ci_strs(bitstrings_to_use, open_shell=False) #or open_shell==True, depending on your case

Parameters:

Name Type Description Default
ci_strs_batches List[Tuple[ndarray, ndarray]] | None

List of (strs_a, strs_b) int64-array tuples. Provide exactly one of this argument or bitstring_matrix_batches.

None
bitstring_matrix_batches List[ndarray] | None

List of boolean NumPy matrices, one per batch. Provide exactly one of this argument or ci_strs_batches.

None
sort_ci_strs bool

Sort and deduplicate each batch's alpha/beta CI strings with np.unique before solving. Defaults to True so solvers that require strictly ascending strings (the general-algebra family) work out of the box; the bitstring path is already sorted, so this is a no-op there. Pair-mode (mode="gdb") solvers are exempt: their (strs_a, strs_b) are parallel (alpha_i, beta_i) lists, so sorting each one independently would break the pairing (they dedup/sort the pair list themselves). Pass False to forward the strings exactly as given.

True
**solver_call_kwargs Any

Additional kwargs forwarded to sci_solver_callable.

{}

sci_solver_callable

sci_solver_callable(ci_strs_batches: 'List[Tuple[np.ndarray, np.ndarray]] | List[np.ndarray]', hcore: ndarray, eri: ndarray, norb: int, nelec: 'Tuple[int, int] | int', **kwargs: Any) -> List[SCIResult]

Diagonalize each batch's CI-string subspace, returning ground states.

The qiskit-addon-sqd entry point: matches the sci_solver signature expected by qiskit_addon_sqd.fermion.diagonalize_fermionic_hamiltonian. Thin wrapper over :meth:sci_solver_callable_eigen_states that keeps each batch's ground state (root 0) and discards the excited states, since the SQD recovery loop consumes only the ground state. To access excited states, call :meth:sci_solver_callable_eigen_states directly.

Note - to get from bitstrings into ci_strs you can use:

from qiskit_addon_sqd.fermion import bitstring_matrix_to_ci_strs
ci_strs = bitstring_matrix_to_ci_strs(bitstrings_to_use, open_shell=False) #or open_shell==True, depending on your case

Parameters:

Name Type Description Default
ci_strs_batches 'List[Tuple[np.ndarray, np.ndarray]] | List[np.ndarray]'

List of (strs_a, strs_b) tuples (spatial), or a list of flat strs arrays (spinless — a scalar nelec; see :meth:sci_solver_callable_eigen_states). Each spatial tuple defines a subspace via the outer product of unique alpha and beta CI strings (int64 arrays where bit i of each integer indicates occupancy of orbital i).

required
hcore ndarray

One-electron integrals, shape (norb, norb).

required
eri ndarray

Two-electron repulsion integrals. Either full 4-D (norb,)*4 or a packed form (4-fold / 8-fold) — what's accepted depends on the concrete solver.

required
norb int

Number of spatial orbitals.

required
nelec 'Tuple[int, int] | int'

(n_alpha, n_beta) (spatial), or a scalar total N (spinless — not every solver implements this; see :meth:sci_solver_callable_eigen_states).

required
**kwargs Any

Solver-specific optional arguments. See each concrete solver for the accepted set.

{}

Returns:

Name Type Description
One List[SCIResult]

class:SCIResult (the ground state) per input batch, in input

List[SCIResult]

order. energy fields are electronic only; callers add e_nuc

List[SCIResult]

themselves to obtain chemical totals.