# Qiskit - Circuit drawing aesthetics - Can I force the measurements in my circuit to show at the end?

I'm studying an introduction course to quantum computation at my uni and we got homework to draw a certain circuit using qiskit. I managed to understand how to do what is asked from me, and this is the final answer:

Now I know that once the qubit is no longer used in a manipulation you can measure it without effecting the results, however I find this circuit rather confusing and messy. Since we can always postponed our measurement to the end, I'd prefer a more organised drawing where all CNOT gates are performed, and only then the measurements - preferably from the top one to the bottom one. Is it possible to force such a thing?

To try and force the code doing that I tried to first use a for loop to apply CNOTs on every qubit, then using a seperate loop I performed the measurements on every qubit

circuit_three = QuantumCircuit(5, 5)
circuit_three.h(0)
for i in range(1, 5):
circuit_three.cx(0, i)
for i in range(0, 5):
circuit_three.measure(i, i)
circuit_three.draw(output='mpl', filename='3')


The desired result is this (done with paint): Thanks in advance

You can add a barrier before the measure

from qiskit import *
circuit_three = QuantumCircuit(5, 5)
circuit_three.h(0)
for i in range(1, 5):
circuit_three.cx(0, i)
for i in range(0, 5):    <--- side note: this can be replaced by circuit_three.measure_all()
circuit_three.measure(i, i)
circuit_three.draw(output='mpl')


Then, with the argument plot_barriers, skip the plotting of the barrier:

circuit_three.draw(output='mpl', plot_barriers=False)


An important caveat: the barrier have meaning for the transpiler. If you are planing to execute that circuit, remember to remove the added barrier.

• Super thanks, it worked as intended. I switched the measurement block to measure_all() as you suggested and it added a barrier between the CNOT gates and the measures automatically, even when i commented the .barrier() line. I didnt understand your comment about the barrier needed to be removed before executed. I read the post you sent and it seems like it is just an esthetic component that prevents the compiler from adding the gates together. I executed it and got the same count as before. So what exactly did you mean? Apr 1, 2021 at 13:45
• @Aqua If you leave the qubit just hanging around in the circuit, decoherence will happen and your result will be less ideal. However, if you removed the barrier, the qubit will be measured immediately after all the gates on its wired has been executed, hence the extracted result will be more ideal. Apr 1, 2021 at 14:16
• the @KAJ226 explanation hits the nail in the head! Apr 1, 2021 at 14:55
• @KAJ226 Got it. make sense... Usually in uni when we deal with quantum states we use eigen states and assume nothing is there to interact with it. So what you say is that theoretically in an ideal system/circuit it should'nt matter where i perform the measurement, but then the system is never ideal so if we wait noise might add up on the qubit. Thanks did'nt think of it that way. Apr 2, 2021 at 8:37