Skip to content

sci_solvers.energy_solvers.dice_solver

DICE-based sci_solver implementation.

DICESolver [source]

DICESolver(*, symmetrize_spin: bool, hamiltonian: HamiltonianData | str | PathLike[str] | None = None, verbose: bool = False, mpirun_options: str | list[str] | None = None, temp_dir: str | None = None, clean_temp_dir: bool = True, select_cutoff: float = 2147483647, tol: float = 1e-10, davidson_tolerance: float = 1e-05, davidson_tolerance_loose: float | None = None, max_hci_iters: int = 1, fci: bool = False, nroots: int = 1, **kwargs: Any)

Bases: EnergyCalculatorBase

sci_solver wrapping the DICE (Dice is Cheap Eigensolver) C++ binary via qiskit-addon-dice-solver's :func:solve_hci.

Performs a single Davidson diagonalization on the projected Hamiltonian of the input bitstrings (no HCI expansion). The defaults are set to enforce this fixed-space mode:

  • select_cutoff=2147483647 (INT_MAX) prevents Dice from selecting any additional determinants beyond the supplied CI strings.
  • max_hci_iters=1 means only one HCI macro-iteration is performed — a single Davidson solve on the projected subspace.
  • tol (HCI energy convergence, Dice's dE) has no practical effect with max_hci_iters=1 since convergence is never checked across iterations. Diagonalization quality is governed by davidson_tolerance (Dice's davidsonTol, default 1e-5) and davidson_tolerance_loose, both exposed by the wrapper.

Multi-root: that single Davidson solve returns the lowest self.nroots eigenpairs (solve_hci's n_roots argument), so setting nroots > 1 yields the ground state plus excited states — the multi-root capability the eigensolver adapters previously exposed. spin_sq projection is still restricted to 0.0/None (see below).

Concurrent same-node mpirun invocations have been observed to crash Dice in this environment, so batches are processed sequentially. Use mpirun_options for intra-call MPI parallelism.

Parameters:

Name Type Description Default
verbose bool

Print per-batch progress / debug output.

False
mpirun_options str | list[str] | None

Options for MPI execution (e.g. "-n 16"). Both string and list forms are accepted.

None
temp_dir str | None

Directory for temporary DICE files. Each batch gets its own subdirectory under this path.

None
clean_temp_dir bool

Whether to clean up temporary files on success. The cleanup is performed by this class rather than by solve_hci, so that Dice's logfile can be read for a convergence signal first.

True
select_cutoff float

Coefficient cutoff for HCI determinant selection. The default (INT_MAX) suppresses all selection so Dice diagonalizes exactly the supplied subspace without adding new configurations.

2147483647
tol float

HCI energy convergence tolerance, forwarded to solve_hci's energy_tol (Dice's dE). Note this is not a Davidson residual tolerance — see davidson_tolerance for that. Has no practical effect at the default max_hci_iters=1 since no inter-iteration convergence check is performed.

1e-10
davidson_tolerance float

Residual tolerance for Dice's final (tight) Davidson solve, forwarded as solve_hci's davidson_tol (Dice's davidsonTol; default 1e-5). At the default max_hci_iters=1 this governs the quality of the returned energy. Dice caps its Davidson iterations at a compile-time constant that cannot be configured from here, so unlike the other solvers there is no max_davidson_iters/davidson_block_size knob.

1e-05
davidson_tolerance_loose float | None

Residual tolerance for the preliminary Davidson that runs on each HCI macro-iteration, forwarded as solve_hci's davidson_tol_loose (Dice's davidsonTolLoose). None (default) omits the keyword so Dice uses its own default. The tight solve is warm-started from this one, so setting it tighter than davidson_tolerance shifts the bulk of the work into the loose solve — whose iteration count Dice actually reports.

None
max_hci_iters int

Maximum HCI macro-iterations, forwarded to solve_hci's max_iter. Defaults to 1 for a single fixed-space Davidson diagonalization. This is an HCI selection loop, unrelated to Davidson iterations on the other solvers.

1
fci bool

If True, passes ci_strs=None to solve_hci, which starts the SHCI expansion from the Hartree-Fock determinant instead of the supplied bitstrings.

False
nroots int

Number of lowest roots (states) to solve for per batch, forwarded to solve_hci's n_roots. 1 (default) returns the ground state only; >1 returns the ground state plus that many excited states, ascending in energy.

1

Initialize the DICE HCI solver.

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

Matches :func:qiskit_addon_sqd.fermion.solve_sci_batch signature.

Run HCI on each batch via DICE.

Parameters:

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

List of (strs_a, strs_b) int64-array tuples.

required
hcore ndarray

One-electron integrals, shape (norb, norb).

required
eri ndarray

Two-electron repulsion integrals, shape (norb,)*4.

required
norb int

Number of spatial orbitals.

required
nelec Tuple[int, int] | int

(n_alpha, n_beta). A scalar nelec (the spinless flat spin-orbital path) is rejected with NotImplementedError — this solver does not implement it.

required
spin_sq float | None

Target value for total spin squared (S²). MUST be None or 0.0. Any other value raises :class:ValueError. See class docstring for rationale.

0.0

Returns:

Name Type Description
One List[EigenStates]

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

List[EigenStates]

input order, each holding the self.nroots lowest

List[EigenStates]

class:SCIResult\ s DICE computes for that batch (ascending

List[EigenStates]

energy). Energies are electronic only.

Raises:

Type Description
ValueError

If spin_sq is neither None nor 0.0.

TypeError

If max_cycle is passed (see below).

NotImplementedError

If nelec is a scalar (the spinless path).

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.