projekter / yquant

Typesetting quantum circuits in a human-readable language
LaTeX Project Public License v1.3c
56 stars 5 forks source link

Align ellipsis gate on discarded qubit #13

Closed tigerjack closed 2 years ago

tigerjack commented 2 years ago

I would like to align the output of the last barrier of vdots in the document, but I am not sure how. I tried the align command, but it doesn't seem to work. What is the recommended way in this situation?

image

As a side note, I am still not sure if my code is to "optimal" way to achieve my result or there is a more compact version.

\documentclass[tikz]{standalone}
\usepackage[compat=0.4]{yquant}
\usepackage{braket}
\newcommand{\qreg}[1]{\texttt{#1}}
\yquantdefinebox{dots}[inner sep=0pt]{$\vdots$}

\begin{document}
\begin{tikzpicture}
  \begin{yquant}
    % [name=qsel]
    qubit {} sels;
    nobit seln;
    qubit {} sele;
    qubit {} hs;
    nobit hn;
    qubit {} he;
    qubit {} syns;
    nobit synn;
    qubit {} syne;
    %
    init {$\qreg{sel}$} (sels, seln, sele);
    init {$\qreg{h}$} (hs, hn, he);
    init {$\qreg{syn}$} (syns, synn, syne);
    % discard is necessary because otw init will draw the line
    discard seln;
    dots {} seln;
    discard hn;
    dots {} hn;
    discard synn;
    dots {} synn;
    %
    box {A} (sels, seln, sele);
    box {B} (sels, seln, sele, hs, hn, he, syns, synn, syne);
    box {C} (sels, seln, sele);
    %
    discard seln;
    dots {} seln;
    discard hn;
    dots {} hn;
    discard synn;
    dots {} synn;
    % 
    output {$n$} (sels, seln, sele);
    output {$rn$} (hs, hn, he);
    output {$r$} (syns, synn, syne);
  \end{yquant}
\end{tikzpicture}
\end{document} 
projekter commented 2 years ago

Ok, a couple of comments, since you also wanted to shorten your code:

Put all together, this is how I would write the circuit:

  \begin{yquant}[register/default name=]
    qubit sel[3];
    qubit h[3];
    qubit syn[3];

    init {$\qreg{sel}$} (sel);
    init {$\qreg{h}$} (h);
    init {$\qreg{syn}$} (syn);
    discard sel[1], h[1], syn[1];

    dots sel[1], h[1], syn[1];

    box {A} (sel);
    box {B} (-);
    box {C} (sel);

    dots sel[1], h[1], syn[1];

    output {$n$} (sel);
    output {$rn$} (h);
    output {$r$} (syn);
  \end{yquant}

And by the way, I feel that the \vdots are a bit off vertically. This is a rather common problem whenever you use \vdots outside of a matrix environment (and even then I'm not totally satisfied with TeX's results). Have a look at \rvdots, which I think is better, though I must admit that I still think it is not perfectly centered. You may need to adjust the \rvdots definition a bit (or just be comfortable with how it is...).

tigerjack commented 2 years ago

Thanks for spending your time on such a precious and detailed answer @projekter I am just starting to use the tool and I still have a lot to learn :)