I have a circuit with 2 ancilla bits. I have only asked that the circuit measure the 4 other qubits, but the results keep including the ancilla bits. How to remove the ancilla bits from the results?


1 Answer 1


You can (and you should) always uncomputer ancilla qubits. This can be done by application of inverse gates in inverse order to original ones which prepared states of ancilla qubits.

Here is an example:


The purpose of the circuit is to calculate $q_0 \,\text{AND}\, q_1 \,\text{AND} q_2$. To do so, firstly $q_0 \,\text{AND}\, q_1$ is calculated and result is stored to ancilla $q_3$. After that final result is obtained by $q_2 \,\text{AND}\, q_3$ and stored to $q_4$. Finnaly, inverse operation (note that inverse gate to Toffoli is again Toffoli) is applied. As a result, state of ancilla $q_3$ is returned back to $|0\rangle$. This value is returned during measurement. If you do not want to include ancilla to measurement, simply do not put the measurement on qubit $q_3$.

  • $\begingroup$ Your comment helped me because I had used too many toffoli gates, so thank you. Simply not putting a measurement on the third qubit, however, doesn't stop it from being measured. From another source I found that you need to change [in the code] the creg from c[5] to c[4] and change measure q[4] -> c[4]; to measure q[4] -> c[3]; $\endgroup$
    – Requiem
    Jul 19, 2020 at 8:45
  • $\begingroup$ @Requiem: Thanks for addition. Originally, I though that you need to uncompute ancilla. Concerning the classical register, you are right that in case a bit is not used, it is still shown as 0. So, to trim length of classical register helps. $\endgroup$ Jul 20, 2020 at 7:13

Your Answer

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

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