Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.28k stars 2.37k forks source link

Method to obtain circuits for evaluation of expectation for of Pauli string observables #13075

Open eendebakpt opened 2 months ago

eendebakpt commented 2 months ago

What should we add?

Often one has an input quantum circuit and wants to calculate the expectation value of an observable, for example the Pauli ZZ. This can be done using the qiskit Estimator class. But for some applications it is useful to see the circuits used to measure the observable (so the input circuit + some gates + measurement in the Z basis). This can be done with the deprecated BackendEstimator:

from qiskit_aer import AerSimulator
from qiskit.circuit import QuantumCircuit
from qiskit.primitives import BackendEstimatorV2, BackendEstimator
from qiskit.circuit import QuantumCircuit
from qiskit_aer.primitives import EstimatorV2

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc.barrier()

backend=AerSimulator()
estimator = BackendEstimator(backend=backend)
r = estimator.run( [qc]*3, ['ZZ', 'ZX', 'ZY'] )
r.result()

for idx in range(3):
    print(estimator.transpiled_circuits[idx].draw())

The corresponding functionality in the new BackendEstimatorV2 is only available using private methods. See https://qiskit.slack.com/archives/C7SS31917/p1725017108211119?thread_ts=1725012640.985669&cid=C7SS31917

Can we make the functionality to generate circuits to measure the expectation values of observables available in qiskit? (either in the new BackendEstimatorV2, or some other class?