7.4 Using VQE with PennyLane
In this section, we will illustrate how to run VQE with PennyLane. The problem that we will work with will be, again, finding the ground state of the dihydrogen molecule. This is a task we are already familiar with and, moreover, this will allow us to compare our results with those that we obtained with Qiskit in the previous section. So, without further ado, let’s start by showing how to define the problem in PennyLane.
7.4.1 Defining a molecular problem in PennyLane
As with Qiskit, PennyLane provides methods to work with quantum chemistry problems. To study the molecule, we can use the following instructions:
import pennylane as qml from pennylane import numpy as np seed = 1234 np.random.seed(seed) symbols = ["H", "H"] coordinates = np.array([0.0, 0.0, -0.6991986158, 0.0, 0.0, 0.6991986158]) H, qubits = qml.qchem.molecular_hamiltonian(symbols, coordinates) print("Qubit Hamiltonian: "...