Skip to content

sci_solvers.energy_solvers.factory

Construct an energy calculator instance by name, and query its capabilities.

This is the entry point external tools (e.g. sweep launchers) use to pick a solver from a string-valued config. :func:supports_multiroot / :func:is_general_algebra answer capability questions by name without constructing the solver. Add a solver by adding one _SOLVER_LOADERS entry (and the matching SolverType literal). Another installed package can add one without editing this file, by declaring an entry point in the sci_solvers.solvers group (see :data:SOLVER_ENTRY_POINT_GROUP).

AVAILABLE_SOLVERS module-attribute

AVAILABLE_SOLVERS: tuple[str, ...] = tuple(sorted(_SOLVER_LOADERS))

create_solver

create_solver(solver_type: SolverType | str, **kwargs: Any) -> EnergyCalculatorBase

Construct an energy calculator instance by name.

The unified entry point for sweep launchers and other tools that pick a solver from a config value (e.g. CLI arg, YAML key) and pass it whatever solver-specific kwargs the user supplied.

Parameters:

Name Type Description Default
solver_type SolverType | str

One of "pyscf", "dice", "sbd", "torch_sci", or "multiroot" (see :data:AVAILABLE_SOLVERS). Matched case-insensitively.

required
**kwargs Any

Solver-specific keyword arguments forwarded verbatim to the chosen solver's __init__. See each solver class for the supported options. Common ones:

  • All solvers: verbose, validation_mode, symmetrize_spin.
  • PySCFSolver: n_roots (>1 solves for excited states, read from states[1:] of each per-batch EigenStates), spin_shift, with_rdm2, max_cycle, plus any kwarg kernel_fixed_space accepts.
  • DICESolver: mpirun_options, temp_dir, clean_temp_dir, mpi_root, auto_setup_mpi, select_cutoff, tol (HCI energy convergence, Dice's dE), davidson_tolerance (Dice's davidsonTol), davidson_tolerance_loose (Dice's davidsonTolLoose), max_hci_iters (HCI macro-iterations), fci. Dice's Davidson iteration cap and block size are compile-time constants, so it has no max_davidson_iters / davidson_block_size.
  • SBDSolver (the in-process sbd-eigensolver package): mode ("tpb" or "gdb"), device ("cpu", "gpu", "gpu-omp", "auto"), fcidump_path, sbd_config (dict of SBD tunables, e.g. method, eps, max_it — the iteration cap; max_cycle is rejected), temp_dir, clean_temp_dir, compute_rdm2.
  • TorchSCISolver: device, devices (list of CUDA devices for single-node multi-GPU batch-parallel dispatch, e.g. ["cuda:0", "cuda:1"]), chunk_size, davidson_block_size, max_davidson_iters, davidson_tolerance, apply_ab_projection, n_roots (>1 solves for excited states, read from states[1:] of each per-batch EigenStates), plus any kwarg make_torch_sci_solver accepts.
  • General-algebra solvers (arpack, lobpcg, primme, slepc, evsl, pyscf_davidson): nroots, tol, maxiter, spin_sq, compute_rdm2, device, dtype, chunk_size, hamiltonian_backend ("torch" or "fulqrum"; not pyscf_davidson), plus per-solver knobs (e.g. window for evsl, use_operator for arpack).
{}

Returns:

Type Description
EnergyCalculatorBase

Initialised energy calculator instance.

Raises:

Type Description
ValueError

If solver_type isn't one of the known names.

TypeError

If solver_type isn't a string.

Examples:

>>> solver = create_solver("pyscf", verbose=True)
>>> result = solver.compute_energy(hamiltonian, configurations)
>>>
>>> solver = create_solver("dice", mpirun_options="-n 4")
>>> result = solver.compute_energy(hamiltonian, configurations, spin_sq=0.0)
>>>
>>> solver = create_solver("sbd", mode="gdb", device="gpu")
>>> result = solver.compute_energy(hamiltonian, configurations)

solver_class

solver_class(solver_type: SolverType | str) -> type[EnergyCalculatorBase]

Return the solver class for solver_type (imported, not constructed).

is_complex_capable

is_complex_capable(solver_type: SolverType | str) -> bool

Whether solver_type can diagonalize a complex Hermitian operator.

supports_multiroot

supports_multiroot(solver_type: SolverType | str) -> bool

Whether solver_type returns more than one root per batch when asked.

is_general_algebra

is_general_algebra(solver_type: SolverType | str) -> bool

Whether solver_type diagonalizes via the general-algebra EigenProblem reduction.

supports_spinless

supports_spinless(solver_type: SolverType | str) -> bool

Whether solver_type accepts a scalar nelec (the flat spin-orbital, no-alpha/beta-split path -- GHF / SOC / generalized-spinor Hamiltonians).

Not the same set as :func:is_complex_capable: every spinless-capable solver is also complex-capable (the spinless operator is complex Hermitian by construction), but the converse does not hold -- a solver can diagonalize a complex-spatial (n_a, n_b) Hamiltonian without implementing the spinless (scalar-nelec) reduction at all.

supports_init_vectors

supports_init_vectors(solver_type: SolverType | str) -> bool

Whether solver_type honors a per-call init_vectors (Davidson start vectors).

Lets a caller (e.g. an SQD loop warm-starting each iteration from the previous one) decide before the call whether to build the vectors at all; the other solvers raise NotImplementedError when one is passed.