What is the barrier in Qiskit for?

The barrier, in qiskit, draws a small line separating circuits.

I always thought that the barrier was just something visual, that it didn’t change anything in the circuit.

However, in fact, the barrier serves to give an instruction to the transpiler: don’t simplify the circuit in the separating barriers.

The simplest example is two H gates in series. The H applied twice equals identity, the effects cancel out. The transpiler simply ignores the two H gates and continues the circuit.

When we put a barrier between the Hs, the transpiler is forced to consider the two H operations. The reason for this? To measure the effect of some noise introduced by gates, for example.

Besides, it helps the visualization of subcircuits.

More information here:

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store