5
$\begingroup$

As you may know, one can use barriers in Qiskit to seperate gates on a circuit in a proper way. So, I was wondering is there a way to give a title to these "sections" seperated by barriers?

I provide an example in Figure below. Titles does not need to be exactly same with the ones in the Figure. It is just an example.

enter image description here

$\endgroup$

2 Answers 2

4
$\begingroup$

The short answer is that the circuit drawer does not have a way to label "sections".

However, you can pass an arbitrary matplotlib.axes.Axes to the Matplotlib circuit drawer (only to that circuit drawer) where you can set and position your labels by hand. For your particular case, it looks something like this:

from matplotlib.pyplot import figure

fig = figure()
ax = fig.add_subplot()
height = 0.8
ax.text(-0.9, height, 'entanglement', size=14)
ax.text(2.5, height, 'init', size=14)
ax.text(4.5, height, 'transfer of\namplitudes', size=14)
ax.text(7, height, 'measurement', size=14)

circuit.draw('mpl', ax=ax)

enter image description here

You might have to adapt the x and y numbers (the first two parameters for text) to readjust their position.

$\endgroup$
2
  • $\begingroup$ I was looking for a built-in method which can automatically determine the positions of labels according to the barrier placements. But I guess this is the best solution we have right now. I appriciate your time and effort:) $\endgroup$
    – Saba
    Mar 14, 2021 at 10:14
  • 1
    $\begingroup$ Sorry, no build-in. The ax parameter was design as a catch-all for these use cases... $\endgroup$
    – luciano
    Mar 14, 2021 at 21:31
1
$\begingroup$

Maybe not looking as good as in the above mentioned solution, but much more convenient to use. The barrier can use a label parameter as shown below.

barrier with label

$\endgroup$

Your Answer

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

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