summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex')
-rw-r--r--Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex133
1 files changed, 119 insertions, 14 deletions
diff --git a/Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex b/Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex
index 446b6407f71..69e8bcd4206 100644
--- a/Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex
+++ b/Master/texmf-dist/doc/latex/qcircuit/Qtutorial.tex
@@ -8,16 +8,16 @@
\begin{document}
\lstset{language=TeX}
-\title{qcircuit 2.0 Tutorial}
+\title{qcircuit 2.5.2 Tutorial}
-\author{Original Authors: Bryan Eastin, Steven T. Flammia\\Edits: Travis L Scholten}
+\author{Original authors: Bryan Eastin, Steve T Flammia\\ Edits: Travis L Scholten}
\affiliation{Department of Physics and Astronomy, University of New
Mexico, Albuquerque, New Mexico 87131-0001, USA}
\begin{abstract}qcircuit is a list of macros that greatly simplifies the construction of
quantum circuit diagrams (QCDs) in \LaTeX \ with the help of the \Xy-pic
package. This tutorial should help the reader acquire
-the skill to render arbitrary QCDs in a matter of minutes. The source code for qcircuit is available for free\footnote{The qcircuit package is distributed under the GNU public license.} at \href{https://github.com/CQuIC-GitHub/qcircuit/tree/master}{https://github.com/CQuIC-GitHub/qcircuit/tree/master}.
+the skill to render arbitrary QCDs in a matter of minutes. The source code for qcircuit is available for free\footnote{The qcircuit package is distributed under the GNU public license.} on the \href{CQuIC GitHub page}{https://github.com/CQuIC/qcircuit}.
\end{abstract}
\maketitle
@@ -105,7 +105,6 @@ We demonstrate the commands below along with their respective outputs:
\end{tabular}
\end{center}
-To enable bras and kets, call qcircuit using the \verb=braket= option. To enable quantum mechanics commands, call the option \verb=qm=.
\section{Simple Quantum Circuits\label{S:basics}}
To begin, suppose the reader would like to typeset the following
@@ -175,7 +174,19 @@ wires at the beginning by inserting the \verb=&= character at the start of each
& \gate{U^\dag} & \qw
} \]\end{verbatim}}
-The only difference between these two codes is that the correct code has an ampersand (\verb=&=) at the start of each new line.
+The only difference between these two codes is that the correct code has an ampersand (\verb=&=) at the start of each new line.\\
+
+To indicate the end of a circuit simply use the \verb=\qwa= command as the last wire.
+
+\[ \Qcircuit @C=1em @R=.7em {
+ & \gate{U} & \qwa \\
+ & \gate{U^\dag} & \qwa
+} \]
+
+{\small \begin{verbatim}\[ \Qcircuit @C=1em @R=.7em {
+ & \gate{U} & \qwa \\
+ & \gate{U^\dag} & \qwa
+} \]\end{verbatim}}
\subsection{CNOT and other controlled single qubit gates \label{S:CNOT}}
@@ -265,6 +276,29 @@ typeset with
\lstick{\ket{1}} & \ctrl{-1} & \rstick{\ket{1}} \qw
}\end{verbatim}}
+There are a few options for labelling multi-qubit input states, as well.
+
+
+\[ \Qcircuit @C=1em @R=1.6em {
+ \lstick{} & \qw & \qw \\
+ \lstick{} & \qw & \qw \inputgroup{1}{2}{.75em}{\ket{0^k}}\\
+ \lstick{} & \qw & \qw \\
+ \lstick{} & \qw & \qw \inputgroupv{3}{4}{.8em}{.8em}{\ket{\psi}}\\
+ \lstick{A} & \qw & \qw \\
+ \lstick{B} & \qw & \qw \inputgrouph{5}{6}{.75em}{\ket{\psi}}{2.2em}
+ }\]
+typeset with
+{\small \begin{verbatim}\Qcircuit @C=1em @R=1.6em {
+ \lstick{} & \qw & \qw \\
+ \lstick{} & \qw & \qw
+ \inputgroup{1}{2}{.75em}{\ket{0^k}}\\
+ \lstick{} & \qw & \qw \\
+ \lstick{} & \qw & \qw
+ \inputgroupv{3}{4}{.8em}{.8em}{\ket{\psi}}\\
+ \lstick{A} & \qw & \qw \\
+ \lstick{B} & \qw & \qw
+ \inputgrouph{5}{6}{.75em}{\ket{\psi}}{2.2em}
+ }\end{verbatim}}
\section{More Complicated Circuits: Multiple Qubit Gates and Beyond}
@@ -316,6 +350,22 @@ with the label for the gate is needed. Strictly speaking, the name of the gate
Note that controls to multiple qubit gates work the same as for single
qubit gates, using \verb=\ctrl= and \verb=\qwx=.
+Sometimes a multi-qubit gate must be applied to qubits which are \emph{not} on adjacent rows (and as such, the \verb=\multigate= command is not suitable). To account for this, the \verb=\sgate= command can be used to ``hook together'' the application of a multi-qubit gate on non-adjacent qubits:
+
+{\scriptsize \begin{verbatim}\\Qcircuit @C=1em @R=.7em {
+ & \multigate{1}{\mathcal{F}} & \sgate{\mathcal{G}}{2} & \qw \\
+ & \ghost{\mathcal{F}} & \qw & \qw\\
+ & \qw & \gate{\mathcal{G}} & \qw \\
+}\end{verbatim}}
+\noindent which yields
+\[ \Qcircuit @C=1em @R=.7em {
+ & \multigate{1}{\mathcal{F}} & \sgate{\mathcal{G}}{2} & \qw \\
+ & \ghost{\mathcal{F}} & \qw & \qw\\
+ & \qw & \gate{\mathcal{G}} & \qw \\
+}\]
+
+Such notation may be a bit confusing, admittedly. An alternative circuit which does use the \verb=\multigate= command would have a step where qubits 2 and 3 above were swapped, then the two-qubit gate $\mathcal{G}$ was applied, and finally the qubits were swapped back.
+
\subsection{Measurements and classical bits}
Measurement gates are typeset just like ordinary gates, but they typically have some sort of decoration to indicate that measurement has occurred. At present, Q-circuit supports the following single qubit measurement gates.
@@ -329,7 +379,11 @@ Measurement gates are typeset just like ordinary gates, but they typically have
\Qcircuit @C=1em @R=.7em {& \measuretab{M_{ijk}}} \hspace{.5em}
& \verb=\measuretab= & \verb=\measuretab{M_{ijk}}=\\
\Qcircuit @C=1em @R=.7em {& \measureD{\chi}}
- & \verb=\measureD= & \verb=\measureD{\chi}=
+ & \verb=\measureD= & \verb=\measureD{\chi}=\\\\
+ \Qcircuit @C=1em @R=1.5em{ &\meterB{\ket{\xi_\pm}}}
+ & \verb=\meterB= & \verb=\meterB{\ket{\xi_\pm}}=\\
+ \Qcircuit @C=1em @R=1.5em{ &\metersymb}
+ & \verb=\metersymb= & \verb=\metersymb=
\end{tabular}
\end{center}}
@@ -346,6 +400,14 @@ Here is an example using measurement gates and classical wires and the correspon
\rstick{\cdots} \cw
}\end{verbatim}}
+If you are using a special basis for your measurements the \verb=\meterB= command allows you to indicate the basis.
+\[\Qcircuit @C=1em @R=1.5em {
+ \lstick{\ket{\psi}} & \meterB{\ket{\xi_\pm}} & \cw
+}\]
+{\small \begin{verbatim}\Qcircuit @C=1em @R=1.5em {
+ \lstick{\ket{\psi}} & \meterB{\ket{\xi_\pm}} & \cw
+}\end{verbatim}}
+
Q-circuit also includes the commands \verb=\multimeasure= and \verb=\multimeasureD= for typesetting measurements on multiple qubits. The syntax for these commands exactly parallels that of the \verb=\multigate= command (see \S\ref{S:multigate}). An example is shown below.
\[\Qcircuit @C=1em @R=.7em {
& \multimeasureD{1}{\text{Bell}} \\
@@ -356,6 +418,19 @@ Q-circuit also includes the commands \verb=\multimeasure= and \verb=\multimeasur
& \ghost{\text{Bell}}
}\end{verbatim}}
+ In addition, if the measurement must be done on qubits which are \emph{not} adjacent, Q-circuit provides for the \verb=\smeterB= command, which, similar to the \verb=\sgate= command, allows one to split the measurement:
+
+ \[ \Qcircuit @C=1em @R=.7em {
+ & \smeterB{\ket{\xi_{\pm}}}{2} & \qw \\
+ & \qw & \qw\\
+ & \gate{\ket{\xi_{\pm}}} & \qw \\
+}\]
+{\small \begin{verbatim} \Qcircuit @C=1em @R=.7em {
+ & \smeterB{\ket{\xi_{\pm}}}{2} & \qw \\
+ & \qw & \qw\\
+ & \gate{\ket{\xi_{\pm}}} & \qw \\
+}\end{verbatim}}
+
\subsection{Non-gate inserts, forcing space, and swap \label{S:inserts}}
In addition to the gates defined by Q-circuit, standard \LaTeX\ can function as a gate if enclosed in curly brackets. By default, inputs are assumed to have zero size, so no space will be made for the resulting object and any wires connecting to it will run straight to the object's middle. Standard \LaTeX\ entries can serve as labels or wire decorations.
@@ -378,20 +453,38 @@ Here is a circuit that shows how to construct swap, decorate wires, and use \ver
& {/} \qw & \gate{H^{\otimes n}} & \qw
}\end{verbatim}}
+To indicate a generalized circuit with $n$ iterations of something, you could use the \verb=\cds= command.
+\[\Qcircuit @C=1em @R=.7em {
+ & \targ & \targ & \cds{4}{\cdots} & \targ & \qw\\
+ & \ctrl{-1} & \qw &\qw & \qw & \qw \\
+ & \qw & \ctrl{-2} & \qw & \qw & \qw \\
+ & & & & & \\
+ & \qw & \qw & \qw & \ctrl{-4} & \qw \\
+}\]
+{\small \begin{verbatim}\Qcircuit @C=1em @R=.3em {
+ & \targ & \targ & \cds{4}{\cdots} & \targ & \qw\\
+ & \ctrl{-1} & \qw &\qw & \qw & \qw \\
+ & \qw & \ctrl{-2} & \qw & \qw & \qw \\
+ & & & & & \\
+ & \qw & \qw & \qw & \ctrl{-4} & \qw \\
+}\end{verbatim}}
+
\subsection{How to control anything}
-Controlled-Z gates, wires with bends, and gates that control-on-zero can all be made using the extended family of control commands. The complete family of control commands is \verb=\ctrl=, \verb=\crtlo=, \verb=\control=, and \verb=\controlo=.
+Controlled-Z gates, wires with bends, and gates that control-on-zero can all be made using the extended family of control commands. The complete family of control commands is \verb=\ctrl=, \verb=\cctrl=, \verb=\ctrlo=, \verb=\cctrlo=, \verb=\control=, and \verb=\controlo=.
\verb=\ctrlo= is identical to the \verb=\ctrl= command (see \S\ref{S:CNOT}) except that it draws an open bullet (indicating control-on-zero). Both commands place a wire to the left and take one argument indicating which wire to connect to.
+The commands \verb=\cctrl= and \verb=\cctrlo= are identical to the \verb=\ctrl= and \verb=\ctrlo= commands, respectively, except they use \emph{classical wires} instead of quantum ones to do the controlling. These commands may be useful for writing circuits where the gates are conditioned on classical outputs.
+
The commands \verb=\control= and \verb=\controlo= are isolated controls; they don't automatically connect to anything. Isolated controls allow you to decide exactly what connections are made to your control operator, which makes them very useful for working with classical wires and rendering things like the controlled-Z.
Here is an example circuit using various controls.
\[ \Qcircuit @C=1em @R=.7em {
& \ctrl{2} & \ctrlo{1} & \ctrl{1} & \qw & \multigate{1}{U} & \qw \\
& \qw & \targ & \ctrlo{2} \qw & \ctrl{1} & \ghost{U} & \qw\\
- & \control \qw & \ctrl{1} & \qw & \meter & \controlo \cw \cwx &\\
- & \qw & \control \qw & \gate{H} & \meter & \control \cw \cwx
+ & \control \qw & \ctrl{1} & \qw & \meter & \cctrlo{-1} &\\
+ & \qw & \control \qw & \gate{H} & \meter & \cctrl{-1}
}\]
{\small \begin{verbatim}\Qcircuit @C=1em @R=.7em {
@@ -400,9 +493,9 @@ Here is an example circuit using various controls.
& \qw & \targ & \ctrlo{2} \qw
& \ctrl{1} & \ghost{U} & \qw \\
& \control \qw & \ctrl{1} & \qw
- & \meter & \controlo \cw \cwx \\
+ & \meter & \cctrlo{-1} \\
& \qw & \control \qw & \gate{H}
- & \meter & \control \cw \cwx
+ & \meter & \cctrl{-1}
}\end{verbatim}}
Note that we, the authors, have used a pair of controls connected by a wire to denote the controlled-Z gate. This isn't standard notation, but we feel it is a logically consistent and concise notation, and it illustrates nicely the symmetry of the controlled-Z gate. We hope to encourage the readers to adopt this notation in their own QCDs.
@@ -579,25 +672,33 @@ The following table is grouped according to the effect of each command.\\
@!R \\
@!C \\
@! \\
- \char92 push\{\#1\}} \\
+ \char92 push\{\#1\} \\
+ \char92 cds\{\#1\}\{\#2\}}\\
Wires & \parbox[t]{6cm}{\tt
\char92 qw[\#1] \\
\char92 qwx[\#1] \\
+ \char92 qwa[\#1] \\
\char92 cw[\#1] \\
+ \char92 cwa[\#1] \\
\char92 cwx[\#1] }\\
Gates & \parbox[t]{6cm}{\tt
\char92 gate\{\#1\} \\
\char92 targ \\
\char92 qswap \\
\char92 multigate\{\#1\}\{\#2\} \\
+ \char92 sgate\{\#1\}\{\#2\}\\
\char92 ghost\{\#1\} }\\
Controls & \parbox[t]{6cm}{\tt
\char92 ctrl\{\#1\} \\
\char92 ctrlo\{\#1\} \\
+ \char92 cctrl\{\#1\} \\
+ \char92 cctrlo\{\#1\} \\
\char92 control \\
\char92 controlo } \\
Measurements & \parbox[t]{6cm}{\tt
\char92 meter \\
+ \char92 meterB\{\#1\} \\
+ \char92 smeterB\{\#1\}\{\#2\} \\
\char92 measure\{\#1\} \\
\char92 measureD\{\#1\} \\
\char92 measuretab\{\#1\} \\
@@ -610,8 +711,12 @@ The following table is grouped according to the effect of each command.\\
\char92 dstick\{\#1\} \\
\char92 bra\{\#1\} \\
\char92 ket\{\#1\} \\
- \char92 gategroup\{\#1\}\{\#2\}\{\#3\}\{\#4\}\{\#5\}\{\#6\} }
+ \char92 gategroup\{\#1\}\{\#2\}\{\#3\}\{\#4\}\{\#5\}\{\#6\}\\
+ \char92 inputgroup\{\#1\}\{\#2\}\{\#3\}\{\#4\}\\
+ \char92 inputgroupv\{\#1\}\{\#2\}\{\#3\}\{\#4\}\{\#5\}\\
+ \char92 inputgrouph\{\#1\}\{\#2\}\{\#3\}\{\#4\}\{\#5\}\\
+ }
\end{tabular}
\end{center}}
-\end{document} \ No newline at end of file
+\end{document}