3
$\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$
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$

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.