Skip to content

sci_solvers.energy_solvers.general_algebra_base

Base class for solvers that diagonalize through the generic EigenProblem reduction.

A "general algebra" solver is one that hands the sampled alpha x beta CI subspace to a general-purpose eigensolver (SciPy ARPACK/LOBPCG, PRIMME, SLEPc, EVSL, a matrix-free torch Davidson, ...). Those solvers know nothing about quantum chemistry, so the problem must first be reduced to a generic operator they understand. That reduction, and the reverse packing of eigenpairs back into SCIResults, is exactly what this base owns:

  • build one :class:~sci_solvers.eigen_problem.EigenProblem per batch,
  • optionally exploit the closed-shell alpha<->beta swap symmetry to solve on a packed :class:~sci_solvers.eigen_problem.SymmetrizedEigenProblem sector view,
  • pack each eigenpair into a :class:SCIResult (amplitudes, occupancies, RDMs).

A concrete subclass writes only :meth:_diagonalize — how it turns one EigenProblem (full space or packed sector view) into its lowest nroots eigenpairs. See the solvers in :mod:sci_solvers.energy_solvers.general_algebra_solvers (e.g. ArpackSolver) for minimal examples.

GeneralAlgebraSolverBase [source]

GeneralAlgebraSolverBase(*, symmetrize_spin: bool, hamiltonian: HamiltonianData | str | PathLike[str] | None = None, verbose: bool = False, nroots: int = 1, tol: float = 1e-08, maxiter: int = 400, device: 'str | torch.device' = 'cpu', dtype: dtype = float64, chunk_size: int = 2000000, matvec_impl: str = 'torch', compute_rdm2: bool = False, mode: str = 'tpb', hermiticity_atol: float = 1e-07, hermiticity_rtol: float = 1e-05, hamiltonian_backend: str = 'torch', fulqrum_mode: str = 'csr', device_fallback: str = 'warn', **kwargs: Any)

Bases: EnergyCalculatorBase

Diagonalize each batch's CI subspace through the EigenProblem reduction.

Owns the sci-problem -> operator reduction, the optional spin-sector symmetrization, and the eigenpair -> SCIResult packing. Subclasses supply only :meth:_diagonalize.

Complex Hermitian integrals (spin-orbit coupling / GHF / SOC / k-point) and the spinless spin-orbital path are dispatched here: complex hcore/eri build a :class:~sci_solvers.eigen_problem.HermitianOperator (via the complex-CI builders) instead of an :class:~sci_solvers.eigen_problem.EigenProblem, and a scalar nelec selects the spinless path. Only solvers whose _diagonalize handles a complex operator set complex_capable (inherited from :class:~sci_solvers.energy_calculation_base.EnergyCalculatorBase) to True; the rest reject complex integrals loudly rather than dropping the imaginary part.

Initialize the reduction knobs shared by every general-algebra solver.

Parameters:

Name Type Description Default
symmetrize_spin bool

Exploit the closed-shell alpha<->beta swap symmetry to block-diagonalize H into parity sectors, solving each on a roughly half-size packed :class:~sci_solvers.eigen_problem.SymmetrizedEigenProblem view. Requires identical alpha/beta CI-string pools.

required
hamiltonian HamiltonianData | str | PathLike[str] | None

Optional bound Hamiltonian (see base class).

None
verbose bool

Print per-batch progress.

False
nroots int

Number of roots (states) to solve for per batch.

1
tol float

Convergence tolerance forwarded to :meth:_diagonalize.

1e-08
maxiter int

Iteration ceiling forwarded to :meth:_diagonalize.

400
device 'str | torch.device'

Torch device for the matvec kernel ("cpu" or "cuda").

'cpu'
dtype dtype

Torch float dtype for the matvec kernel.

float64
chunk_size int

Matvec batch size for the torch kernel.

2000000
matvec_impl str

torch_sci_solver matvec backend for the real-valued path: "torch" (default, portable), "triton" (fused kernel; CUDA + real dtype only, errors otherwise) or "auto" ("triton" on CUDA when available, else "torch"). The complex path always uses "torch" and rejects an explicit "triton". Block matvecs under Triton apply columns one at a time (no vmap). "batched" is a deprecated alias for "torch" and logs a warning; prefer "auto" for available Triton acceleration.

'torch'
compute_rdm2 bool

When True build the spin-summed 2-RDM per root and recompute the energy from the RDMs (<dm1, h> + 1/2 <dm2, eri>).

False
mode str

CI-basis contract for the batches. "tpb" (default) treats each batch as a Cartesian t\ ensor-p\ roduct b\ asis (alpha x beta, dim Na * Nb); "gdb" treats each batch as an explicit parallel (alpha_i, beta_i) g\ eneral- d\ eterminant-b\ asis pair list (dim = number of pairs), backed by :class:~sci_solvers.eigen_problem.PairCIProblem.

