# qiskit - Is there any way to discard the results of a measurement?

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?

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

• I've updated my question to better clarify the issue. – tigerjack89 Dec 15 '18 at 17:48
• I'm not sure I understand. It is only the classical register that is shown in the output. Results from qubits only appear if measured. In that case, they appear on the classical bit you chose when measuring. – James Wootton Dec 15 '18 at 17:58
• Sure, but when I measure the n qubits, the result of the ancilla is still shown in the output. Instead, I only want the results from the n qubits, i.e. the one that I'm interested to. – tigerjack89 Dec 15 '18 at 18:11
• Does the new snippet in my edit do the kind of thing you want? – James Wootton Dec 15 '18 at 18:23
• Exactly this... – tigerjack89 Dec 15 '18 at 18:25