sci_solvers.energy_solvers.pyscf_solver¶
PySCF-based sci_solver implementation.
Thin wrapper around pyscf.fci.selected_ci.kernel_fixed_space, with a
convergence signal surfaced on every result and multi-root support.
Single-root path (n_roots == 1)¶
Calls qiskit_addon_sqd.fermion.solve_sci per batch via
:meth:PySCFSolver._solve_one_with_convergence, which monkey-patches
SelectedCI to capture the Davidson converged flag that
solve_sci would otherwise discard. Returns
:class:~sci_solvers.eigen_states.SCIResultWithConvergence so callers
can check result.state.
Multi-root path (n_roots > 1)¶
qiskit_addon_sqd cannot be used because its solve_sci is
hard-wired for a single root. The module-level
:func:solve_sci_batch_multiroot helper calls kernel_fixed_space
directly with nroots > 1, iterates over the returned list of CI
vectors to build one :class:~sci_solvers.eigen_states.SCIResultWithConvergence
per root, and reads myci.converged (available because we own the
myci instance) to populate state on each root.
PySCFSolver
[source]
¶
PySCFSolver(*, symmetrize_spin: bool, hamiltonian: HamiltonianData | str | PathLike[str] | None = None, verbose: bool = False, nroots: int = 1, n_roots: int = 1, spin_shift: float = 0.2, with_rdm2: bool = True, **kwargs: Any)
Bases: EnergyCalculatorBase
sci_solver wrapping PySCF's selected-CI kernel.
Suitable for small-to-medium subspaces on CPU. Multithreaded via BLAS;
supports spin projection via spin_sq.
Multi-root support: pass n_roots > 1 to solve for excited states in
addition to the ground state. When n_roots == 1 (default) the solver
uses :meth:_solve_one_with_convergence per batch (capturing PySCF's
Davidson converged flag). When n_roots > 1 it calls
kernel_fixed_space directly via :func:solve_sci_batch_multiroot.
All results are :class:~sci_solvers.eigen_states.SCIResultWithConvergence
— read the convergence state from result.state, and excited states from
states[1:] of each per-batch
:class:~sci_solvers.eigen_states.EigenStates.
Initialize the PySCFSolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symmetrize_spin
|
bool
|
Passed to the base class. |
required |
hamiltonian
|
HamiltonianData | str | PathLike[str] | None
|
Optional bound Hamiltonian (see base class). |
None
|
verbose
|
bool
|
Print solver progress. |
False
|
nroots
|
int
|
Number of lowest eigenpairs to solve for per batch. Default
|
1
|
n_roots
|
int
|
Backward-compatible alias for |
1
|
spin_shift
|
float
|
Penalty strength forwarded to |
0.2
|
with_rdm2
|
bool
|
Whether to retain the 2-RDM in each result. Only
relevant for |
True
|
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 = 200, davidson_block_size: int | None = None, **kwargs: Any) -> List[EigenStates]
Diagonalize each batch via PySCF's selected_ci kernel.
When n_roots == 1 calls :meth:_solve_one_with_convergence per
batch, which captures PySCF's Davidson converged flag.
When n_roots > 1 calls kernel_fixed_space directly via
:func:solve_sci_batch_multiroot.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ci_strs_batches
|
List[Tuple[ndarray, ndarray]] | List[ndarray]
|
List of |
required |
hcore
|
ndarray
|
One-electron integrals, shape |
required |
eri
|
ndarray
|
Two-electron repulsion integrals, shape |
required |
norb
|
int
|
Number of spatial orbitals. |
required |
nelec
|
Tuple[int, int] | int
|
|
required |
spin_sq
|
float | None
|
Target value for total spin squared (S²). |
None
|
max_cycle
|
int
|
Flat Davidson iteration budget — total matvec cycles
across all restarts (PySCF's Davidson is one flat loop; a
restart is an internal flag, not an outer loop). Kept distinct
from the nested solvers' |
200
|
davidson_block_size
|
int | None
|
Davidson subspace size — vectors accumulated
before a restart, carrying the same meaning as on
|
None
|
**kwargs
|
Any
|
Additional kwargs forwarded to the underlying PySCF
call — e.g. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
List[EigenStates]
|
class: |
List[EigenStates]
|
input order. Each holds one |
|
List[EigenStates]
|
class: |
|
List[EigenStates]
|
solved root, ascending in energy: |
|
List[EigenStates]
|
state and |
|
List[EigenStates]
|
|
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. |