VQE¶
- class VQE(hamiltonian=None, molecule=None, n_electrons=None, n_layers=1, ansatz=None, initial_state=None, max_iterations=10, **kwargs)[source]¶
Bases:
VariationalQuantumAlgorithmVariational Quantum Eigensolver (VQE) implementation.
VQE is a hybrid quantum-classical algorithm used to find the ground state energy of a given Hamiltonian. It works by preparing a parameterized quantum state (ansatz) and optimizing the parameters to minimize the expectation value of the Hamiltonian.
The algorithm can work with either: - A molecular Hamiltonian (for quantum chemistry problems) - A custom Hamiltonian operator
- Variables:
ansatz (
Ansatz) – The parameterized quantum circuit ansatz.n_layers (
int) – Number of ansatz layers.n_qubits (
int) – Number of qubits in the system.n_electrons (
int) – Number of electrons (for molecular systems).cost_hamiltonian – The Hamiltonian to minimize.
loss_constant (
float) – Constant term extracted from the Hamiltonian.molecule – The molecule object (if applicable).
optimizer – Classical optimizer for parameter updates.
max_iterations (
int) – Maximum number of optimization iterations.current_iteration (
int) – Current optimization iteration.
Initialize the VQE problem.
- Parameters:
hamiltonian (
Operator|SparsePauliOp|None) – A Hamiltonian representing the problem. Defaults to None.molecule (
Molecule|None) – The molecule representing the problem. Defaults to None.n_electrons (
int|None) – Number of electrons associated with the Hamiltonian. Only needed when a Hamiltonian is given. Defaults to None.n_layers (
int) – Number of ansatz layers. Defaults to 1.ansatz (
Ansatz|None) – The ansatz to use for the VQE problem. Defaults to HartreeFockAnsatz.initial_state (
InitialState|None) – Initial state preparation. Pass anInitialStateinstance (e.g.ZerosState(),SuperpositionState()). Defaults toZerosState()if None.max_iterations (
int) – Maximum number of optimization iterations. Defaults to 10.**kwargs – Additional keyword arguments passed to the parent class.
Attributes Summary
Get the computed eigenstate as a NumPy array.
Number of trainable parameters per ansatz layer.
Methods Summary
sample_solution([params])Extract the eigenstate corresponding to the lowest energy found.
Attributes Documentation
- eigenstate¶
Get the computed eigenstate as a NumPy array.
- Returns:
- The array of bits of the lowest energy eigenstate,
or None if not computed.
- Return type:
npt.NDArray[np.int32] | None
- n_params_per_layer¶
Number of trainable parameters per ansatz layer.
- Returns:
Parameters per layer for the current ansatz, qubit count, and electron count.
- Return type:
Methods Documentation