qdk_chemistry.algorithms.qubit_hamiltonian_solver module

QDK/Chemistry qubit hamiltonian solver abstractions and utilities.

This module provides the base classes QubitHamiltonianSolver and QubitHamiltonianSolverFactory for solving qubit Hamiltonians for ground state energies using various algorithms.

qdk_chemistry.algorithms.qubit_hamiltonian_solver.davidson_solver(csr_matrix: object, tol: SupportsFloat = 1e-08, max_m: SupportsInt = 20) tuple

Diagonalize a sparse matrix using the Davidson eigensolver.

This function finds the lowest eigenvalue and corresponding eigenvector of a sparse matrix.

Parameters:
  • csr_matrix (scipy.sparse.csr_matrix) – Sparse matrix representation of the Hamiltonian.

  • tol (float, optional) – Convergence tolerance for the eigenvalue (default: 1e-8).

  • max_m (int, optional) – Maximum subspace size for the Davidson method (default: 20).

Returns:

  • eigenvalue: float, the lowest eigenvalue found

  • eigenvector: numpy.ndarray, corresponding eigenvector

Return type:

tuple of (float, numpy.ndarray)

Raises:

RuntimeError – If the Davidson solver fails to converge or encounters numerical issues

qdk_chemistry.algorithms.qubit_hamiltonian_solver.syev_solver(matrix: Annotated[numpy.typing.ArrayLike, numpy.float64]) tuple

Solve a dense matrix eigenvalue problem using LAPACK’s syev.

This function computes all eigenvalues and eigenvectors of a dense matrix.

Parameters:

matrix (numpy.ndarray) – Dense matrix.

Returns:

  • eigenvalues: numpy.ndarray, the eigenvalues of the matrix in ascending order

  • eigenvectors: numpy.ndarray, the eigenvectors of the matrix, where each column corresponds to an eigenvector

Return type:

tuple of (numpy.ndarray, numpy.ndarray)

Raises:
  • ValueError – If the input matrix is not square or symmetric.

  • RuntimeError – If LAPACK fails to compute the eigenvalues.

class qdk_chemistry.algorithms.qubit_hamiltonian_solver.QubitHamiltonianSolver[source]

Bases: Algorithm

Abstract base class for solving a qubit Hamiltonian.

__init__()[source]

Initialize the QubitHamiltonianSolver.

type_name()[source]

Return qubit_hamiltonian_solver as the algorithm type name.

Return type:

str

class qdk_chemistry.algorithms.qubit_hamiltonian_solver.QubitHamiltonianSolverFactory[source]

Bases: AlgorithmFactory

Factory class for creating QubitHamiltonianSolver instances.

algorithm_type_name()[source]

Return qubit_hamiltonian_solver as the algorithm type name.

Return type:

str

default_algorithm_name()[source]

Return qdk_sparse_matrix_solver as the default algorithm name.

Return type:

str

class qdk_chemistry.algorithms.qubit_hamiltonian_solver.SparseMatrixSolverSettings[source]

Bases: Settings

Settings configuration for a SparseMatrixSolver.

SparseMatrixSolver-specific settings:

tol (float, default=1e-8): Tolerance for the solver. max_m (int, default=20): Maximum subspace dimension for the solver.

__init__()[source]

Initialize SparseMatrixSolverSettings.

class qdk_chemistry.algorithms.qubit_hamiltonian_solver.SparseMatrixSolver(tol=1e-8, max_m=20)[source]

Bases: QubitHamiltonianSolver

Qubit Hamiltonian solver using sparse matrix methods.

Parameters:
__init__(tol=1e-8, max_m=20)[source]

Initialize the SparseMatrixSolver.

Parameters:
name()[source]

Return the name of the qubit hamiltonian solver.

Return type:

str

class qdk_chemistry.algorithms.qubit_hamiltonian_solver.DenseMatrixSolver[source]

Bases: QubitHamiltonianSolver

Qubit Hamiltonian solver using dense matrix methods.

__init__()[source]

Initialize the DenseMatrixSolver.

name()[source]

Return the name of the qubit hamiltonian solver.

Return type:

str