sci_solvers.energy_calculation_base¶
Base class for sci_solver implementations.
Defines the qiskit-addon-sqd compatible sci_solver_callable
interface that all solvers in this package implement. Each concrete
subclass wraps a different diagonalizer (RIKEN's sbd binary,
qiskit-addon-dice-solver, PySCF's selected_ci) and exposes a uniform
per-batch dispatch interface.
The single contract is::
sci_solver_callable(ci_strs_batches, hcore, eri, norb, nelec, **kwargs)
-> List[SCIResult]
where ci_strs_batches is a list of (strs_a, strs_b) int64-array
tuples — one batch per element — and the returned SCIResult.energy
values are ELECTRONIC (no nuclear repulsion). Adding e_nuc is the
caller's responsibility, matching qiskit-addon-sqd's convention.
Subclasses MAY accept additional optional keyword arguments beyond the
protocol minimum (e.g. max_cycle, symmetrize_spin, spin_sq);
those are the per-solver knobs documented on each concrete solver class.
EnergyCalculatorBase
[source]
¶
EnergyCalculatorBase(*, symmetrize_spin: bool, hamiltonian: HamiltonianData | str | PathLike[str] | None = None, verbose: bool = False, nroots: int = 1, **kwargs: Any)
Bases: ABC
Abstract base class for sci_solver_callable wrappers.
Concrete subclasses implement :meth:sci_solver_callable to
diagonalize a Hamiltonian on the subspace spanned by each input
batch's (strs_a, strs_b) outer product.
Args:
hamiltonian: Optional HamiltonianData instance.
If provided in this constructor you may not override it in sci_solver_callable to avoid ambiguity.
you can provide either:
- a HamiltonianData instance directly, or
- a path to an FCIDUMP file (as a string or Path) from which the HamiltonianData instance will be created
If None (the default), then no Hamiltonian is stored/"bound" to this class instance.
symmetrize_spin:
verbose: Print solver-specific progress / debug output.
nroots: Number of lowest roots (states) to solve for per batch. Stored
as self.nroots for the subclasses to use and implement it.
**kwargs: Forwarded up the super().__init__.
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_eigen_states
abstractmethod
¶
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', **kwargs: Any) -> List[EigenStates]
Diagonalize the Hamiltonian on each batch's CI-string subspace.
This is the multi-root primitive every concrete solver implements. It
returns the lowest eigenpairs of each batch (one or more roots).
:meth:sci_solver_callable wraps this and hands qiskit-addon-sqd the
ground state per batch, so single-root callers never touch this method
directly.
Concrete implementations should call super().sci_solver_callable_eigen_states(...)
first to run the bound-Hamiltonian ambiguity guard (below).
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
Two reduction paths, dispatched on nelec's type (mirrors
GeneralAlgebraSolverBase/TorchSCISolver, the two families that
implement both):
- spatial —
nelecan(n_a, n_b)tuple:ci_strs_batchesis a list of(strs_a, strs_b)tuples, each defining a subspace via the outer product of unique alpha and beta CI strings. - spinless (flat spin-orbital, no alpha/beta split — GHF / SOC /
generalized-spinor Hamiltonians) —
neleca scalar total particle numberN:ci_strs_batchesis a list of flatstrsarrays, oneN-particle spin-orbital determinant bitmask list per subspace. Not every solver implements this path — a solver that doesn't should raiseNotImplementedErrorpromptly (see e.g.PySCFSolver,DICESolver,SBDSolver,DavidsonSolver,TruncatedDavidsonSolver) rather than let a bare tuple-unpack or index crash with an unrelated-lookingTypeError/ValueErrordeep inside the implementation.
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 (spin-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[EigenStates]
|
class: |
List[EigenStates]
|
in input order. Each holds one :class: |
|
List[EigenStates]
|
ascending in energy ( |
|
List[EigenStates]
|
solvers return an |
|
List[EigenStates]
|
are electronic only; callers add |
|
List[EigenStates]
|
chemical totals. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
|
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. |
project_init_vector
¶
project_init_vector(prev_state: Any, ci_strs: 'Tuple[np.ndarray, np.ndarray] | np.ndarray', mode: str = 'tpb', *, min_norm: float = 1e-08, device: Any = 'cpu') -> 'np.ndarray | None'
Project a previous solve's state onto a new basis, as an init_vectors entry.
Warm starting an SQD iteration from the previous one means mapping the previous
ground state onto this iteration's strings, which drop some and add others. This
builds the entry for one batch: amplitudes copied on the determinants both bases
share, zero on the new ones, normalized. It is laid out exactly as
init_vectors expects in each mode, so a caller never handles orderings or
sign conventions. That holds because every mode's init_vectors contract uses
the convention that mode's own sci_state.amplitudes come back in (TPB
spin-block, GDB interleaved-Wick), so amplitudes are copied, never re-signed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prev_state
|
Any
|
the previous result's |
required |
ci_strs
|
'Tuple[np.ndarray, np.ndarray] | np.ndarray'
|
the new batch's strings, as passed to the solver: |
required |
mode
|
str
|
|
'tpb'
|
min_norm
|
float
|
overlap below which the bases share nothing worth starting from. |
1e-08
|
device
|
Any
|
torch device for the key lookup, a sort over every determinant. CPU
takes ~3.4 s per 10⁷ GDB pairs; pass the solve device (e.g. |
'cpu'
|
Returns:
| Type | Description |
|---|---|
'np.ndarray | None'
|
The 1-D entry, or |
'np.ndarray | None'
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
|