I want to use IBMQ's runtime Estimator primitive to address their systems. Since it has no function to return the transpiled circuit, but I need the knowledge what circuit exactly was executed in the end, I want to do the transpilation locally and then give that circuit into the estimator.
For the transpiling I add the needed post-rotations for measuring non-PauliZ, then add the classical registers for the measurements and then transpile this circuit. So I end up with a complete circuit with classical registers and qubits on which nothing happens, they are just part of the device. (see code below)
What is a elegant way to separate this into a circuit and an observable that I can pass to the estimator?
minimal `code example:
from qiskit import QuantumCircuit, transpile, IBMQ from qiskit_ibm_runtime import QiskitRuntimeService backend='ibmq_quito' service=QiskitRuntimeService() backend=service.get_backend(backend) #circuit circuit = QuantumCircuit(2) circuit.h(0) circuit.cx(0, 1) #post-rotations: want to measure 'XZ' meas_circuit= QuantumCircuit(2) meas_circuit.h(0) #add post-rotations to circuit full_circ=circuit.compose(meas_circuit).measure_all(inplace=False) #transpile trans_circ = transpile(full_circ, backend) print(trans_circ)
I want to use the estimator to measure the expectation value of ZZ on the non-idle qubits of trans_circ.
Since I need the same number of observables and qubits, can I just take the identity as observable for the qubits I am not interested in? Those will just give factors of 1 to each term of the expectation value. What I tried was:
service=QiskitRuntimeService() session=Session(service=service, backend=backend) options=Options() options.resilience_level=3 estimator=Estimator(session=session, options=options) params= obs=SparsePauliOp.from_list([("IIIZZ", 1)]) job=estimator.run(circuits=trans_circ, observables=obs, parameter_values=params) expvals=job.result().values print(expvals)
This gives me some output, but I am not sure whether it is correct: It returns values around 0.95 while I calculated an expectation value of 0.5 on paper. Is there a mistake or do I see the impact of noise of the hardware here like in this question?
Also what happens to the measurement instructions here? Are they ignored? Do I need them or better separate?