6
$\begingroup$

I'm trying to construct a quantum circuit with 3 mid-circuit measurements, here's an example:

 qrz = QuantumRegister(2,'q')
 crz = ClassicalRegister(3,'c')
 qc = QuantumCircuit(qrz,crz)
 for i in range (3):
    qc.append(qc1(...),[0,1]). # qc1 is some circuit segment.
    qc.measure(1,i)
    qc.barrier()
    qc = transpile(qc,backend=backend,optimization_level=2,initial_layout = [0,1])

I'm wondering if I could perform the readout error mitigation in this case. Here's what I'm trying to do:

import matplotlib.pyplot as plt
qlist = [1]    # Suppose we want to perform the mid-circuit measurement on this qubit.
cal_circuits, state_labels = complete_meas_cal(qubit_list= qlist,circlabel='mcal')
print(len(cal_circuits))
cal_job = execute(cal_circuits, 
                 backend = backend,
                 shots = 1024,
                  optimization_level = 0
                 )
cal_results = cal_job.result()
meas_fitter = CompleteMeasFitter(cal_results, state_labels)  # Generate the complete fitter. 
fig, ax = plt.subplots(figsize=(10, 10))
meas_fitter.plot_calibration(ax)
meas_filter = meas_fitter.filter

Is there a way I can apply the filter to the qubit that I measured 3 times? Thanks for the help:)

$\endgroup$
7
+100
$\begingroup$

That's a very interesting question, I haven't thought about it before, thanks for that!

Now, the way I see this, you have 2 different potential paths to investigate.

1

The first one would be the same as the other answer, meaning you look independently at each result by using marginal_counts :

raw_res0 = marginal_counts(results, indices=[0])
raw_res1 = marginal_counts(results, indices=[1])
raw_res2 = marginal_counts(results, indices=[2])

And the you apply the filter to each raw_res

#You can do this step only once
meas_filter = meas_fitter.filter
# You do this for each raw_res 
mitigated_results0 = meas_filter.apply(raw_res0)
mitigated_counts0 = mitigated_results0.get_counts(0)
plot_histogram([raw_res0.get_counts(), mitigated_counts0], legend=['raw0', 'mitigated0'])

Now, I think that this may be oversimplifying the problem, since they are many cause for errors, and that one measure error can have consequences on the future measurements, but this is still a good place to start and comprehend how to correct the dependencies between everything.

2

Another idea I had would be to do your qc1 segment only once, measure (only once as well) the resulting state, correct via your filter the counts you have, and from that, "create" the state you measured (careful with this, of course you'll never be able to reproduce exactly the state you had before measurement, but create something "similar"), and start from there for the second round of your qc1 and so on.

To be more specific, once you have your mitigated counts, from that, you may take the square root of each probabilities to get "the amplitudes", say new_state, and then you can create it on your quantum circuit via the initialize method, for example to initialize 2 qubits :

qr = QuantumRegister(2)
cr = ClassicalRegister(2)
qc = QuantumCircuit(qr,cr)
qc.initialize(new_state, [0,1])
#and whatever you want next

Once again, this is just the beginning of a reflexion, as for the first idea, lots could be wrong, especially the initialization to create the state for the next step, but this could be a first step to develop a nice procedure for this kind of situation.

I hope all of this will help you on your problem, best of luck! :)

$\endgroup$
1
  • 2
    $\begingroup$ Thank you so much for the helpful answer! $\endgroup$
    – ZR-
    Jun 15 at 18:13
3
$\begingroup$

Yes! You would need 3 times the number of classical registers to store each measurement. Please see this.

simp_counts1 = marginal_counts(simp_job.result(), indices=[0]).get_counts()
simp_counts2 = marginal_counts(simp_job.result(), indices=[1]).get_counts()
simp_counts3 = marginal_counts(simp_job.result(), indices=[3]).get_counts()

The for each measurement use your filter, for example:

meas_filter = meas_fitter.filter
mitigated_results = meas_filter.apply(sim_counts1)
$\endgroup$
1
  • 1
    $\begingroup$ Thank you for the answer, that's really helpful! $\endgroup$
    – ZR-
    Jun 15 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.