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?
Asked
Active
Viewed 1,592 times
0
1 Answers
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)

BẢO BẠCH GIA
- 179
- 8
-
Is this calculation or measurement of the code given? I need to run the circuit on a real quantum device, so I need to measure the expectation value of the obeservable which contains a lot of anti-commute term. – ironmanaudi Apr 13 '21 at 06:52
-
Moreover, Can I input a matrix or tensor (each term is a Pauli string) to the expectation function? – ironmanaudi Apr 13 '21 at 07:21
-
The code above is the calculation of expectation value. If you want to measure the expectation value you should check this link: https://qiskit.org/documentation/apidoc/qiskit.aqua.operators.expectations.html – BẢO BẠCH GIA Apr 13 '21 at 09:27
-
You can input a matrix and tensor to the expectation function as well – BẢO BẠCH GIA Apr 13 '21 at 09:28
-
Thanks. Is there any requirements for the tensor (in my case, it is a four-index tensor), like the data structure? In my case, each element of the tensor is a Pauli string, and should I claim the whole tensor as something in qiksit? – ironmanaudi Apr 13 '21 at 12:22
-
I think there are no requirements for your tensor and yeah you should claim the tensor as a matrix and put in into qiskit – BẢO BẠCH GIA Apr 13 '21 at 12:56
-
So, in this case, I can input a 3-index tensor like this [[[a,b,c], [d,e,f]], [[c,e,f],[l,m,d]]] with its data structure as python list and elements as Pauli strings, is that right? – ironmanaudi Apr 13 '21 at 13:02
-
Yeah I think you can but you should use NumPy to create that matrix . – BẢO BẠCH GIA Apr 16 '21 at 10:36
aux_operators
toVQE.compute_minimum_eigenvalue
to evaluate the observable at the final state. – Cryoris Apr 11 '21 at 12:42