Skip to content

Commit 64fc90e

Browse files
authored
Create Qcircuit.sty
1 parent cde5d4c commit 64fc90e

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

Qcircuit.sty

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
% qcircuit version 2.5.3
2+
% Contributors: Steve Flammia, Bryan Eastin, Travis Scholten
3+
% This program is free software; you can redistribute it and/or modify
4+
% it under the terms of the GNU General Public License as published by
5+
% the Free Software Foundation; either version 2 of the License, or
6+
% (at your option) any later version.
7+
%
8+
% This program is distributed in the hope that it will be useful,
9+
% but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
% GNU General Public License for more details.
12+
%
13+
% You should have received a copy of the GNU General Public License
14+
% along with this program; if not, write to the Free Software
15+
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16+
17+
% Thanks to the Xy-pic guys, Kristoffer H Rose, Ross Moore, and Daniel Müllner,
18+
% for their help in making Qcircuit work with Xy-pic version 3.8.
19+
% Thanks also to Dave Clader, Andrew Childs, Rafael Possignolo, Tyson Williams,
20+
% Sergio Boixo, Cris Moore, Jonas Anderson, and Stephan Mertens for helping us test
21+
% and/or develop the new version.
22+
\ProvidesPackage{qcircuit}[2016/12/29]
23+
\RequirePackage{xy}
24+
25+
\DeclareOption{braket}{
26+
\newcommand{\bra}[1]{\ensuremath{\left\langle{#1}\right\vert}}
27+
\newcommand{\ket}[1]{\ensuremath{\left\vert{#1}\right\rangle}}
28+
}
29+
30+
\DeclareOption{qm}{
31+
\newcommand{\ip}[2]{\ensuremath{\left\langle{#1}\middle\vert{#2}\right\rangle}}
32+
\newcommand{\melem}[3]{\ensuremath{\left\langle{#1}\middle\vert{#2}\middle\vert{#3}\right\rangle}}
33+
\newcommand{\expval}[1]{\ensuremath{\left\langle #1 \right\rangle}}
34+
\newcommand{\op}[2]{\ensuremath{\left\vert{#1}\middle\rangle\middle\langle{#2}\right\vert}}
35+
}
36+
37+
\ProcessOptions\relax
38+
39+
\xyoption{matrix}
40+
\xyoption{frame}
41+
\xyoption{arrow}
42+
\xyoption{arc}
43+
44+
\usepackage{ifpdf}
45+
\ifpdf
46+
\else
47+
\PackageWarningNoLine{Qcircuit}{qcircuit is not loading in PDF mode. Activating all Xy-pic features to compensate. If you wish to use specific drivers for Xy-pic, you must modify the code in qcircuit.sty}
48+
% The following option loads all the features in Xy-pic. This
49+
% this is included as work-around to ensure documents compile
50+
% images correctly when using XeLaTeX.
51+
\xyoption{all}
52+
\fi
53+
54+
% The following resets Xy-pic matrix alignment to the pre-3.8 default, as
55+
% required by Qcircuit.
56+
\entrymodifiers={!C\entrybox}
57+
58+
\newcommand{\qw}[1][-1]{\ar @{-} [0,#1]}
59+
% Defines a wire that connects horizontally. By default it connects to the object on the left of the current object.
60+
% WARNING: Wire commands must appear after the gate in any given entry.
61+
\newcommand{\qwx}[1][-1]{\ar @{-} [#1,0]}
62+
% Defines a wire that connects vertically. By default it connects to the object above the current object.
63+
% WARNING: Wire commands must appear after the gate in any given entry.
64+
\newcommand{\qwa}[1][-1]{\ar @{<-} [0,#1]}
65+
% Defines a wire that connects horizontally with an arrow. By default it makes an end wire with an arrow indicating the end of the circuit.
66+
% WARNING: Wire commands must appear after the gate in any given entry.
67+
\newcommand{\cw}[1][-1]{\ar @{=} [0,#1]}
68+
% Defines a classical wire that connects horizontally. By default it connects to the object on the left of the current object.
69+
% WARNING: Wire commands must appear after the gate in any given entry.
70+
\newcommand{\cwx}[1][-1]{\ar @{=} [#1,0]}
71+
% Defines a classical wire that connects vertically. By default it connects to the object above the current object.
72+
% WARNING: Wire commands must appear after the gate in any given entry.
73+
\newcommand{\cwa}[1][-1]{\ar @{<=} [0,#1]}
74+
% Defines a classical wire that connects horizontally with an arrow. By default it makes an end wire with an arrow indicating the end of the circuit.
75+
% WARNING: Wire commands must appear after the gate in any given entry.
76+
\newcommand{\cds}[2]{*+<1em,.9em>{\hphantom{#2}} \POS [0,0].[#1,0]="e",!C *{#2};"e"+ R \qw}
77+
% Allows the insertion of text without a box and exands circuit around this text.
78+
% This is useful for such things as ... to indicate a generalized circuit.
79+
\newcommand{\gate}[1]{*+<.6em>{#1} \POS ="i","i"+UR;"i"+UL **\dir{-};"i"+DL **\dir{-};"i"+DR **\dir{-};"i"+UR **\dir{-},"i" \qw}
80+
% Boxes the argument, making a gate.
81+
\newcommand{\sgate}[2]{\gate{#1} \qwx[#2]}
82+
% Creates a gate and a qwx wire going #2 spots below, for a gate split over
83+
% non-adjacent rows
84+
\newcommand{\meter}{*=<1.8em,1.4em>{\xy ="j","j"-<.778em,.322em>;{"j"+<.778em,-.322em> \ellipse ur,_{}},"j"-<0em,.4em>;p+<.5em,.9em> **\dir{-},"j"+<2.2em,2.2em>*{},"j"-<2.2em,2.2em>*{} \endxy} \POS ="i","i"+UR;"i"+UL **\dir{-};"i"+DL **\dir{-};"i"+DR **\dir{-};"i"+UR **\dir{-},"i" \qw}
85+
% Inserts a measurement meter.
86+
% In case you're wondering, the constants .778em and .322em specify
87+
% one quarter of a circle with radius 1.1em.
88+
% The points added at + and - <2.2em,2.2em> are there to strech the
89+
% canvas, ensuring that the size is unaffected by erratic spacing issues
90+
% with the arc.
91+
\newcommand{\metersymb}{\xy ="j","j"-<.778em,.322em>;{"j"+<.778em,-.322em> \ellipse ur,_{}},"j"-<0em,.4em>;p+<.5em,.9em> **\dir{-},"j"+<2.2em,2.2em>*{},"j"-<2.2em,2.2em>*{} \endxy}
92+
% A longer meter
93+
\newcommand{\meterB}[1]{*=<1.8em,2.6em>{\xy 0;<0em,-.8em>:
94+
0*{\begingroup
95+
\everymath{\scriptstyle}
96+
\tiny #1 \endgroup},<0em,.7em>*{\xy ="j","j"-<.778em,-.322em>;{"j"+<.778em,.322em> \ellipse ur,_{}},"j"-<0em,-.2em>;p+<.5em,.9em> **\dir{-},"j"+<2.2em,2.2em>*{},"j"-<2.2em,2.2em>*{} \endxy}
97+
\endxy} \POS ="i","i"+UR;"i"+UL **\dir{-};"i"+DL **\dir{-};"i"+DR **\dir{-};"i"+UR **\dir{-},"i" \qw}
98+
% A meter that allows for a measurement operator to be added below
99+
\newcommand{\smeterB}[2]{\meterB{#1} \qwx[#2] \qw}
100+
% A split meter that allows for a measurement operator to be split over non-
101+
% adjacent rows
102+
\newcommand{\measure}[1]{*+[F-:<.9em>]{#1} \qw}
103+
% Inserts a measurement bubble with user defined text.
104+
\newcommand{\measuretab}[1]{*{\xy*+<.6em>{#1}="e";"e"+UL;"e"+UR **\dir{-};"e"+DR **\dir{-};"e"+DL **\dir{-};"e"+LC-<.5em,0em> **\dir{-};"e"+UL **\dir{-} \endxy} \qw}
105+
% Inserts a measurement tab with user defined text.
106+
\newcommand{\measureD}[1]{*{\xy*+=<0em,.1em>{#1}="e";"e"+UR+<0em,.25em>;"e"+UL+<-.5em,.25em> **\dir{-};"e"+DL+<-.5em,-.25em> **\dir{-};"e"+DR+<0em,-.25em> **\dir{-};{"e"+UR+<0em,.25em>\ellipse^{}};"e"+C:,+(0,1)*{} \endxy} \qw}
107+
% Inserts a D-shaped measurement gate with user defined text.
108+
\newcommand{\multimeasure}[2]{*+<1em,.9em>{\hphantom{#2}} \qw \POS[0,0].[#1,0];p !C *{#2},p \drop\frm<.9em>{-}}
109+
% Draws a multiple qubit measurement bubble starting at the current position and spanning #1 additional gates below.
110+
% #2 gives the label for the gate.
111+
% You must use an argument of the same width as #2 in \ghost for the wires to connect properly on the lower lines.
112+
\newcommand{\multimeasureD}[2]{*+<1em,.9em>{\hphantom{#2}} \POS [0,0]="i",[0,0].[#1,0]="e",!C *{#2},"e"+UR-<.8em,0em>;"e"+UL **\dir{-};"e"+DL **\dir{-};"e"+DR+<-.8em,0em> **\dir{-};{"e"+DR+<0em,.8em>\ellipse^{}};"e"+UR+<0em,-.8em> **\dir{-};{"e"+UR-<.8em,0em>\ellipse^{}},"i" \qw}
113+
% Draws a multiple qubit D-shaped measurement gate starting at the current position and spanning #1 additional gates below.
114+
% #2 gives the label for the gate.
115+
% You must use an argument of the same width as #2 in \ghost for the wires to connect properly on the lower lines.
116+
\newcommand{\control}{*!<0em,.025em>-=-<.2em>{\bullet}}
117+
% Inserts an unconnected control.
118+
\newcommand{\controlo}{*+<.01em>{\xy -<.095em>*\xycircle<.19em>{} \endxy}}
119+
% Inserts a unconnected control-on-0.
120+
\newcommand{\ctrl}[1]{\control \qwx[#1] \qw}
121+
% Inserts a control and connects it to the object #1 wires below.
122+
\newcommand{\ctrlo}[1]{\controlo \qwx[#1] \qw}
123+
% Inserts a control-on-0 and connects it to the object #1 wires below.
124+
\newcommand{\cctrl}[1]{\control \cwx[#1] \cw}
125+
% Inserts a classical control and connects it to the object #1 wires below.
126+
\newcommand{\cctrlo}[1]{\controlo \cwx[#1] \cw}
127+
% Inserts a classical control-on-0 and connects it to the object #1 wires below.
128+
\newcommand{\targ}{*+<.02em,.02em>{\xy ="i","i"-<.39em,0em>;"i"+<.39em,0em> **\dir{-}, "i"-<0em,.39em>;"i"+<0em,.39em> **\dir{-},"i"*\xycircle<.4em>{} \endxy} \qw}
129+
% Inserts a CNOT target.
130+
\newcommand{\qswap}{*=<0em>{\times} \qw}
131+
% Inserts half a swap gate.
132+
% Must be connected to the other swap with \qwx.
133+
\newcommand{\multigate}[2]{*+<1em,.9em>{\hphantom{#2}} \POS [0,0]="i",[0,0].[#1,0]="e",!C *{#2},"e"+UR;"e"+UL **\dir{-};"e"+DL **\dir{-};"e"+DR **\dir{-};"e"+UR **\dir{-},"i" \qw}
134+
% Draws a multiple qubit gate starting at the current position and spanning #1 additional gates below.
135+
% #2 gives the label for the gate.
136+
% You must use an argument of the same width as #2 in \ghost for the wires to connect properly on the lower lines.
137+
\newcommand{\ghost}[1]{*+<1em,.9em>{\hphantom{#1}} \qw}
138+
% Leaves space for \multigate on wires other than the one on which \multigate appears. Without this command wires will cross your gate.
139+
% #1 should match the second argument in the corresponding \multigate.
140+
\newcommand{\push}[1]{*{#1}}
141+
% Inserts #1, overriding the default that causes entries to have zero size. This command takes the place of a gate.
142+
% Like a gate, it must precede any wire commands.
143+
% \push is useful for forcing columns apart.
144+
% NOTE: It might be useful to know that a gate is about 1.3 times the height of its contents. I.e. \gate{M} is 1.3em tall.
145+
% WARNING: \push must appear before any wire commands and may not appear in an entry with a gate or label.
146+
\newcommand{\gategroup}[6]{\POS"#1,#2"."#3,#2"."#1,#4"."#3,#4"!C*+<#5>\frm{#6}}
147+
% Constructs a box or bracket enclosing the square block spanning rows #1-#3 and columns=#2-#4.
148+
% The block is given a margin #5/2, so #5 should be a valid length.
149+
% #6 can take the following arguments -- or . or _\} or ^\} or \{ or \} or _) or ^) or ( or ) where the first two options yield dashed and
150+
% dotted boxes respectively, and the last eight options yield bottom, top, left, and right braces of the curly or normal variety. See the Xy-pic reference manual for more options.
151+
% \gategroup can appear at the end of any gate entry, but it's good form to pick either the last entry or one of the corner gates.
152+
% BUG: \gategroup uses the four corner gates to determine the size of the bounding box. Other gates may stick out of that box. See \prop.
153+
\newcommand{\inputgroupv}[5]{\POS"#1,1"."#2,1"."#1,1"."#2,1"!C*+<#3>\frm{\{}, \POS"#1,1"."#2,1"."#1,1"."#2,1"*!C!<1.7em,#4>=<0em>{#5}}
154+
% Constructs an input group with label #5 and a grouping { from rows #1 to #2 with #3 and #4 controlling the spacing
155+
\newcommand{\inputgroup}[4]{\POS"#1,1"."#2,1"."#1,1"."#2,1", \POS"#1,1"."#2,1"."#1,1"."#2,1"*!C!<1em,#3>=<0em>{#4}}
156+
% Constructs an input group with label #4 from rows #1 to #2 with #3 controlling the spacing
157+
\newcommand{\inputgrouph}[5]{\POS"#1,1"."#2,1"."#1,1"."#2,1", \POS"#1,1"."#2,1"."#1,1"."#2,1"*!C!<#5,#3>=<0em>{#4}}
158+
% Constructs an input group with label #4 and a grouping /vdots from rows #1 to #2 with #3 and #5 controlling the spacing
159+
\newcommand{\rstick}[1]{*!L!<-.5em,0em>=<0em>{#1}}
160+
% Centers the left side of #1 in the cell. Intended for lining up wire labels. Note that non-gates have default size zero.
161+
\newcommand{\lstick}[1]{*!R!<.5em,0em>=<0em>{#1}}
162+
% Centers the right side of #1 in the cell. Intended for lining up wire labels. Note that non-gates have default size zero.
163+
\newcommand{\ustick}[1]{*!D!<0em,-.5em>=<0em>{#1}}
164+
% Centers the bottom of #1 in the cell. Intended for lining up wire labels. Note that non-gates have default size zero.
165+
\newcommand{\dstick}[1]{*!U!<0em,.5em>=<0em>{#1}}
166+
% Centers the top of #1 in the cell. Intended for lining up wire labels. Note that non-gates have default size zero.
167+
\newcommand{\Qcircuit}{\xymatrix @*=<0em>}
168+
% Defines \Qcircuit as an \xymatrix with entries of default size 0em.
169+
\newcommand{\link}[2]{\ar @{-} [#1,#2]}
170+
% Draws a wire or connecting line to the element #1 rows down and #2 columns forward.
171+
\newcommand{\pureghost}[1]{*+<1em,.9em>{\hphantom{#1}}}
172+
% Same as \ghost except it omits the wire leading to the left.
173+
174+
\endinput

0 commit comments

Comments
 (0)