projekter/yquant

Align ellipsis gate on discarded qubit

Closed this issue · 2 comments

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} 

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

  • When you define a box, the content of this box is given in its definition. Therefore, there is no need to pass any value to the custom box gates (dots seln; instead of dots {} seln;).
  • yquant's register specification is quite versatile. If you want to do discard x; dots x; for the gates x, y, and z, you can of course write it in this way in six lines, but you can easily combine all the stuff: discard x, y, z; dots x, y, z;. Bonus: This immediately solves your alignment problem, since if you specify a gate in this way, it is ensured that the horizontal position of this gate is the same for all gates. No align gate even necessary!
  • In case you wonder how you could do it without exploiting this nice feature: You'd have to rearrange your commands a bit. If you say align -;, this will align all registers horziontally, so that the next gate on any register will start at the position where the rightmost among all registers had its last gate. Therefore, you must first discard all the gates discard seln; discard hn; discard synn; (and here I do it separately just to avoid the automatic alignment), then you can say align -;, and after this you can put your dots seln; dots hn; dots synn;.
  • Since you initialize all registers with empty text, I would just move this to an option, then you can also get rid of the empty values.
  • I would use vector registers and immediately discard the middle ones - this makes adressing a bit easier.
  • Regardless of the use of vector registers, I would recommend addressing the registers in ranges: sels-sele instead of sels, seln, sele, or - instead of enumerating all possible registers.
  • Actually, why do you discard the ...n registers a second time? They did not change their type, so this is really unnecessary.

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...).

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 :)