Closed tigerjack closed 11 months ago
The warning goes away if I use an additional qubit, like this
\documentclass[tikz]{standalone}
\usepackage[compat=0.6]{yquant}
\begin{document}
\begin{tikzpicture}
\begin{yquant}
qubit {} c[1];
qubit {} a[2];
swap a | c; % I use a separate qubit as control
\end{yquant}
\end{tikzpicture}
\end{document}
First of all, it is just a warning. Therefore, you may always ignore those possibly without any issues.
Second, the warning does not go away, but it just does not apply to the second situation. In the first situation, you place a multi-qubit SWAP gate on the qubits a[0]
and a[1]
with some control. In the second situation, you place two single-qubit SWAP gates (yes, this does not make any semantic sense, but it cannot be distinguished visually due to how the gate looks like). So semantically, your second example is something completely different, which you can easily see if you replace the SWAP operation by, e.g., a box
gate.
Third, the meaning of the warning is that if a multi-qubit gate spreads among various registers, it just grows in size. However, if a gate acts on multiple discontiguous registers (say, just 1 and 3), it cannot do this (how would you then notice that it does not act on 2). Therefore, it is split into two parts which are connected by a vertical wavy line. Now, if you have controls, the control line must extend from the topmost to the bottommost involved register. Obviously, this leads to overlapping lines and will make the whole circuit not only visually displeasing, but hard to grasp.
You might now say that this has nothing to do with the current situation, as a[0]
and a[1]
are adjacent. True, but the SWAP gate is special: The shape of the SWAP gate is a cross. Now, clearly this cross does not scale vertically into a giant distorted cross when it's acting on multiple gates. Instead, even adjacent registers are always treated as discontiguous. Therefore, the situation that I described above always applies to SWAP. And SWAP also restyles the line between such now-discontiguous registers: It becomes a straight instead of a wavy line, as this is how the gate usually looks like.
Due to these specialties, the warning above actually does not make a lot of sense. But I'll have to think of how to be effective here - the warning should only occur if multiple SWAPs are written with a control, as in swap (a), (b) | c;
- now there's absolutely no way to see what is swapped, although it is in priciple a valid operation and indeed perfectly fine without the control. But I won't be doing this on my holiday.
Oh, and of course you can just turn off the warning globally, for all SWAPS, or locally by setting /yquant/operator/multi warning
to false
at the appropriate places.
I've got a better handle on where this behavior is coming from now, and I appreciate the explanation. I just wanted to mention a couple of things:
swap
gates are treated like 'zz' gates? It only requires changing two
dot symbols to a cross. I'm not sure how feasible that is, but it might help address the problem.By the way, I don't want to mess with your holiday vibes at all! If you need any assistance with testing or anything else, just give me a shout.
Yes, this is of course correct - there is no good reason why the control line should extend all the way down. It would be enough if it went to the first (or last, depending on where the control is) register that is affected by the multi-register gate. However, there are certain scenarios that have to be thought about:
Now, these are all somewhat unprobable scenarios. There is not really an established standard of how to even draw multi-register gates over non-adjacent registers. (Which makes sense, as hardware support...still has a lot of potential.) The squiggly line was just a choice of mine. Maybe this will also change if the community decides to, say, keep the straight line, rendering the whole discussion obsolete. The reason for my choice was that with just straight lines, it is not possible to distinguish a controlled non-contiguous multi-register gate from two controlled single- (or contiguous multi-)register gate.
The current behavior in yquant is just the one that is easiest to implement: A control line by definition always runs from the topmost to the bottom-most register that is involved. In both scenarios that is sketched above, you could of course say: But the squiggly line basically means that this is just a single gate, and we don't draw control lines without gates. I agree, but I'll have to think a bit more possible edge cases.
/yquant/operator/multi as single
is in effect.multi as single
operators), it is unclear how the gates all act together. However, there is further knowledge available about the gates which tells us that they won't ever occur in a single-register context. This is true for all multi as single
gates, which are xx
, zz
, swap
, and iswap
. So in this particular case, it would make sense to suppress the warning unless there are two multi-register gates plus control in a single operation.Please check the latest commit, which should address the warning issue.
I agree on this, there are several edge cases. While sketching my algorithms on paper, I often uses a puzzle pieces notation, which you can see below. I am bad at drawing, but the point on how to differentiate multi-target control qubits and multi-register gates should be clear. I don't know how difficult it is to implement it using tikz though.
I was thinking of something like this, which allows avoiding treating the swap like a general box. Note that the code doesn't work, it is just to show the idea.
\begin{yquant}
qubit {$q_\idx$} q[4];
%
[this control/.code={\unexpanded{%
\ifcase\idx\relax%
\pgfkeysalso{cross}%
\or%
\pgfkeysalso{cross}%
\else%
\pgfkeysalso{circle}%
\fi%
}}]
zz (q[3], q[0], q[1], q[2]);
\end{yquant}
only at
style, which I added in 0.7.3 (because of #25). Using this, it is fairly easy. You just have to change the shape
of the nodes. Usually, for zz
it is yquant-circle
, if you want a cross, use yquant-swap
instead. Of course, you can also use a swap
gate and change the style of the control node to yquant-circle
and add some filling.Hi @projekter , thanks for your reply.
\documentclass[tikz]{standalone}
\usepackage[compat=0.7]{yquant}
\useyquantlanguage{groups}
\usetikzlibrary{shapes, shapes.misc}
\usepackage{amssymb}
\begin{document}
\newcommand\withsouth[2]{%
\yquant [name=southgate] #2;
\node[inner sep=0pt, yshift=-5.6pt] at (#1 -| southgate.south) {$\scriptscriptstyle\blacktriangle$};
}
\newcommand\withnorth[2]{%
\yquant [name=northgate] #2;
\node[inner sep=0pt, anchor=north, yshift=7pt,fill=white] at (#1 -| northgate.north) {$\scriptscriptstyle\blacktriangledown$};
}
\newcommand\withboth[2]{%
\yquant [name=meridiangate] #2;
\node[inner sep=0pt, yshift=-5.6pt] at (#1 -| meridiangate.south) {$\scriptscriptstyle\blacktriangle$};
\node[inner sep=0pt, anchor=north, yshift=7pt] at (#1 -| meridiangate.north) {$\scriptscriptstyle\blacktriangledown$};
}
\begin{tikzpicture}
\begin{yquant}
[name=q1] qubit x;
qubit {} a[3];
[name=q2] qubit y;
qubit {} b[3];
[name=q3] qubit z;
zz (x,z, a[2], b[1]);
hspace {-6mm} -;
\withsouth{q1}{[fill=white]box {G} x}
\withboth{q2}{[fill=white]box {G} y}
\withnorth{q3}{[fill=white]box {G} z}
\end{yquant}
\end{tikzpicture}
\end{document}
The output is the following. It was a quick POC, but you get the idea.
Unfortunately, I do not know much about the inner working of tex to help you. I just adapted the code you provided in a previous reply
zz
gate, but with a different shape. Something like what you suggested already, that is \begin{yquant}
qubit q[2];
%
[operator style={only at={0}{shape=yquant-swap,radius=.75mm,draw}}]
zz (q[1], q[0]);
\end{yquant}
But under the hoods, avoiding therefore the problems with the other box
gates.
The previous circuit, although producing the correct result, raises the following warning
I'm using
lualatex
, but the warning is also raised withxelatex
andpdflatex
. Tex version isTeX 3.141592653