1
$\begingroup$

Setup

I am drawing this circuit:

qc_b = QuantumRegister(2, 'b')
qc_f1 = QuantumRegister(1, 'f1')
qc_a1 = QuantumRegister(1, 'a1')
qc_a2 = QuantumRegister(1, 'a2')
qc_f2 = QuantumRegister(1, 'f2')

qc_0 = QuantumCircuit(qc_a1, qc_f1, qc_b, qc_f2, qc_a2)

qc_0.x(qc_f1)
qc_0.barrier([*range(1, 5)])

for t in range(0, 3):
    if t != 0:
        qc_0.reset(qc_a1)
        qc_0.reset(qc_a2)
    qc_0.unitary(np.eye(2**4), range(1, 5), label=h_label)
    qc_0.unitary(np.eye(2**2), [0, 1], label=l_label)
    qc_0.unitary(np.eye(2**2), [4, 5], label=l_label)


qc_0.barrier([*range(1, 5)])
qc_0.unitary(np.eye(2), [1], label='M')
qc_0.unitary(np.eye(2), [2], label='M')
qc_0.unitary(np.eye(2), [3], label='M')
qc_0.unitary(np.eye(2), [4], label='M')

qc_0.draw('latex')

Which gives me this picture:

circuit_with_numbers

Question

How can I remove the 'qubit numbers' (the 0, 1, 2, 3 before every unitary)?

$\endgroup$

1 Answer 1

3
$\begingroup$

As far as I understand, there is no built-in method that allows that unfortunately.

But - what you can do is getting the LaTex code by using the command print(qc_0.draw(output = 'latex_source')).Then you can edit the Latex output and remove those qubit numbers (Using print() is necessary otherwise we get a messy LaTex code).

If you add this piece of code at the bottom of your code:

latex_source = qc_0.draw('latex_source')
for number in range(4):
    look_for = "<<<{" + str(number) + "}"
    latex_source = latex_source.replace(look_for,"<<<{}")
print(latex_source)

Then you get this output:

\documentclass[border=2px]{standalone}

\usepackage[braket, qm]{qcircuit}
\usepackage{graphicx}

\begin{document}
\scalebox{1.0}{
\Qcircuit @C=1.0em @R=0.2em @!R { \\
        \nghost{{a1} :  } & \lstick{{a1} :  } & \qw & \qw & \qw & \multigate{1}{\mathrm{D}}_<<<{} & \gate{\mathrm{\left|0\right\rangle}} & \multigate{1}{\mathrm{D}}_<<<{} & \gate{\mathrm{\left|0\right\rangle}} & \multigate{1}{\mathrm{D}}_<<<{} & \qw & \qw & \qw & \qw\\
        \nghost{{f1} :  } & \lstick{{f1} :  } & \gate{\mathrm{X}} \barrier[0em]{3} & \qw & \multigate{3}{\mathrm{H}}_<<<{} & \ghost{\mathrm{D}}_<<<{} & \multigate{3}{\mathrm{H}}_<<<{} & \ghost{\mathrm{D}}_<<<{} & \multigate{3}{\mathrm{H}}_<<<{} & \ghost{\mathrm{D}}_<<<{} \barrier[0em]{3} & \qw & \gate{\mathrm{M}} & \qw & \qw\\
        \nghost{{b}_{0} :  } & \lstick{{b}_{0} :  } & \qw & \qw & \ghost{\mathrm{H}}_<<<{} & \qw & \ghost{\mathrm{H}}_<<<{} & \qw & \ghost{\mathrm{H}}_<<<{} & \qw & \qw & \gate{\mathrm{M}} & \qw & \qw\\
        \nghost{{b}_{1} :  } & \lstick{{b}_{1} :  } & \qw & \qw & \ghost{\mathrm{H}}_<<<{} & \qw & \ghost{\mathrm{H}}_<<<{} & \qw & \ghost{\mathrm{H}}_<<<{} & \qw & \qw & \gate{\mathrm{M}} & \qw & \qw\\
        \nghost{{f2} :  } & \lstick{{f2} :  } & \qw & \qw & \ghost{\mathrm{H}}_<<<{} & \multigate{1}{\mathrm{D}}_<<<{} & \ghost{\mathrm{H}}_<<<{} & \multigate{1}{\mathrm{D}}_<<<{} & \ghost{\mathrm{H}}_<<<{} & \multigate{1}{\mathrm{D}}_<<<{} & \qw & \gate{\mathrm{M}} & \qw & \qw\\
        \nghost{{a2} :  } & \lstick{{a2} :  } & \qw & \qw & \qw & \ghost{\mathrm{D}}_<<<{} & \gate{\mathrm{\left|0\right\rangle}} & \ghost{\mathrm{D}}_<<<{} & \gate{\mathrm{\left|0\right\rangle}} & \ghost{\mathrm{D}}_<<<{} & \qw & \qw & \qw & \qw\\
\\ }}
\end{document}

If you render the above output in this engine for example, then you get your wish:

enter image description here

The piece of code that i have wrote just erases the numbers in the phrases <<<{QUBIT_NUMBER_HERE} in the LaTex code. I have set the range to of the loop to 4 and it's enough that case - but of course it can be extended to erase as much qubit numbers as needed.

$\endgroup$
3
  • $\begingroup$ Thanks for the hint :). At this point I might just go into GIMP and draw over it in the png. $\endgroup$ Aug 18, 2022 at 6:13
  • $\begingroup$ @AndreasBurger I have modified my answer such that a nice loop handles the issue easily now. $\endgroup$
    – Ohad
    Aug 18, 2022 at 10:31
  • $\begingroup$ Thanks for the effort! Works perfectly :) $\endgroup$ Aug 19, 2022 at 0:04

Your Answer

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

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