What is the barrier in Qiskit for?

Arnaldo Gunzi
Arnaldo Gunzi Quantum
Aug 2, 2021

--

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:

--

--

Arnaldo Gunzi
Arnaldo Gunzi Quantum

Project Manager - Advanced Analytics, AI and Quantum Computing. Sensei of Analytics.