0

Is there a way to get certain measurement results by variational quantum eigensolver in qiskit? More specifically, I want to get measurement results for certain operators, like $\langle a^\dagger_ia_j\rangle$ (which I assume that I later transform it into the qubit version using Jordan-Wigner transformation) for every $i,j$ in the system. Therefore, I need to get the measurement results for the matrix for, say, $10^4$ shots. I noticed that the VQE class provides the function to calculate the expection value, can I use this function to get my job done, or there are any other ways to achieve this?

ironmanaudi
  • 799
  • 3
  • 10

1 Answers1

1

$\newcommand{\Ket}[1]{\left|#1\right>}$ $\newcommand{\ket}[1]{|#1\rangle}$ $\newcommand{\bra}[1]{\left<#1\right|}$

I think you can find the answer to your question here: Circuit for VQE Expectation Value Finding

If you want to get the expectation value (average value) of an operator corresponding to an observable on a quantum state you can follow this formula:

$E(M) = \braψM\ketψ $

Here an example code:

from qiskit import QuantumCircuit
import numpy as np
from qiskit.aqua.operators import StateFn
from qiskit.aqua.operators import Z

qc = QuantumCircuit(2) qc.rz(np.pi/3, [0]) qc.rx(np.pi/3, [0]) qc.cx(0, 1)

operator = Z psi = StateFn(qc) expectation_value = (~psi @ operator @ psi).eval() print(expectation_value.real)