# How to improve accuracy of ground energy values from a VQE

Using the Qiskit textbook I have been using a VQE to find the ground state energy of Hydrogen at different interatomic distances on a quantum machine. However, the average energy value I will always calculate at a interatomic distance of 0.735 A (groundstate) is ~ 1.06 Hartrees while the exact value calculated with the NumpyEigensolver is 1.1373... Hartrees. I am unable to see what is causing this inaccuracy and at higher interatomic distances this inaccuracy increases. In some cases the VQE values for the ground energy are above even above the HartreeFock energy given by:

VQE_result.hartree_fock_energy


I was under the impression that the qubits are initialised in the HartreeFock initial state so how can the VQE energy given by:

VQE_result.total_energies


be above its initial state if the VQE is meant to be minimizing the value? Unless I am miss understanding how the algorithm is working? Is this inaccuracy just an effect of quantum noise and decoherence in NISQ era machinery or is this an error with my method.

This is a graph of my VQE results (Blue) and the exact values (Orange) to demonstrate the inaccuracy:

The main loop of my code which retrieves these values is:

for i in np.arange(0.25,4.25,0.25):
molecule = Molecule(geometry=[['H', [0., 0., 0.]],
['H', [0., 0., i]]],
charge=0, multiplicity=1)

driver = PySCFDriver(molecule = molecule, unit=UnitsType.ANGSTROM, basis='sto3g')

#Map fermionic hamiltonian to qubit hamiltonian
transformation = FermionicTransformation(qubit_mapping=FermionicQubitMappingType.PARITY,
two_qubit_reduction=True,
freeze_core=True)

numpy_solver = NumPyMinimumEigensolver()

#Initialize the VQE solver

vqe_solver = VQEUCCSDFactory(QuantumInstance(backend = backend, shots = 1024))

#Ground state algorithm
calculation_VQE = GroundStateEigensolver(transformation, vqe_solver)

calculation_numpy = GroundStateEigensolver(transformation, numpy_solver)

#Calculate results
VQE_result = calculation_VQE.solve(driver)
VQE_results_array.append(VQE_result.total_energies)
hf_energies.append(VQE_result.hartree_fock_energy)
NRE.append(VQE_result.nuclear_repulsion_energy)

Numpy_result = calculation_numpy.solve(driver)
Numpy_result_array.append(Numpy_result.total_energies)


One way to improve the accuracy of your answer is to increase the number of shots. I see that you set your shots to 1024, so you might want to increase that to 8192 shots (the maximum shots allowed by Qiskit).

You are right that noise is the problem. The noise are being introduced both by the gate operations and the read-out/measurement process. To fix the noise at the read-out stage, you can use measurement error mitigation technique. Since you are using Aqua, this can be implement directly through your quantum instance as follow:

from qiskit.ignis.mitigation.measurement import CompleteMeasFitter

quantum_instance = QuantumInstance(backend,
shots = 8192,
initial_layout = None,
optimization_level = 3,
measurement_error_mitigation_cls = CompleteMeasFitter,
cals_matrix_refresh_period = 0)


Then if you want to go a step further, and try to correct the errors from the quantum circuit, you can use the technique from this paper: Extending the computational reach of a noisy superconducting quantum processor Which is essentially, pro-long the circuit execution time to allow more decoherence, then use that bad result along with the good result (when you didn't pro-long the circuit execution time) to do an extrapolation to obtain a better result. There is a naive implementation of this, by essentially, extending your circuit execution time by executing the exact but longer version of the circuit . That is, suppose of executing the circuit:

q_0: ──■──
┌─┴─┐
q_1: ┤ X ├
└───┘


           ░       ░

How did your result look like when you execute this on the qasm_simulator? Was it better? One of the thing about VQE is also about figuring out the right Ansatz or Variation_form (the parameterized quantum circuit to create your trial state) but it seems like you are already using UCCSD Ansatz and for $$H_2$$ that should be more than enough. However, UCCSD usually have a long circuit representation so be careful of that as you move forward to larger system... What is your circuit depth anyway for this particular problem?