4

I'm using Quantikz to draw a multiqubit gate (=labelled box) without targeting some qubits (=horizontal lines).

I have never used tikz before and wonder if there is an easy way to get the desired output.

The idea is to represent quantum gates between specific qubits as shown in the picture, where J13 does not affect qubit 2 (middle line). I would like to have this qubit line going above the J13 box: like this

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\begin{document}
\begin{tikzcd}
 & \gate[wires=2]{J_{12}} & \gate[wires=3]{J_{13}} & \qw                    & \qw \\
 &                        &  \gateinput{------}\gateoutput{------}  & \gate[wires=2]{J_{23}} & \qw \\
 & \qw                    &                        &                        & \qw
\end{tikzcd}
\end{document}

In my failed attempt (picture above) I added dashes to the gate, but they have the wrong thickness, and this will need readjustment every time I widen the size of the box. Coming up with a solution using xshift and yshift will suffer from the latter problem as well.

I think the easiest solution would be to make the quantum wire command "\qw" draw above the boxes by default, instead of using "\gateinput{------}\gateoutput{------}".

A more complicated solution might be to write a command targeting specific qubits for this kind of boxed gates.

Any recommendation or solution?

4
  • 3
    Welcome to TeX.SX. There are many ways in which the above figure can be drawn. But it would be better if you can provide a minimal working example of what you have tried so that folks here can help you finish it.
    – nidhin
    Dec 15, 2018 at 7:16
  • The example is working now
    – Rol
    Dec 16, 2018 at 22:22
  • 1
    @Rol No, it's still just a code fragment. Please embed it into a compilable document, beginning with \documentclass{...} and ending with \end{document}.
    – Alan Munn
    Dec 16, 2018 at 22:56
  • @Alan Munn OK, done
    – Rol
    Dec 17, 2018 at 6:31

2 Answers 2

4

Premise: I'm not a physicist, I do not know what you're talking about.

You can use the option execute at end picture={...} to add some code to be executed after your tikzcd.

\tikzcdmatrixname is the name of the TikZ matrix the tikzcd is translated into.

\tikzcdmatrixname-r-c is the name of the cell of the TikZ matrix at the rth row and cth column.

Maybe there is a better method (without manual adjustments xshift and yshift) but I don't know it.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\begin{document}
    \begin{tikzcd}[execute at
        end picture={
            \draw[thick] ([yshift=-23.8pt, 
            xshift=39pt]\tikzcdmatrixname-1-1.north 
            west) -- 
            ([yshift=-23.8pt, xshift=-39pt]\tikzcdmatrixname-1-5.north west);
        }]
        & \gate[wires=2]{J_{12}} & \gate[wires=3]{\raisebox{4pt}{$J_{13}$}} & 
        \qw                    & \qw \\
        &                        &  & 
        \gate[wires=2]{J_{23}} & \qw \\
        & \qw                    &                        
        &                        & \qw
    \end{tikzcd}
\end{document}

enter image description here

Here is a pure TikZ alternative without fine-tuning with a matrix:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix, fit}
\tikzset{gate/.style={rectangle, thick, fill=white,align=center, draw, text width=1.5em}}
\begin{document}
    \begin{tikzpicture}
    \matrix[matrix of nodes,
        nodes in empty cells,
        column sep=2.5em,
        row sep=4ex] (mymatr) {
        &[-1em]&&&[-1em]\\
        &&&&\\
        &&&&\\};
    \draw[thick] (mymatr-1-1) -- (mymatr-1-5);
    \draw[thick] (mymatr-3-1) -- (mymatr-3-5);
    \node[fit=(mymatr-1-3)(mymatr-3-3), gate, text height=5ex] {$J_{13}$};
    \draw[thick] (mymatr-2-1) -- (mymatr-2-5);
    \node[fit=(mymatr-1-2)(mymatr-2-2), gate] {$J_{12}$};
    \node[fit=(mymatr-2-4)(mymatr-3-4), gate] {$J_{23}$};
    \end{tikzpicture}
\end{document}

enter image description here

Here is a pure TikZ alternative without fine-tuning and without any matrix:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\tikzset{gate/.style={rectangle, thick, align=center, draw, text width=1.5em}}
\begin{document}
    \begin{tikzpicture}[node distance=1.5em]
    \node[gate, minimum height=18ex, text height=0ex] (j13) {$J_{13}$};
   \node[left =of j13.north west, anchor=north east, minimum height=12ex, gate] (j12) {$J_{12}$};
    \node[right =of j13.south east, anchor=south west, minimum height=12ex, gate] (j23) {$J_{23}$};
    \coordinate (start1) at ([yshift=-2ex]j12.north west);
    \coordinate (end1) at ([xshift=1em]j23.east |- start1);
    \draw[thick] (start1) -- +(-1em, 0);
    \draw[thick] (start1 -| j12.east) -- (start1 -| j13.west);
    \draw[thick] (start1 -| j13.east) -- (end1);
    \coordinate (start2) at ([yshift=2ex]j12.south west);
    \draw[thick] (start2) -- +(-1em, 0);
    \draw[thick] (start2 -| j12.east) --
    (start2 -| j23.west);
    \draw[thick] (start2 -| j23.east) --
     +(1em, 0);
     \coordinate (start3) at ([yshift=2ex]j23.south west -| start1);
    \draw[thick] (start3) +(-1em, 0) -- (start3 -| j13.west) ;
    \draw[thick] (start3 -| j13.east) --
     (start3 -| j23.west);
     \draw[thick] (start3 -| j13.east) --
     (start3 -| j23.west);
    \draw[thick] (start3 -| j23.east) --
     +(1em, 0);
    \end{tikzpicture}
\end{document}

enter image description here

4
  • Thank you for the answer. I edited my post to make clear that the issue is about the center line being odd when it crosses the middle box. The top and bottom grey boxes are residues of a snip when I generated a .jpg file, because I can't upload .pdf files to this site
    – Rol
    Dec 18, 2018 at 5:47
  • While this works for now, it needs some trial and error to adjust the position and size of the line for arbitrary drawings. But I guess I can build upon from here. Thank you.
    – Rol
    Dec 24, 2018 at 1:02
  • @Rol If you want to use quantikz I'm afraid there's no better solutions. With pure tikz it would be very easy but you'd loose the \gate and \qw commands. Thank you for accepting my answer!
    – CarLaTeX
    Dec 24, 2018 at 4:22
  • @Rol See my renewed answer for some pure TikZ alternatives.
    – CarLaTeX
    Dec 24, 2018 at 7:30
1

For the use of future viewers of this question, this functionality can be achieved directly within quantikz:

\begin{quantikz}[transparent]
& \gate[2]{J_{12}} & \gate[3,label style={yshift=0.2cm}]{
J_{13}} & \qw & \qw \\
& & \linethrough &\gate[2]{J_{23}} & \qw \\
& \qw &&& \qw
\end{quantikz}

the only thing you have to put up with is the fact that gates are transparent instead of being filled with white. Often the background is white, so it doesn't change much.

1
  • I had already seen the update in arxiv, brilliant solution, and thanks for answering my question explicitly.
    – Rol
    May 30, 2019 at 5:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .