sci_solvers.energy_solvers.torch_sci_solver¶
torch_sci_solver-based sci_solver implementation.
Wraps torch_sci_solver's matvec + Davidson + RDM stack (via
make_torch_sci_solver) in this package's :class:EnergyCalculatorBase
contract. Runs on GPU by default (device="cuda") and falls back to CPU;
suited to large active spaces where the torch batched matvec is fastest.
TorchSCISolver
[source]
¶
TorchSCISolver(*, symmetrize_spin: bool, hamiltonian: HamiltonianData | str | PathLike[str] | None = None, device: device | str = 'cuda', devices: Optional[List[device | str]] = None, dtype: dtype = float64, verbose: bool = False, chunk_size: int = 2000000, davidson_block_size: Optional[int] = 20, max_davidson_iters: int = 20, davidson_tolerance: float = 0.0001, apply_ab_projection: bool = False, nroots: int = 1, n_roots: int = 1, **solver_kwargs: Any)
Bases: EnergyCalculatorBase
torch_sci based - a torch implementation of SCI, uses GPU by default
Multi-root support: pass n_roots > 1 to solve for excited states in
addition to the ground state. Each per-batch
:class:~sci_solvers.eigen_states.EigenStates then holds states[0]
(ground state) through states[n_roots - 1] (highest solved root),
ascending in energy — read excited states from states[1:]. The
qiskit-addon-sqd recovery loop (driven via
:meth:~sci_solvers.energy_calculation_base.EnergyCalculatorBase.sci_solver_callable)
still consumes only the ground state, so raising n_roots is free for the
hot loop and surfaces excited states only to callers that read them. This
mirrors the general-algebra solvers' nroots (named n_roots here to
match the underlying torch_sci_solver package).
Initialize the TorchSCISolver.
Default parameters are set to match exact energy as sbd tpb app (https://github.com/r-ccs-cms/sbd/tree/main/apps/chemistry_tpb_selected_basis_diagonalization)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device | str
|
Single torch device for the diagonalization (default
|
'cuda'
|
devices
|
Optional[List[device | str]]
|
Opt into single-node, multi-GPU batch-parallel
dispatch by passing a list of CUDA devices, e.g.
|
None
|
dtype
|
dtype
|
Numeric dtype for the diagonalization (default
|
float64
|
davidson_block_size
|
Optional[int]
|
Davidson subspace size — vectors accumulated
before a restart (default |
20
|
max_davidson_iters
|
int
|
Outer Davidson restart count per diagonalization
(default |
20
|
davidson_tolerance
|
float
|
Davidson residual ( |
0.0001
|
nroots
|
int
|
Number of lowest eigenpairs (roots) to solve for per batch
(canonical spelling, matching the general-algebra solvers).
Default |
1
|
n_roots
|
int
|
Backward-compatible alias for |
1
|
config
property
¶
config: dict[str, Any]
JSON-friendly requested/resolved engine configuration.
Delegates to the underlying torch_sci_solver engine so workflows do
not need to reach into self._solver for the mode, device, dtype,
distributed launch config or gdb_kwargs.
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_davidson_iters: int | None = None, init_vectors: List[ndarray | None] | None = None, **kwargs: Any) -> List[EigenStates]
Diagonalize each batch via our homegrown torch_sci implementation.
Positional signature matches qiskit_addon_sqd.fermion.solve_sci_batch
(ci_strings, one_body, two_body, norb, nelec plus spin_sq); the
remaining keyword knobs are this solver's own and are not PySCF's —
the torch engine runs its own Davidson, nothing routes to
kernel_fixed_space.
Two reduction paths are dispatched on nelec's type, mirroring
GeneralAlgebraSolverBase:
- spatial —
nelecan(n_a, n_b)tuple:ci_strs_batchesis a list of(strs_a, strs_b)tuples over separate alpha/beta determinant lists. - spinless (flat spin-orbital, no alpha/beta split) —
neleca scalar total particle numberN:ci_strs_batchesis a list of flatstrsarrays. Complex-only (mirrorssci_solvers.spinless_ci_problem). Multi-root (n_roots > 1at construction) works at the same level as the spatial path (davidson_torchis basis-shape-agnostic);spin_sqis rejected (no alpha/beta split to target a spin sector).
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 (spin-orbitals |
required |
nelec
|
Tuple[int, int] | int
|
|
required |
spin_sq
|
float | None
|
Target value for total spin squared (S²). Spatial path only; rejected on the spinless path. |
None
|
max_davidson_iters
|
int | None
|
Outer Davidson restart count for this call.
Defaults to the solver's own |
None
|
init_vectors
|
List[ndarray | None] | None
|
Davidson start vector per batch, to warm start an
iteration from the previous one's state projected onto the new
strings (the projection is the caller's job). One entry per
batch, each
The solver reorders it to its internal basis (strings are sorted
and deduplicated; a duplicate takes its first occurrence's
amplitude, a string not passed starts at 0), applies the αβ
projection, and normalizes it. If less than 1e-8 of its own
norm is left after that, it falls back to the cold start (so its
overall scale does not matter). Whether each batch was warm
started is reported as |
None
|
**kwargs
|
Any
|
Additional kwargs forwarded to the underlying
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
One |
List[EigenStates]
|
class: |
List[EigenStates]
|
input order, each holding one :class: |
|
List[EigenStates]
|
ascending in energy: |
|
List[EigenStates]
|
|
|
List[EigenStates]
|
was constructed with |
|
List[EigenStates]
|
solver returns an |
|
List[EigenStates]
|
electronic only. |
capabilities
¶
capabilities() -> dict[str, Any]
Per-mode engine support map (layouts, dtypes, RDM/S², distributed, ...).
preflight
¶
preflight(ci_strings: List[Tuple[ndarray, ndarray]] | List[ndarray], nelec: Tuple[int, int] | int, **call_kwargs: Any) -> dict[str, Any]
Run the engine's call-time gates and return the resolved plan, without solving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ci_strings
|
List[Tuple[ndarray, ndarray]] | List[ndarray]
|
The per-batch CI strings (same shapes as
:meth: |
required |
nelec
|
Tuple[int, int] | int
|
|
required |
**call_kwargs
|
Any
|
The per-call keywords the solve would receive.
|
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The engine's JSON-friendly plan: effective basis/mode, per-subspace |
dict[str, Any]
|
dimensions, |
dict[str, Any]
|
warm/cold start and RDM path. |
last_call_subspace_stats
¶
last_call_subspace_stats() -> List[dict[str, Any]]
Per-batch diagnostics of the most recent solve, one dict per batch, in order.
The public way to confirm what a call actually did, without reaching into the
engine: warm (whether that batch started from its init_vectors entry,
False when it fell back to the cold start), n_matvecs,
davidson_dtype, davidson_fp32_shift, the resolved
davidson_fp32_energy, and the timings (t_setup, t_davidson,
t_occ) and mem_peak_gb. Empty before the first call, after a spinless
call (that path keeps no per-batch log) and after a call that raised: never an
earlier call's stats.
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. |