projekter/yquant

Add support for iSWAP gate

Closed this issue · 2 comments

Is your feature request related to a problem? Please describe.
Not really a problem, but I've been writing several circuits that use a lot of iSWAPS, and it's a nice compact way to write them the way it is written in the qiskit documentation. Currently, I can only do this by manually adding crossed out circles with tikz, and it looks great but it's cumbersome. It seems there should be a way to have the gate representation added but I'm not very savy with latex.

Describe the solution you'd like
Just like we would have

\begin{yquant}
    qubit {} q[2];
    swap (q[0], q[1]);
\end{yquant}

for swap gates, it would be nice if we could write

\begin{yquant}
    qubit {} q[2];
    iswap (q[0], q[1]);
\end{yquant}

and get the outputs from the screenshots below

Describe alternatives you've considered
Currently, the way I get the desired output as mentioned above is by following this mwe:

\documentclass[margin=2mm]{standalone}

\usepackage{yquant}

\begin{document}

\usetikzlibrary{shapes.misc}
\tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt}, cross/.default={2.5pt}}

\begin{tikzpicture}
	\begin{yquant}
		qubit {} q[2];
		swap (q[1], q[0]);
	\end{yquant}
	\draw[fill=white] (0.35 ,-0.15) circle (3pt);
	\draw (0.35 ,-0.15) node[cross] {};
	\draw[fill=white] (0.35 ,-0.55) circle (3pt);
	\draw (0.35 ,-0.55) node[cross] {};
\end{tikzpicture}

\end{document

which produces the screenshot below. But this is very cumbersome since I have to manually edit the numbers in the \draw instructions to align the crossed circles.
Screen Shot 2022-11-28 at 1 23 06 PM

Please check whether the current commit satisfies what you'd expect from the iSWAP gate, then I'll push the new version to CTAN.
By the way, you should never mix yquant and TikZ code in this way. Here, you hardcoded the positions of the gates. If you instead use yquant's naming mechanism, you can use positions that are relative to gates and therefore will automatically always be at the correct position.

I changed the internal way of drawing by creating a new shape (so that anchors are correct and not rotated) and set the default size so the one of SWAP for consistency. Since there were no further comments, this is now v0.7.2, which should be available on CTAN within the next days.