5
$\begingroup$

Here's my circuit, trying to checkout the effect of measurement on the IBM Q circuit. Here you can see I do 2 different measurement at different time, and I hope to be able to see both results. However, I do not know how to do so. enter image description here

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc = QuantumCircuit(q, c)
qc.h(q[0])
qc.cx(q[0], q[1])
qc.measure(q,c)
job_sim = execute(qc, backend=simulator, shots=1024)
counts_sim = job_sim.result().get_counts(qc)
qc.cx(q[0], q[1])
qc.measure(q,c)
job_sim2 = execute(qc, backend=simulator, shots=1024)
counts_sim2 = job_sim2.result().get_counts(qc)

Can anyone tell me how do I extract all measurement results at different time from the same classical bits in one execution? Thank you!

$\endgroup$

3 Answers 3

2
$\begingroup$

Unfortunately this is not currently possible on the IBM devices.

What you should really do is only have four classical channels and send your first two measurements to the first two classical channels, and the second two measurements to the second two classical channels. You then only execute the circuit once. However, you can try this and it still won't work because this can't yet be done on the IBM machines.

edit: a slightly more constructive answer is that you can achieve what you want using two extra qubits. The idea is to replace the first two measurements with CNOTs with the controls on your qubits and the target on the extra qubits. You can then measure all four qubits. The measurement of the extra qubits corresponds to your first set of measurements and the measurements of your original qubits corresponds to the second set of measurments.

$\endgroup$
1
$\begingroup$

When you measure, you choose a bit where the result should go. If you measure to the same bit multiple times, then the results of all but the last will not be recorded.

To get the results you want, you'll need to declare more bits. For example, you could use a couple of two-bit classical registers: one for the first pair of bits, and the other for the second.

q = QuantumRegister(2)
c1 = ClassicalRegister(2)
c2 = ClassicalRegister(2)
qc = QuantumCircuit(q, c)
qc.h(q[0])
qc.cx(q[0], q[1])
qc.measure(q,c1)
job_sim = execute(qc, backend=simulator, shots=1024)
counts_sim = job_sim.result().get_counts(qc)
qc.cx(q[0], q[1])
qc.measure(q,c2)
job_sim2 = execute(qc, backend=simulator, shots=1024)
counts_sim2 = job_sim2.result().get_counts(qc)

As the other answer notes, this will not currently run on real hardware. Only on simulators.

$\endgroup$
1
$\begingroup$

This is now possible. Please check https://quantum-computing.ibm.com/lab/docs/iql/manage/systems/midcircuit-measurement/

$\endgroup$
1
  • $\begingroup$ Please avoid link only answers (that is, answers that contain very little or no information if the link dies); could you edit this to contain some of the relevant information from the link? $\endgroup$
    – auden
    Jun 14, 2021 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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