Solvers
The solvers subpackage provides high-level solver interfaces that accept
a Hamiltonian and return a standardized SolverResult.
Base Classes
- class qvartools.solvers.solver.SolverResult(diag_dim, wall_time, method, converged, energy=None, metadata=<factory>)[source]
Bases:
objectImmutable container for solver output.
- Parameters:
energy (
floatorNone) – Ground-state energy estimate in Hartree, orNonewhen the solver fails or skips the computation.diag_dim (
int) – Dimension of the diagonalisation subspace (number of basis configurations used).wall_time (
float) – Wall-clock time in seconds for the full solve.method (
str) – Human-readable solver method name (e.g."FCI","SQD").converged (
bool) – Whether the solver converged to the requested tolerance.metadata (
dict) – Additional method-specific information (e.g. iteration history, basis size per step, training metrics).
Examples
>>> result = SolverResult( ... diag_dim=100, wall_time=1.5, method="SQD", converged=True, ... energy=-1.137, ... ) >>> result.energy -1.137
- class qvartools.solvers.solver.Solver[source]
Bases:
ABCAbstract base class for all quantum chemistry solvers.
Every subclass must implement
solve(), which takes a Hamiltonian and a molecular information dictionary and returns aSolverResult.The
mol_infodictionary is expected to contain at least:"name": str – molecule name."n_qubits": int – number of qubits (spin-orbitals)."basis": str – Gaussian basis set."geometry": list – atomic geometry."charge": int – net molecular charge."spin": int – spin multiplicity minus one (2S).
- abstractmethod solve(hamiltonian, mol_info)[source]
Compute the ground-state energy.
- Parameters:
hamiltonian (
Hamiltonian) – The molecular Hamiltonian to diagonalise.mol_info (
dict) – Molecular metadata dictionary with keysname,n_qubits,basis,geometry,charge,spin.
- Returns:
Result containing energy, timing, and convergence information.
- Return type:
Reference Solvers
- class qvartools.solvers.reference.fci.FCISolver(max_configs=500000)[source]
Bases:
SolverFull configuration interaction solver.
Attempts to use PySCF’s FCI module for molecular Hamiltonians. When PySCF is unavailable or the Hamiltonian is not molecular, falls back to dense exact diagonalisation via
exact_ground_state().For CAS molecules (
mol_info["is_cas"] = True), the solver uses the active-space integrals directly instead of rebuilding the full molecule, and returnsenergy=Nonewhen the CAS Hilbert space exceeds 50 million configurations.- Parameters:
max_configs (
int, optional) – Maximum number of configurations (Hilbert-space dimension) for which dense diagonalisation is attempted (default500_000). Systems exceeding this limit returnenergy=Nonewhen PySCF is unavailable.
Examples
>>> solver = FCISolver() >>> result = solver.solve(hamiltonian, mol_info) >>> result.energy -1.1373060356
- solve(hamiltonian, mol_info)[source]
Compute the FCI ground-state energy.
- Parameters:
hamiltonian (
Hamiltonian) – The molecular Hamiltonian.mol_info (
dict) – Molecular metadata. For the PySCF path (non-CAS molecules), must contain"geometry"(list of(atom, coord)tuples) and"basis"(str); optionally"charge"and"spin". For CAS molecules ("is_cas"isTrue), uses active-space integrals from the Hamiltonian directly. The"name"key is used only for logging.
- Returns:
FCI energy result.
energyisNonewhen the computation was skipped (e.g. CAS too large, dense fallback exceedsmax_configs).- Return type:
SolverResult
- class qvartools.solvers.reference.ccsd.CCSDSolver[source]
Bases:
SolverCoupled cluster singles and doubles solver via PySCF.
Requires PySCF to be installed. The solver runs RHF followed by CCSD on the molecular geometry specified in
mol_info.Examples
>>> solver = CCSDSolver() >>> result = solver.solve(hamiltonian, mol_info) >>> result.method 'CCSD'
- solve(hamiltonian, mol_info)[source]
Compute the CCSD ground-state energy.
- Parameters:
hamiltonian (
Hamiltonian) – The molecular Hamiltonian (used for metadata; PySCF recomputes integrals internally).mol_info (
dict) – Molecular metadata. Must contain"geometry"and"basis".
- Returns:
CCSD energy result.
- Return type:
SolverResult- Raises:
ImportError – If PySCF is not installed.
RuntimeError – If the RHF or CCSD calculation does not converge.
Subspace Solvers
- class qvartools.solvers.subspace.sqd.SQDSolver(n_samples=5000, flow_type='particle_conserving', training_config=None, device='cpu')[source]
Bases:
SolverSample-based quantum diagonalization solver.
Trains a normalizing flow to generate computational-basis configurations, builds a projected Hamiltonian in the sampled basis, and diagonalises it.
- Parameters:
n_samples (
int, optional) – Number of configuration samples to draw after training (default5000).flow_type (
str, optional) – Type of normalizing flow:"particle_conserving"or"discrete"(default"particle_conserving").training_config (
dictorNone, optional) – Override training hyperparameters. Keys are forwarded toPhysicsGuidedConfig. IfNone, sensible defaults are used.device (
str, optional) – Torch device for computation (default"cpu").
Examples
>>> solver = SQDSolver(n_samples=3000) >>> result = solver.solve(hamiltonian, mol_info) >>> result.method 'SQD'
- class qvartools.solvers.subspace.cipsi.CIPSISolver(max_iterations=30, max_basis_size=10000, convergence_threshold=1e-05, expansion_size=500)[source]
Bases:
SolverSelected CI solver using the CIPSI perturbative selection scheme.
- Parameters:
- solve(hamiltonian, mol_info)[source]
Run the CIPSI selected-CI algorithm.
- Parameters:
hamiltonian (
MolecularHamiltonian) – Hamiltonian exposingget_hf_state(),matrix_elements_fast(),get_connections(),diagonal_element(), anddiagonal_elements_batch().mol_info (
dict) – Molecular metadata (unused, kept for API compatibility).
- Return type:
SolverResult
Krylov Solvers
- class qvartools.solvers.krylov.skqd.SKQDSolver(n_samples=5000, skqd_config=None, training_config=None, device='cpu')[source]
Bases:
SolverSample-based Krylov quantum diagonalization solver.
Trains a normalizing flow, samples an initial basis, and runs Krylov-based diagonalisation to obtain the ground-state energy.
- Parameters:
n_samples (
int, optional) – Number of configuration samples from the trained flow (default5000).skqd_config (
dictorNone, optional) – Override SKQD hyperparameters forwarded toSKQDConfig.training_config (
dictorNone, optional) – Override training hyperparameters forwarded toPhysicsGuidedConfig.device (
str, optional) – Torch device (default"cpu").
Examples
>>> solver = SKQDSolver(n_samples=3000) >>> result = solver.solve(hamiltonian, mol_info) >>> result.method 'SKQD'
- class qvartools.solvers.krylov.nf_skqd.NFSKQDSolver(flow_model, config=None)[source]
Bases:
SolverNF-SKQD: faithful NF analog of quantum SKQD with cumulative basis.
Each Krylov power k:
Sample from the current NF distribution NF_k.
Add unique, particle-number-valid configs to the cumulative basis.
Diagonalize the projected Hamiltonian (Rayleigh–Ritz).
Partially update the NF toward the ground-state eigenvector.
- Parameters:
flow_model (
object) – A normalizing-flow model exposingsample(),log_prob(), andparameters()methods.config (
NFSKQDConfig, optional) – Solver hyper-parameters. Uses defaults when omitted.
- solve(hamiltonian, mol_info)[source]
Run NF-SKQD and return the ground-state energy estimate.
- Parameters:
hamiltonian (
MolecularHamiltonian) – Hamiltonian withget_hf_state,matrix_elements_fast,diagonal_element, anddiagonal_elements_batchmethods.mol_info (
dict) – Molecular metadata (unused by this solver, kept for API compat).
- Return type:
SolverResult
Iterative Solvers
- class qvartools.solvers.iterative.iterative_sqd.IterativeNFSQDSolver(n_iterations=5, n_samples=2000, training_config=None, convergence_tol=1e-06, device='cpu')[source]
Bases:
SolverIterative normalizing-flow SQD with eigenvector feedback.
At each iteration the solver:
Trains a normalizing flow + NQS to generate configuration samples.
Builds and diagonalises the projected Hamiltonian in the sampled basis (SQD).
Uses the ground-state eigenvector coefficients to bias the NQS log-amplitudes for the next iteration.
The feedback loop progressively focuses sampling on the most important configurations for the ground state.
- Parameters:
n_iterations (
int, optional) – Number of outer SQD iterations (default5).n_samples (
int, optional) – Samples per iteration from the trained flow (default2000).training_config (
dictorNone, optional) – Override training hyperparameters forwarded toPhysicsGuidedConfig.convergence_tol (
float, optional) – Stop iterating when the energy change between consecutive iterations is below this threshold (default1e-6).device (
str, optional) – Torch device (default"cpu").
Examples
>>> solver = IterativeNFSQDSolver(n_iterations=3) >>> result = solver.solve(hamiltonian, mol_info) >>> result.method 'IterativeNFSQD'
- class qvartools.solvers.iterative.iterative_skqd.IterativeNFSKQDSolver(n_iterations=5, n_samples=2000, training_config=None, skqd_config=None, convergence_tol=1e-06, device='cpu')[source]
Bases:
SolverIterative normalizing-flow SKQD with eigenvector feedback.
Same iterative feedback loop as
IterativeNFSQDSolver, but uses Krylov subspace expansion (SKQD) instead of direct projected diagonalisation at each iteration.- Parameters:
n_iterations (
int, optional) – Number of outer iterations (default5).n_samples (
int, optional) – Samples per iteration (default2000).training_config (
dictorNone, optional) – Override training hyperparameters.skqd_config (
dictorNone, optional) – Override SKQD hyperparameters forwarded toSKQDConfig.convergence_tol (
float, optional) – Energy convergence threshold (default1e-6).device (
str, optional) – Torch device (default"cpu").
Examples
>>> solver = IterativeNFSKQDSolver(n_iterations=3) >>> result = solver.solve(hamiltonian, mol_info) >>> result.method 'IterativeNFSKQD'