2

I have a circuit composed by n qubits, plus a single one which is an ancilla. I'm making multiple measurements on the ancilla at different stages of the circuit, while working on the n qubits. These measurements are not really needed at all: they are just a way to collapse the state of the qubit at some point during the computation and then reuse the same qubit in a different way.

At the end of the circuit, when I'm measuring the outcome of the n qubits, I don't want the result of this ancilla to be shown in the output of the get_counts() function; what I want is only the output of the n qubits. Is there any way to achieve this result?

tigerjack
  • 538
  • 3
  • 16

1 Answers1

2

If you keep measuring to the same bit, the value should get overridden every time. So you won't receive the intermediary values.

For example, the following will output a single 1 from the second measurement, with no trace of the first.

from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit
from qiskit import execute
from qiskit import BasicAer

q = QuantumRegister(1)
c = ClassicalRegister(1)
qc = QuantumCircuit(q,c)

qc.measure(q,c)
qc.x(q)
qc.measure(q,c)

job = execute(qc,backend=BasicAer.get_backend('qasm_simulator'))
job.result().get_counts()

I guess what you want is something more like

q = QuantumRegister(n) # n qubits
a = QuantumRegister(1) # one ancilla qubit
c = ClassicalRegister(n) # n classical bits for output

qc = QuantumCircuit(q,a,c)

qc.x(a[0]) 
qc.measure(a[0],c[0]) # measure the ancilla to one of the classical bits

qc.measure(q,c) # measure the n qubits to the n bits (overwriting the output from the previous measurement
James Wootton
  • 11,272
  • 1
  • 31
  • 72