2

I'm looking for a way to draw a permutation gate using Qcircuit in the way it is done in the following picture (e.g. inside the red box):

Quantum Circuit with permutation gates

(How) Can this be achieved using Qcircuit?

Edit: Since I was asked to provide a MWE of what I have achieved so far, this is my source code:

\documentclass{article}
\usepackage{qcircuit}
 \begin{document}
 \mbox{
     \Qcircuit @C=0.5cm @R=.2cm {
         \lstick{x_1} & \multigate{1}{\ } & \rstick{x_1} \qw \\
         \lstick{x_2} & \ghost{\ }        & \rstick{x_2} \qw 
     }
 }
 \end{document}

Which produces what can be seen in the left half of the following picture, however I have no idea at all how to produce the diagonal lines shown in red on the right side:

enter image description here

  • Please tell us what you have achieved so far by providing a minimal working example (MWE). – Pouya Apr 21 '15 at 9:46
  • As you requested, I've added a MWE of what I have achieved so far! – vauge Apr 21 '15 at 10:09
  • Is there a particular reason for using Qcircuit instaed of circuitikz? – John Kormylo Apr 21 '15 at 16:27
  • The circuit I need to draw contains a lot of quantum gates so I thought using Qcircuit would be a good choice. – vauge Apr 22 '15 at 16:03
2

I believe the answer is no, it's not possible. The \multigate command doesn't do much more than draw a rectangle over the appropriate number of rows. I think the diagonal lines you want are outside the scope of Qcircuit altogether-although I don't know xy (which Qcircuit uses) well enough to say for certain.

However such a permutation operation is the same as a sequence of swap gates between different modes. Writing the circuit in this manner has the same effect and arguably makes more sense (in experiment qubits are often fixed in place, so such swap operations are more realistic descriptions of multi-qubit gates between initially spatially separated qubits).

More significantly, Qcircuit allows for such operations which would be the best resolution to your problem (short of moving to a different package). For the operation you highlighted the following image/code is an alternative description, namely permuting 7 -> 6, 6-> 5, 5 -> 4 and 4 -> 7.

Qswap permutation circuit example

Produced with

\documentclass{article}

\usepackage{qcircuit}

\begin{document}

\Qcircuit @C=.7em @R=1em @!R {
\lstick{x_1} & \qw & \qw & \qw & \qw & \qw & \rstick{y_1} \\
\lstick{x_2} & \qw & \qw & \qw & \qw & \qw & \rstick{y_2} \\
\lstick{x_3} & \qw & \qw & \qw & \qw & \qw & \rstick{y_3} \\
\lstick{x_4} & \qw & \qswap & \qswap & \qswap & \qw & \rstick{y_4} \\
\lstick{x_5} & \qw & \qw \qwx & \qw \qwx & \qswap \qwx & \qw & \rstick{y_5} \\
\lstick{x_6} & \qw & \qw \qwx & \qswap \qwx & \qw  & \qw & \rstick{y_6} \\
\lstick{x_7} & \qw & \qswap \qwx & \qw & \qw & \qw & \rstick{y_7} 
}

\end{document}
3

You can get the kind of angled wires you want using the \link command. I often use these to represent swaps. The simplest way to get something like what you're asking for is to use the link command and make a box around the region of interest with the \gategroup command. Here's an example:

enter image description here

This was typeset with the following code:

\documentclass{standalone}
\input{Qcircuit}% using  qcircuit version 2
\begin{document}
\hspace{1em}
\begin{tabular}{c}
\vspace{-.6em}\\
     \Qcircuit @C=0.5cm @R=.5cm {
         \lstick{x_1} & \qw & \link{1}{-1} & \rstick{x_1} \qw \\
         \lstick{x_2} & \qw & \link{-1}{-1} & \rstick{x_2} \qw
         \gategroup{1}{2}{2}{3}{.8em}{-}
     }
\vspace{1.2em}\hspace{1.2em}
\\
\end{tabular}
\end{document}

The wires don't bend at exactly the edge of the box, however. If you want that then you can hack it up using \link, \multigate, and \ghost, but you have to set the default column spacing to zero and force the wire lengths by \pushing a \rule. Here's an example of that:

enter image description here

This was typeset with the following code:

\documentclass{standalone}
\input{Qcircuit}% using  qcircuit version 2
\begin{document}
\hspace{1em}
\begin{tabular}{c}
\vspace{-.6em}\\
     \Qcircuit @C=0cm @R=.2cm {
         \lstick{x_1} & \qw & \qw & \multigate{1}{\ \ \ } & \qw \link{1}{-2} & \qw & \rstick{x_1} \qw \\
         \lstick{x_2} & \qw & \qw & \ghost{\ \ \ } & \qw \link{-1}{-2} & \qw & \rstick{x_2} \qw \\
         & \push{\rule{1.2em}{0em}} & & & & \push{\rule{1.2em}{0em}}
     }
\vspace{.2em}\hspace{1.2em}
\\
\end{tabular}
\end{document}

Alternatively, you could set the slack length on the box (second to last field in \gategroup) in the first example to 0em and extend the box to the preceding and following line, but this will require fiddling with the row spacing to get it to look right (and quite probably \pushing vertical rules).

  • I don't find \link in the manual :-( – pushpen.paul Apr 10 at 8:44
  • True. The manual hasn't been updated since the initial release. Sorry about that. – beastin Apr 11 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.