'tpb'
hermiticity_atol float

Absolute tolerance for the ERI/hcore Hermiticity guards in the complex CI builders (the (pq|rs) == conj((qp|sr)) checks). Only reaches the complex-Hermitian and spinless paths; the real path has no such guard. Two-component (KGHF/X2C1e, AMF-SOC) integrals are Hermitian only to SCF/AVAS round-off, so this and hermiticity_rtol are the knobs that admit that round-off without masking a genuine non-Hermitian operator. Forwarded verbatim from a solver's create_solver kwargs, so it is reachable from the pipeline's solver_kwargs without any new step setting.

1e-07
hermiticity_rtol float

Relative tolerance for the same Hermiticity guards. np.allclose compares against atol + rtol * |b|, so a nonzero rtol accepts round-off that scales with the element magnitude.

1e-05
hamiltonian_backend str

What builds each batch's projected Hamiltonian. "torch" (default) is the torch Slater-Condon kernel (:class:~sci_solvers.eigen_problem.EigenProblem / :func:~sci_solvers.complex_ci_problem.build_selected_complex_ci_problem). "fulqrum" assembles it with fulqrum instead (:func:~sci_solvers.fulqrum_ci_problem.build_fulqrum_ci_problem, needs the fulqrum extra); the eigensolver, spin handling and result packing are unchanged. "fulqrum" supports mode="tpb" and mode="gdb" with real or complex Hermitian integrals, and the spinless (scalar nelec) path. It is CPU-only: a non-CPU device is handled as device_fallback says.

'torch'
fulqrum_mode str

How the fulqrum backend holds and applies the operator, in every basis mode and the spinless path: "csr" (default; one CSR matrix, lowest peak memory of the assembled modes), "csr_fast" (about 30% faster build, about 2.5x the peak memory), or "matrix_free" (no matrix; regenerates the elements on every product, so memory stays near the basis size but each product costs several CSR ones). See :mod:sci_solvers.fulqrum_ci_problem. Ignored unless hamiltonian_backend="fulqrum"; "matrix_free" is rejected on a solver configured to need an assembled matrix (:meth:_needs_assembled_matrix).

'csr'
device_fallback str

What happens when hamiltonian_backend cannot run on device (today: fulqrum, which is CPU-only, with a GPU device). "warn" (default) warns and runs on "cpu": the same results, with different time and memory. "raise" raises ValueError.

'warn'
**kwargs Any

Cooperative-inheritance passthrough (see :class:~sci_solvers.energy_calculation_base.EnergyCalculatorBase).

{}

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, **kwargs: Any) -> List[EigenStates]

Diagonalize each batch's CI subspace via :meth:_diagonalize.

Three reduction paths are dispatched on the integral dtype and nelec:

  • real spatial — real integrals, (n_a, n_b) tuple: build an :class:~sci_solvers.eigen_problem.EigenProblem per (strs_a, strs_b).
  • complex spatial — complex Hermitian integrals, (n_a, n_b) tuple: build a :class:~sci_solvers.eigen_problem.HermitianOperator via :func:~sci_solvers.complex_ci_problem.build_selected_complex_ci_problem.
  • complex spinless — a scalar nelec (total N): each batch is a flat strs array; see :meth:_solve_spinless_batches.

Parameters:

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

(strs_a, strs_b) tuples (spatial) or flat strs arrays (spinless). In mode="tpb" each string array must be strictly ascending (sorted, unique).

required
hcore ndarray

One-electron integrals, shape (norb, norb) (may be complex).

required
eri ndarray

Two-electron integrals, full 4-index chemists' notation (may be complex).

required
norb int

Number of spatial orbitals (spin-orbitals nmo when spinless).

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

(n_alpha, n_beta) for the spatial path, or a scalar total N for the spinless spin-orbital path.

required
nroots int | None

Solve-time override of the constructor nroots. Lets a decorator (e.g. SpinFilterMixin) oversolve without mutating the solver. None uses self.nroots.

None
**kwargs Any

Accepted for API parity; forwarded to the base guard. spin_sq is rejected here — see Raises.

{}

Returns:

Name Type Description
One List[EigenStates]

class:~sci_solvers.eigen_states.EigenStates per batch, in input

List[EigenStates]

order, each holding the lowest nroots roots (ascending energy).

Raises:

Type Description
TypeError

If spin_sq is passed. On this family the spin target is a constructor argument (consumed by :class:~sci_solvers.energy_solvers.spin_filter_mixin.SpinFilterMixin), so a per-call value has nothing to act on.

ValueError

If, in mode="tpb", a batch's strs_a or strs_b is not strictly ascending (sorted, unique).

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.