sergiomtzlosa / HEEM

Library to implement the Variational Quantum Eigensolver (VQE) using hardware-efficient entangled measurements to estimate the energy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Entanglement Qubits - Apaisado

Hardware-efficient-variational-quantum-eigensolver-with-entangled-measurements

DOI

The Variational Quantum Eigensolver (VQE) is a hybrid quantum-classical algorithm whose aim is to find the ground state of a Quantum Hamiltonian. Implementing VQE in NISQ devices is challenging. The two main obstacles are:

  1. Deep circuits are implemented with low quality [1].
  2. Many circuits are required to evaluate the energy [2,3].

Both difficulties have been studied independently. ¿Can they be tackled simultaneously?

We propose to use Hardware-Efficient Entangled Measurements (HEEM), which are measurements that take advantage of entanglement between neighboring qubits according to the device’s architecture. The usage of HEEM reduces the number of measurements needed to perform VQE without compromising the quality of the experiment.

In this github we implement the VQE algorithm using HEEM to estimate the energy. Cite to the doi: 10.5281/zenodo.6074767

Dependences

This package needs the following packages:

pip install qiskit
pip install qiskit_nature
pip install pyscf
pip install networkx
pip install tqdm
pip install joblib
pip install SciencePlots

Folders

This github is organizated ad follows:

In Articles you can find the main refenreces for this project. In Figures we include all the plots and scketches used, while in Report there is a PDF with all the technical details of the algoritmhs and the main results of the project, together with the LaTeX files to compile the mentioned report. The main folder is Codes, with all the python scrips and jupyter notebooks needed to reproduce the results.

In this last folder you can find the new VQE class in VQE.py than implement the HEEM functions of HEEM_VQE_Functions.py and the grouping from GroupingAlgorithm.py. On utils.py we include differents functions of general purpose that will be needed along the project. In data we save all the simulations and experiments. In the folder deprecated there are all versions of the codes, which are no longer in use. In experiments is the jupyter notebook used to perform an experiment in a real devide. Finaly, in the folder tests and examples there are several notebooks checking the correct funtionality of the different functions and shows some simple examples for their use.

Usage

Here we provide a minimal example for the calculation of the minimum energy at a given distance for the LiH molecule using HEEM (NOTE: This example is designed to be executed in a jupyter notebook instance).

  1. To use HEEM VQE we first have to import the modified VQE class.
from VQE import VQE
  1. In order to use HEEM VQE to simulate molecules, we have created some functions that provided qiskit quantum operators for LiH and BeH2 molecules
from utils import LiH

qubit_op, init_state = LiH(initial_state=True)
num_qubits = qubit_op.num_qubits
  1. Import the qiskit quantum instante for the simulation, and functions needed to simulate a real device
from qiskit import Aer
from qiskit.providers.aer import QasmSimulator
from qiskit.providers.aer.noise import NoiseModel
from qiskit.test.mock import FakeVigo
from qiskit.utils.quantum_instance import QuantumInstance
  
backend = Aer.get_backend('qasm_simulator')
device_backend = FakeVigo()
device = QasmSimulator.from_backend(device_backend)
coupling_map = device.configuration().coupling_map
noise_model = NoiseModel.from_backend(device)
basis_gates = noise_model.basis_gates
qi = QuantumInstance(backend=backend, coupling_map=coupling_map,
                     noise_model=noise_model, basis_gates=basis_gates)
  1. Choose a classical optimizer and and ansatz for the variational circuit
from qiskit.algorithms.optimizers import SPSA
from qiskit.circuit.library import EfficientSU2

optimizer = SPSA(maxiter=150, last_avg=1)
ansatz = init_state.compose(EfficientSU2(num_qubits, ['ry', 'rz'],
                                         entanglement='linear', reps=1))
initial_params = [0.1] * ansatz.num_parameters
  1. Create a callback to verify the progress of VQE
from IPython.display import display, clear_output
def callback(evals, params, mean, deviation):  
    display("{}, {}".format(evals, mean))
    clear_output(wait=True)
  1. Initialize and run the algorithm
solver = VQE(ansatz, optimizer, grouping='Entangled',
             quantum_instance=qi, conectivity=coupling_map,
             callback=callback)
result = solver.compute_minimum_eigenvalue(qubit_op).eigenvalue.real
  1. Extract the energy computed in each iteration and plot it
import matplotlib.pyplot as plt
energies = solver.energies
plt.plot(energies)

test

For more examples, look at the Examples and Test folders.

References

[1] Nature 549, 242 (2017).
[2] Npj Quantum Information 6, 56 (2020).
[3] Phys. Rev. A 101, 062322 (2020). [4] arXiv:1907.13623 (2019)

About

Library to implement the Variational Quantum Eigensolver (VQE) using hardware-efficient entangled measurements to estimate the energy


Languages

Language:Jupyter Notebook 89.2%Language:Python 10.3%Language:TeX 0.5%