Skip to content

sci_solvers.energy_solvers.general_algebra_solvers.davidson

In-house Davidson selected-CI solver (matrix-free, real symmetric or complex Hermitian).

Wraps the conjugate-aware :func:~sci_solvers.energy_solvers.davidson_solver.davidson1 core, which forms the effective subspace matrix with conjugate inner products (_fill_heff_hermitian) and infers its dtype from the trial vectors — so the same iteration serves the real and complex Hermitian cases. Dependency-free (no scipy/PETSc/primme) and the reference complex-capable general-algebra solver.

MultiRootDavidsonSolver [source]

MultiRootDavidsonSolver(*, davidson_block_size: int | None = None, max_cycle: int | None = None, **kwargs: Any)

Bases: SpinFilterMixin, GeneralAlgebraSolverBase

In-house matrix-free multi-root Davidson over the EigenProblem / HermitianOperator reduction.

Uses :func:sci_solvers.energy_solvers.davidson_solver.davidson1, which is dtype-generic and Hermitian-correct (conjugate inner products throughout), so both real symmetric and complex Hermitian operators are handled by the same iteration, for any number of roots. Falls back to an exact dense eigh for small n.

Distinct from :class:~sci_solvers.energy_solvers.davidson_solver.DavidsonSolver, the native single-root fixed-space Davidson (real only, exposes shift_mode); this one is matrix-free over the reduction, multi-root, and complex-capable.

Initialize the subspace size and iteration budget.

Parameters:

Name Type Description Default
davidson_block_size int | None

Davidson subspace size — vectors accumulated before a restart, carrying the same meaning as on TorchSCISolver / SBDSolver / DavidsonSolver. davidson1 widens its max_space by (nroots-1)*4, so that widening is subtracted in :meth:_diagonalize (where nroots is known) and the subspace used equals what you request, at any root count. None (default) instead yields _DEFAULT_MAX_SPACE + (nroots-1)*4 — a subspace that scales with the root count rather than a fixed size, since that constant is passed through uncorrected.

None
max_cycle int | None

Flat Davidson iteration budget — total matvec cycles across all restarts, handed to davidson1 as its max_cycle. This is the only accepted spelling on this solver: the base class calls the same quantity maxiter, and passing that here raises rather than silently offering two names for one knob. maxiter remains correct on the sibling backends, where it does not denote a flat matvec budget (ARPACK and PRIMME scale it by n, LOBPCG does not). None (default) uses the base's own default value.

None

Raises:

Type Description
TypeError

If maxiter is passed — pass max_cycle instead.

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_eigen_states

sci_solver_callable_eigen_states(ci_strs_batches: 'List[Tuple[np.ndarray, np.ndarray]] | List[np.ndarray]', hcore: ndarray, eri: ndarray, norb: int, nelec: 'Tuple[int, int] | int', *, nroots: int | None = None, spin_filter: bool | None = None, **kwargs: Any) -> List[EigenStates]

Oversolve (when possible), then keep the roots whose <S^2> matches spin_sq.

A pure passthrough when spin_sq is None or not active (the common case) -- nelec and ci_strs_batches flow through unexamined to the wrapped solver, so this works on the spinless path (a scalar nelec) exactly as far as the wrapped solver itself does. The classification step below (_keep_target_spin / _spin_square) is spatial-only (<S^2> has no meaning without an alpha/beta split, and it reads SCIState.ci_strs_a/ci_strs_b, which a spinless SpinlessSCIState does not carry), so an active filter on a scalar nelec is rejected outright rather than left to fail with an unrelated-looking AttributeError deep in _spin_square.

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.