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.EigenProblemper batch, - optionally exploit the closed-shell alpha<->beta swap symmetry to solve on a
packed :class:
~sci_solvers.eigen_problem.SymmetrizedEigenProblemsector 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 |
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: |
1e-08
|
maxiter
|
int
|
Iteration ceiling forwarded to :meth: |
400
|
device
|
'str | torch.device'
|
Torch device for the matvec kernel ( |
'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'
|
compute_rdm2
|
bool
|
When |
False
|
mode
|
str
|
CI-basis contract for the batches. |
'tpb'
|
hermiticity_atol
|
float
|
Absolute tolerance for the ERI/hcore Hermiticity
guards in the complex CI builders (the |
1e-07
|
hermiticity_rtol
|
float
|
Relative tolerance for the same Hermiticity guards.
|
1e-05
|
hamiltonian_backend
|
str
|
What builds each batch's projected Hamiltonian.
|
'torch'
|
fulqrum_mode
|
str
|
How the fulqrum backend holds and applies the operator, in
every basis mode and the spinless path: |
'csr'
|
device_fallback
|
str
|
What happens when |
'warn'
|
**kwargs
|
Any
|
Cooperative-inheritance passthrough (see
:class: |
{}
|
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.EigenProblemper(strs_a, strs_b). - complex spatial — complex Hermitian integrals,
(n_a, n_b)tuple: build a :class:~sci_solvers.eigen_problem.HermitianOperatorvia :func:~sci_solvers.complex_ci_problem.build_selected_complex_ci_problem. - complex spinless — a scalar
nelec(totalN): each batch is a flatstrsarray; see :meth:_solve_spinless_batches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ci_strs_batches
|
'List[Tuple[np.ndarray, np.ndarray]] | List[np.ndarray]'
|
|
required |
hcore
|
ndarray
|
One-electron integrals, shape |
required |
eri
|
ndarray
|
Two-electron integrals, full 4-index chemists' notation (may be complex). |
required |
norb
|
int
|
Number of spatial orbitals (spin-orbitals |
required |
nelec
|
'Tuple[int, int] | int'
|
|
required |
nroots
|
int | None
|
Solve-time override of the constructor |
None
|
**kwargs
|
Any
|
Accepted for API parity; forwarded to the base guard.
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
List[EigenStates]
|
class: |
List[EigenStates]
|
order, each holding the lowest |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
ValueError
|
If, in |
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 |
None
|
bitstring_matrix_batches
|
List[ndarray] | None
|
List of boolean NumPy matrices, one per batch.
Provide exactly one of this argument or |
None
|
sort_ci_strs
|
bool
|
Sort and deduplicate each batch's alpha/beta CI strings with
|
True
|
**solver_call_kwargs
|
Any
|
Additional kwargs forwarded to |
{}
|
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 |
required |
hcore
|
ndarray
|
One-electron integrals, shape |
required |
eri
|
ndarray
|
Two-electron repulsion integrals. Either full 4-D
|
required |
norb
|
int
|
Number of spatial orbitals. |
required |
nelec
|
'Tuple[int, int] | int'
|
|
required |
**kwargs
|
Any
|
Solver-specific optional arguments. See each concrete solver for the accepted set. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
List[SCIResult]
|
class: |
List[SCIResult]
|
order. |
|
List[SCIResult]
|
themselves to obtain chemical totals. |