Is there a convenient way in Qiskit to calculate the expectation value for a non-local operator, i.e. I would like to calculate:
$$ \langle \Psi|O|\Psi \rangle $$
More precisely, I would like to calculate the expectation value for an Operator that can be described by the following circuit:
operator_circ = QuantumCircuit(4)
operator_circ.x(0)
operator_circ.cz([1, 1, 2], [2, 3, 3])
I am currently doing the following to calculate the expectation value:
operator = Operator(operator_circ)
#Where psi is some quantumstate/quantumcircuit
psi.save_expectation_value(operator, range(4))
But I am afraid, that this is not what I want since when I look into the decomposition of the Operator it consists of some multiplexers that in turn consists of $CCX$ gates and a gate called squ_dg
. However, what I would like is to calculate the expectation value w.r.t. the decomposition of the operator circuit into summed weighted local Pauli.
Ideally some function expresses the $CZ$ gate like so:
$$ CZ_{12} = \frac{1}{2} (I_1 \otimes I_2 + I_1 \otimes Z_2 + Z_1 \otimes I_2 - Z_1 \otimes Z_2) $$
and then calculates the expectation value over the sums of weighted Paulis on the right hand side.
Or is it the same as just using the afformentioned code? What would be the best practice in Qiskit in this case?
save_expectation_value
saves the expectation value of an hermitian operator ($O$ in that case) with respect to a statevector ($|\Psi\rangle$ in that case). Why would we care about different decompositions of $O$? $\endgroup$