Open BhumikaSaini opened 4 months ago
Adding two barriers with different semantics seems confusing and the full point of barrier
is to have optimization consequences (the drawing alignment is more of a collateral effect).
Let me offer you the following workaround. You can remove the barrier before optimizing with qiskit.transpiler.passes.RemoveBarriers
:
For example:
from qiskit import QuantumCircuit
circuit = QuantumCircuit(4)
circuit.z(0)
circuit.h(3)
circuit.barrier()
circuit.h(range(4))
circuit.barrier()
circuit.draw('mpl')
circuit.draw('mpl', plot_barriers=False)
from qiskit.transpiler.passes import RemoveBarriers
remove_barriers = RemoveBarriers()
new_circuit = remove_barriers(circuit)
new_circuit.draw('mpl')
What do you think? That covers your use-case?
Support idea for only visual barriers
Does plot_barriers=False
help?
What should we add?
Often, it is helpful to add visual barriers in the rendered circuit for ease of reference. Currently, this is achieved via the
Barrier
instruction. However, using theBarrier
instruction has a direct impact on circuit optimizations (docs).Is there any existing support for visual-only barriers that don't affect circuit optimization? If not, I think adding this might be helpful.
For instance, the following is much easier to reference and looks better organized with the help of barriers...
... as compared to:
While this is a toy example, visual barriers would help for more complex circuits.
Proposed approaches:
Barrier
that denotes whether the barrier is a visual-only barrier or if it affects compilation too. The two barriers types should be rendered differently.