[
  {
    "path": ".gitignore",
    "content": "*.bbl\n*.blg\n*.log\n*.aux\n*.out\n*.synctex.gz\n*.tar.gz\n"
  },
  {
    "path": "LICENSE",
    "content": "GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>\n 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Lesser General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n                            NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    {description}\n    Copyright (C) {year}  {fullname}\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License along\n    with this program; if not, write to the Free Software Foundation, Inc.,\n    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  {signature of Ty Coon}, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License."
  },
  {
    "path": "QcircuitDemo.tex",
    "content": "% Qcircuit demonstration graphic\r\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\r\n\r\n\\documentclass{amsart}\r\n\r\n\\usepackage[matrix,frame,arrow]{xypic}\r\n\\usepackage[braket]{qcircuit}\r\n\r\n\\vfuzz2pt % Don't report over-full v-boxes if over-edge is small\r\n\r\n%%% ----------------------------------------------------------------------\r\n\\begin{document}\r\n\\[\r\n\\Qcircuit @C=1.0em @R=.7em {\r\n& \\gate{H} & \\ctrlo{3} & \\qw & \\qw & \\qw & \\ctrl{5} & \\qw & \\gate{H} & \\multigate{2}{U^\\dag} & \\qw\\\\\r\n\\lstick{\\begin{array}{r}\\alpha\\ket{000}\\ \\ \\ \\\\+\\beta\\ket{111}\\end{array}} \r\n& \\gate{H} & \\qw & \\qswap \\qwx[2] & \\ctrl{3} & \\qw & \\qw & \\qw & \\gate{H} & \\ghost{U^\\dag} \\qw & \\qw\\\\\r\n& \\gate{H} & \\qw & \\qw & \\qw & \\ctrl{2} & \\qw & \\ctrl{3} & \\gate{H} & \\ghost{U^\\dag} \\qw & \\qw\\\\\r\n& \\lstick{\\ket{0}} & \\targ & \\qswap \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\measure{answer} \\cwx\\\\\r\n& \\lstick{\\ket{1}} & \\qw & \\qw & \\control \\qw & \\targ & \\qw & \\qw & \\qw & \\meter\\\\\r\n& \\lstick{\\ket{0}} & \\qw & \\qw & \\qw \\gategroup{6}{3}{6}{5}{1.0em}{_\\}} & \\qw & \\targ & \\gate{Y} & \\qw & \\measuretab{M_{abc}} \\gategroup{1}{9}{6}{10}{1em}{--} & \\control \\cw \\cwx[3] \\\\ \r\n& & & & & & \\vdots \\\\\r\n\\\\\r\n& \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\multigate{2}{\\mathcal{F}} & \\qw\\\\\r\n& \\qw & \\qw & \\qw & {\\backslash} \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\ghost{\\mathcal{F}} \\qw & \\qw\\\\\r\n& \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\qw & \\ghost{\\mathcal{F}} \\qw & \\qw\r\n}\r\n\\]\r\n\\end{document}\r\n% ------------------------------------------------------------------------\r\n"
  },
  {
    "path": "Qtutorial.tex",
    "content": "\\documentclass[twocolumn,nofootinbib]{revtex4}\n\\usepackage[bookmarks = true, pdfpagemode = None, pdfstartview = FitH, colorlinks = true, urlcolor = blue]{hyperref}\n\\usepackage[braket, qm]{qcircuit}\n\\usepackage{amsmath}  \n\\usepackage{listings}\n\\renewcommand{\\arraystretch}{1.5}\n\n\\begin{document}\n\\lstset{language=TeX}\n\n\\title{qcircuit 2.7.0 Tutorial}\n\n\\author{Original authors: Bryan Eastin, Steve T Flammia\\\\ Edits: Travis L Scholten}\n\\affiliation{Department of Physics and Astronomy, University of New\nMexico, Albuquerque, New Mexico 87131-0001, USA}\n\t\n\\begin{abstract}qcircuit is a list of macros that greatly simplifies the construction of \nquantum circuit diagrams (QCDs) in \\LaTeX \\ with the help of the \\Xy-pic \npackage.  This tutorial should help the reader acquire \nthe 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}.\n\\end{abstract}\n\n\\maketitle\n\n\\section{Introduction}\n\\setcounter{footnote}{1}\nEver tried to use \\LaTeX\\ to typeset something like this?\n\\[\n\\Qcircuit @C=.5em @R=0em @!R {\n& \\ctrl{1} & \\qw & & & \\qw & \\ctrl{1} & \\qw & \\ctrl{1} & \\ctrl{2} & \\qw\\\\\n& \\ctrl{1} & \\qw & \\push{\\rule{.3em}{0em}=\\rule{.3em}{0em}} & & \\ctrl{1} & \\targ & \\ctrl{1} & \\targ & \\qw & \\qw\\\\\n& \\gate{U} & \\qw & & & \\gate{V} & \\qw & \\gate{V^\\dag} & \\qw & \\gate{V} & \\qw\n}\n\\]\n\\noindent Or maybe this?\n\\[\n\\Qcircuit @C=.7em @R=.4em @! {\n\\lstick{\\ket{\\psi}} & \\qw & \\qw & \\ctrl{1} & \\gate{H} & \\meter & \\control \\cw\\\\\n\\lstick{\\ket{0}} & \\qw & \\targ & \\targ & \\qw & \\meter & \\cwx\\\\\n\\lstick{\\ket{0}} & \\gate{H} & \\ctrl{-1} & \\qw & \\qw & \\gate{X} \\cwx & \\gate{Z} \\cwx & \\rstick{\\ket{\\psi}} \\qw\n}\n\\]\n\\noindent Or how about\\footnote{Code for these circuits is given in Appendix \\ref{S:code}.}\n\\[\n\\Qcircuit @C=1.3em @R=.6em {\n  & & & & & & \\mbox{Syndrome Measurement} & & & &\n    \\mbox{Recovery}\\\\\n  & \\qw & \\qw & \\ctrl{3} & \\qw & \\qw & \\qw &\n    \\ctrl{5} & \\qw & \\qw &\n    \\multigate{2}{\\ \\mathcal{R}\\ } & \\qw\\\\\n  & \\qw & \\qw & \\qw & \\ctrl{2} & \\ctrl{3} & \\qw &\n    \\qw & \\qw & \\qw & \\ghost{\\ \\mathcal{R}\\ } \\qw &\n    \\qw\\\\\n  & \\qw & \\qw & \\qw & \\qw & \\qw & \\ctrl{2} & \\qw &\n    \\ctrl{3} & \\qw & \\ghost{\\ \\mathcal{R}\\ } \\qw &\n    \\qw\\\\\n  & & \\lstick{\\ket{0}} & \\targ \\qw & \\targ \\qw &\n    \\qw & \\qw & \\qw & \\qw & \\measure{M_a} &\n    \\control \\cw \\cwx\\\\\n  & & \\lstick{\\ket{0}} & \\qw & \\qw & \\targ \\qw &\n    \\targ \\qw & \\qw & \\qw & \\measure{M_b} &\n    \\control \\cw \\cwx\\\\\n  & & \\lstick{\\ket{0}} & \\qw & \\qw & \\qw & \\qw &\n    \\targ \\qw & \\targ \\qw & \\measure{M_c}\n    \\gategroup{2}{2}{7}{10}{.8em}{--} &\n    \\control \\cw \\cwx\n}\n\\]\n\nTypesetting quantum circuit diagrams using standard \\LaTeX\\ graphics packages is a difficult and time consuming business.  qcircuit is a high level macro package designed to change that.  With qcircuit, drawing quantum circuit diagrams is as easy as constructing an array.  In a matter of minutes you can learn the basic syntax and start producing circuits of your own.\n\nThis tutorial teaches you to use qcircuit from the ground up.  Many readers will find that they've learned everything they need to know by the end of \\S\\ref{S:basics}, but plenty of material is included for those that wish to typeset more complicated circuits.\n\n\\section{Getting Started}\n\nTo install qcircuit, place the file \\verb=qcircuit.sty= somewhere your \\TeX\\ distribution can find it and run the appropriate command to update your \\TeX\\ tree.  To use it, place the command\n{\\small \\begin{verbatim}\\usepackage[options]{qcircuit}\\end{verbatim}}\n\\noindent in the preamble of your document.  \\verb=qcircuit.sty= loads the \\verb=amsmath= and \\verb=xy= packages and implements a set of circuit commands.  If need be, you can obtain the necessary packages at \\href{http://www.ctan.org/}{http://www.ctan.org/}.\n\nqcircuit comes with two options - \\verb=braket= and \\verb=qm= - which provide defined commands for bras, kets, inner and outer products, matrix elements, and expectation values. By default, these options are not enabled, allowing you to define your own commands if you wish. \n\n\\section{Special Commands}\nAs mentioned above, qcircuit comes with predefined commands for some commonly used functions. We have chosen to use the \\verb=ensuremath= command, meaning you do not need to put dollar signs around the calls to these commands.\n\nWe demonstrate the commands below along with their respective outputs:\n\n\\begin{center}\n\\begin{tabular}{l c l c}\n\\begin{lstlisting}\n\\ket{A}\n\\end{lstlisting} & \\ket{A} & \\begin{lstlisting}\n\\bra{B}\n\\end{lstlisting} & \\bra{B}\\\\\n\\begin{lstlisting}\n\\ip{A}{B}\n\\end{lstlisting} & \\ip{A}{B} & \\begin{lstlisting}\n\\op{A}{B}\n\\end{lstlisting} & \\op{A}{B}\\\\\n\\begin{lstlisting}\n\\melem{j}{B}{k}\n\\end{lstlisting} & \\melem{j}{B}{k} &\n\\begin{lstlisting}\n\\expval{B}\n\\end{lstlisting} & \\expval{B}\\\\\n\\end{tabular}\n\\end{center}\n\n\\section{Simple Quantum Circuits\\label{S:basics}}\n\nTo begin, suppose the reader would like to typeset the following \nsimple circuit:\n\\[ \\Qcircuit @C=1em @R=.7em {\n      & \\gate{X} & \\qw\n}\\]\n\nThis was typeset using\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n      & \\gate{X} & \\qw\n}\\end{verbatim}}\n\nThe command \\verb=\\Qcircuit= is simply a disguised \\verb=\\xymatrix= command \nwith a default parameter set.  For readers unfamiliar with the \\verb=xymatrix= environment, it suffices \nto know that it behaves more or less like the \\verb=array= environment. \nThat is, new columns are denoted by \\verb=&= and new rows by \\verb=\\\\=, \nas in the following example:\n\\[ \\Qcircuit @C=1.4em @R=1.2em {\n     a & i \\\\\n     1 & x\n} \\]\nwhich was typeset using\n{\\small \\begin{verbatim}\\Qcircuit @C=1.4em @R=1.2em {\n     a & i \\\\\n     1 & x\n} \\end{verbatim}}\nThe parameters \\verb?@C=1.4em? and \\verb?@R=1.2em? that appear after \\verb=\\Qcircuit= specify the spacing between the columns and the rows of the circuit, respectively.  They may take any length as an argument.  Additional parameters are discussed in \\S\\ref{S:spaces}.\n\n\\subsection{Wires and gates}\n\nThe command \\verb=\\qw= draws a wire between two columns of \na QCD. The command derives its name from an abbreviation of `quantum wire'.  \n\\[ \\Qcircuit @C=1em @R=.7em {\n   & \\gate{H} & \\gate{Z} & \\gate{H} & \\qw \\\\\n   & \\qw & \\gate{X} & \\qw & \\qw\n} \\]\n\nThe diagram above was drawn using \n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n   & \\gate{H} & \\gate{Z} & \\gate{H} & \\qw \\\\\n   & \\qw & \\gate{X} & \\qw & \\qw\n}\\end{verbatim}}\n\\noindent Note that \\verb=\\qw= is used to connect a wire {\\it towards the left}.\n\nThe \\verb=\\gate= command draws the argument of the function inside a \nframed box and extends a wire {\\it back to the previous column}.  When using the \n\\verb=\\gate= and \\verb=\\qw= commands, make sure there is another column \nentry to the left of the current column entry in your QCD, otherwise the wire will not \nconnect to anything (and you'll get an error), as in the following example code:\n\n{\\small \\begin{verbatim} (**Wrong!**)\n\\Qcircuit @C=1em @R=.7em {\n     \\gate{U} & \\qw \\\\\n     \\gate{U^\\dag} & \\qw\n} \\end{verbatim}}\n\nThe proper way to render this circuit would be to include space for the incoming\nwires at the beginning by inserting the \\verb=&= character at the start of each new line:\n\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\gate{U} & \\qw \\\\\n     & \\gate{U^\\dag} & \\qw\n} \\]\n\n{\\small \\begin{verbatim}\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\gate{U} & \\qw \\\\\n     & \\gate{U^\\dag} & \\qw\n} \\]\\end{verbatim}}\n\nThe only difference between these two codes is that the correct code has an ampersand (\\verb=&=) at the start of each new line.\\\\\n\nTo indicate the end of a circuit simply use the \\verb=\\qwa= command as the last wire.\n\n\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\gate{U} & \\qwa \\\\\n     & \\gate{U^\\dag} & \\qwa\n} \\]\n\n{\\small \\begin{verbatim}\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\gate{U} & \\qwa \\\\\n     & \\gate{U^\\dag} & \\qwa\n} \\]\\end{verbatim}}\n\n\\subsection{CNOT and other controlled single qubit gates \\label{S:CNOT}}\n\nWith just these few commands, one can already render a circuit with an arbitrary number of wires and single qubit gates.  In this section, we'll learn how to draw CNOT \ngates and controlled single qubit gates with an arbitrary number \nof controls.  \n\nA simple circuit with two CNOT gates in it is\n\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\ctrl{1} & \\targ & \\qw \\\\\n     & \\targ & \\ctrl{-1} & \\qw\n}\\]\nwhich was typeset by\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n     & \\ctrl{1} & \\targ & \\qw \\\\\n     & \\targ & \\ctrl{-1} & \\qw\n}\\end{verbatim}}\nIn this circuit, the command \\verb=\\targ= draws the target gate on the \nwire, and the \\verb=\\ctrl{#1}= puts a bullet down, and connects to the \ntarget which is \\verb=#1= array elements \\textit{below} the control.\nHence, to connect the second CNOT gate properly, we used -1.\n\nA more complicated circuit with multiple controls and arbitrary gates\nmight look like\n\\[ \\Qcircuit @C=1em @R=.7em {\n   & \\ctrl{2} & \\targ & \\gate{U} & \\qw \\\\\n   & \\qw & \\ctrl{-1} & \\qw & \\qw \\\\\n   & \\targ & \\ctrl{-1} & \\ctrl{-2} & \\qw \\\\\n   & \\qw & \\ctrl{-1} & \\qw & \\qw \n}\\]\nwhich was drawn using\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n   & \\ctrl{2} & \\targ & \\gate{U} & \\qw \\\\\n   & \\qw & \\ctrl{-1} & \\qw & \\qw \\\\\n   & \\targ & \\ctrl{-1} & \\ctrl{-2} & \\qw \\\\\n   & \\qw & \\ctrl{-1} & \\qw & \\qw \n}\\end{verbatim}}\n\nIn the first gate, the control bit connects to the \ntarget on wire 3.  In the second gate, each control connects to the object \ndirectly above it.  Finally, the third gate is an example of how to do \ncontrols on arbitrary gates; simply place the desired gate where you would\nnormally put a target.\n\n\\subsection{Vertical wires}\n\nSuppose we want to typeset the following circuit:\n\\[ \\Qcircuit @C=1em @R=1.2em {\n     & \\gate{U_1} & \\qw \\\\\n     & \\ctrl{1} \\qwx & \\qw \\\\\n     & \\gate{U_2} & \\qw \\\\\n}\\]\nso that the middle control has to connect to more than one gate.  The way\nto accomplish this is with the \\verb=\\qwx= command.  The command\n\\verb=\\qwx[#1]= takes an optional input, \\verb=#1=, and connects from \nthe current position to a position \\verb=#1= entries {\\it below}\nthe current position.  The default argument is -1.  Thus, one way to\ntypeset the above diagram is with the following code:\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=1.2em {\n     & \\gate{U_1} & \\qw \\\\\n     & \\ctrl{-1} \\qwx[1] & \\qw \\\\\n     & \\gate{U_2} & \\qw \\\\\n}\\end{verbatim}}\n\\noindent or, equivalently,\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=1.2em {\n     & \\gate{U_1} & \\qw \\\\\n     & \\ctrl{1} \\qwx & \\qw \\\\\n     & \\gate{U_2} & \\qw \\\\\n}\\end{verbatim}}\n\\noindent which is what the author used.\n\nNote that wire commands must not precede the gate command in an entry.\nAlso, remember that commands taking an optional \nargument use {\\it square} braces rather than curly braces.\n\n\\subsection{Labelling input and output states \\label{S:labels}}\nThe last element we need for simple circuits is the ability to add labels.  We'll look at input and output labels here, other kinds of labels are discussed in \\S\\ref{S:labels2}.\n\nWhen labelling input and output qubits, one should use the \\verb=\\lstick= and \\verb=\\rstick= commands.  These commands ensure that the labels and the wires connecting to them line up correctly.  The \\verb=\\lstick= command is used for input labels (on the left of the diagram), and the \\verb=\\rstick= command is used for output labels (on the right of the diagram).  Placement rules are the same as those for gates with the exception that \\verb=\\lstick= and \\verb=\\rstick= can be inserted in the leftmost column of the array.  Here is an example circuit:\n\\[ \\Qcircuit @C=1em @R=1em {\n\\lstick{\\ket{1}} & \\targ &  \\rstick{\\ket{0}} \\qw \\\\\n\\lstick{\\ket{1}} & \\ctrl{-1} & \\rstick{\\ket{1}} \\qw\n}\\]\ntypeset with\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=1em {\n \\lstick{\\ket{1}} & \\targ & \\rstick{\\ket{0}} \\qw \\\\\n \\lstick{\\ket{1}} & \\ctrl{-1} & \\rstick{\\ket{1}} \\qw\n}\\end{verbatim}}\n\nThere are a few options for labelling multi-qubit input states, as well.\n\n\n\\[ \\Qcircuit @C=1em @R=1.6em {\n    \\lstick{} & \\qw & \\qw \\\\\n    \\lstick{} & \\qw & \\qw \\inputgroup{1}{2}{.75em}{\\ket{0^k}}\\\\\n    \\lstick{} & \\qw & \\qw \\\\\n    \\lstick{} & \\qw & \\qw \\inputgroupv{3}{4}{.8em}{.8em}{\\ket{\\psi}}\\\\\n    \\lstick{A} & \\qw & \\qw \\\\\n    \\lstick{B} & \\qw & \\qw \\inputgrouph{5}{6}{.75em}{\\ket{\\psi}}{2.2em}\n  }\\]\ntypeset with\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=1.6em {\n    \\lstick{} & \\qw & \\qw \\\\\n    \\lstick{} & \\qw & \\qw \n      \\inputgroup{1}{2}{.75em}{\\ket{0^k}}\\\\\n    \\lstick{} & \\qw & \\qw \\\\\n    \\lstick{} & \\qw & \\qw\n      \\inputgroupv{3}{4}{.8em}{.8em}{\\ket{\\psi}}\\\\\n    \\lstick{A} & \\qw & \\qw \\\\\n    \\lstick{B} & \\qw & \\qw \n      \\inputgrouph{5}{6}{.75em}{\\ket{\\psi}}{2.2em}\n  }\\end{verbatim}}\n\n\\section{More Complicated Circuits: Multiple Qubit Gates and Beyond}\n\nSo far, we have seen how to make arbitrary QCDs involving single qubit gates and controlled gates, including CNOT.  Since this is known to be universal for computation, we could just stop here!  Of course, many circuit diagrams use more complicated structures such as multi-qubit gates, measurements, classical wires, and swaps.  We will learn how to use Q-circuit to make all of these in this section.\n\n\\subsection{Multiple qubit gates \\label{S:multigate}}\n\nLet's look at an example, and then we'll explain the code. \n\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\multigate{2}{U^\\dag} & \\qw \\\\\n     & \\ghost{U^\\dag}& \\qw \\\\\n     & \\ghost{U^\\dag} & \\qw \n}\\]\nThe 3-qubit gate above was typeset with\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n     & \\multigate{2}{U^\\dag} & \\qw \\\\\n     & \\ghost{U^\\dag}& \\qw \\\\\n     & \\ghost{U^\\dag} & \\qw \n}\\end{verbatim}}\nFirst let's go over the \\verb=\\multigate= command.  \n\\verb=\\multigate{#1}{#2}= is a two argument gate that takes the \n\\textit{depth} of the\ngate for the first argument and the \\textit{label} of the gate for the\nsecond argument.  In the above example, \\verb=#1= equals 2 because the 3-qubit gate\nextends two rows below the position of \\verb=\\multigate=.  On the other two lines, \nthe \\verb=\\ghost= command is used to get the spacing and connections right.  \\verb=\\ghost= behaves like an invisible gate that allows the quantum wires on either side of your multigate to connect correctly.\n\nThe generalization to an arbitrarily large gate is now obvious.  Let's look at a 6-qubit gate. The code\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=0em {\n     & \\multigate{5}{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \n}\\end{verbatim}}\n\\noindent yields\n\\[ \\Qcircuit @C=1em @R=0em {\n     & \\multigate{5}{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw \n}\\]\nThus, for every entry below the top, a \\verb=\\ghost= command\nwith the label for the gate is needed.  Strictly speaking, the name of the gate is not necessary inside the \\verb=\\ghost= command.  Since \\verb=\\ghost= is just an invisible place holder, anything with the same width as the label specified in multigate will work as well.  In practice, however, it is usually easiest to use the same argument.\n\nIn addition it is possible to use a classical input to a gate with \\verb=\\cghost=, or no input with \\verb=\\nghost=.\n\\[ \\Qcircuit @C=1em @R=0em {\n& \\qw    & \\multigate{3}{U} & \\qw & \\qw \\\\\n& \\cw    &       \\cghost{U} & \\cw & \\cw \\\\\n& \\cdots &       \\nghost{U} & \\cdots &  \\\\\n& \\qw    &        \\ghost{U} & \\qw & \\qw\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=0em {\n& \\qw    & \\multigate{3}{U} & \\qw & \\qw \\\\\n& \\cw    &       \\cghost{U} & \\cw & \\cw \\\\\n& \\cdots &       \\nghost{U} & \\cdots &  \\\\\n& \\qw    &        \\ghost{U} & \\qw & \\qw\n}\\end{verbatim}}\n\nNote that controls to multiple qubit gates work the same as for single\nqubit gates, using \\verb=\\ctrl= and \\verb=\\qwx=.\n\nSometimes 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:\n\n{\\scriptsize   \\begin{verbatim}\\\\Qcircuit @C=1em @R=.7em {\n     & \\multigate{1}{\\mathcal{F}} & \\sgate{\\mathcal{G}}{2} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw & \\qw\\\\\n     & \\qw & \\gate{\\mathcal{G}} & \\qw \\\\\n}\\end{verbatim}}\n\\noindent which yields\n\\[ \\Qcircuit @C=1em @R=.7em {\n     & \\multigate{1}{\\mathcal{F}} & \\sgate{\\mathcal{G}}{2} & \\qw \\\\\n     & \\ghost{\\mathcal{F}} & \\qw & \\qw\\\\\n     & \\qw & \\gate{\\mathcal{G}} & \\qw \\\\\n}\\]\n\nSuch 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.\n\n\\subsection{Measurements and classical bits}\n\nMeasurement 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.\n{\\small \\begin{center}\n    \\begin{tabular}{l | l | l} \n        \\multicolumn{1}{c}{\\itshape Example} & \\multicolumn{1}{c}{\\itshape Command} & \\multicolumn{1}{c}{\\itshape Example Code }\\\\ \\hline \n        \\Qcircuit @C=1em @R=.7em {& \\meter}\n            & \\verb=\\meter= & \\verb=\\meter=\\\\\n        \\Qcircuit @C=1em @R=.7em {& \\measure{\\mbox{Basis}}}\n            & \\verb=\\measure = & \\verb=\\measure{\\mbox{Basis}}=\\\\\n        \\Qcircuit @C=1em @R=.7em {& \\measuretab{M_{ijk}}} \\hspace{.5em}\n            & \\verb=\\measuretab= & \\verb=\\measuretab{M_{ijk}}=\\\\\n        \\Qcircuit @C=1em @R=.7em {& \\measureD{\\chi}}\n            & \\verb=\\measureD= & \\verb=\\measureD{\\chi}=\\\\\\\\\n        \\Qcircuit @C=1em @R=1.5em{ &\\meterB{\\ket{\\xi_\\pm}}}\n            & \\verb=\\meterB= & \\verb=\\meterB{\\ket{\\xi_\\pm}}=\\\\\n        \\Qcircuit @C=1em @R=1.5em{ &\\metersymb}\n            & \\verb=\\metersymb= & \\verb=\\metersymb=\n    \\end{tabular}\n\\end{center}}\n\nOften we want to condition some gate on the output of a measurement.  One convenient way illustrate this is with the classical wire commands, \\verb=\\cw= and \\verb=\\cwx=.  The classical wire commands work exactly like the quantum wire commands, but they draw double instead of single lines.\n\nHere is an example using measurement gates and classical wires and the corresponding code.\n\\[\\Qcircuit @C=1em @R=.7em {\n     & \\qw & \\measure{\\mbox{Codebit}} \\cwx[1] \\\\\n     & \\qw & \\gate{\\chi} & \\meter & \\rstick{\\cdots} \\cw\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n     & \\qw & \\measure{\\mbox{Codebit}} \\cwx[1] \\\\\n     & \\qw & \\gate{\\chi} & \\meter &\n        \\rstick{\\cdots} \\cw\n}\\end{verbatim}}\n\nIf you are using a special basis for your measurements the \\verb=\\meterB= command allows you to indicate the basis.\n\\[\\Qcircuit @C=1em @R=1.5em {\n    \\lstick{\\ket{\\psi}} & \\meterB{\\ket{\\xi_\\pm}} & \\cw\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=1.5em {\n    \\lstick{\\ket{\\psi}}  & \\meterB{\\ket{\\xi_\\pm}} & \\cw\n}\\end{verbatim}}\n\nQ-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.\n\\[\\Qcircuit @C=1em @R=.7em {\n    & \\multimeasureD{1}{\\text{Bell}} \\\\\n    & \\ghost{\\text{Bell}}\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n    & \\multimeasureD{1}{\\text{Bell}} \\\\\n    & \\ghost{\\text{Bell}}\n}\\end{verbatim}}\n \n 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:\n\n \\[ \\Qcircuit @C=1em @R=.7em {\n     &  \\smeterB{\\ket{\\xi_{\\pm}}}{2} & \\qw \\\\\n     &  \\qw & \\qw\\\\\n     & \\gate{\\ket{\\xi_{\\pm}}} & \\qw \\\\\n}\\]\n{\\small \\begin{verbatim} \\Qcircuit @C=1em @R=.7em {\n     &  \\smeterB{\\ket{\\xi_{\\pm}}}{2} & \\qw \\\\\n     &  \\qw & \\qw\\\\\n     & \\gate{\\ket{\\xi_{\\pm}}} & \\qw \\\\\n}\\end{verbatim}}\n\nThe \\verb=\\gate= command draws a gate with an incoming quantum wire. In contrast, the \\verb=\\cgate= command draws a gate with an incoming classical wire, and it can be useful for resetting a qubit after measurement:\n\\[\\Qcircuit @C=1em @R=.7em {\n    & \\qw    & \\gate{X}              & \\qw             & \\qw \\\\\n    & \\meter & \\control \\cw \\cwx[-1] & \\cgate{\\ket{0}} & \\qw\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n    & \\qw & \\gate{X} & \\qw & \\qw \\\\\n    & \\meter & \\control \\cw \\cwx[-1] \n        & \\cgate{\\ket{0}} & \\qw\n}\\end{verbatim}}\n\n\n\\subsection{Non-gate inserts, forcing space, and swap \\label{S:inserts}}\n\nIn 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.\n\nTo force an object to take up space, you should use the \\verb=\\push= command.  \\verb=\\push= is most useful in conjunction with the \\LaTeX\\ command \\verb=\\rule=.  Together they can be used to construct various sorts of invisible props and struts.\n\nQ-circuit implements a gate command called \\verb=\\qswap= that is equivalent to the text \\verb={\\times} \\qw=.  The effect of \\verb=\\qswap= is to insert half of a swap gate (that is a $\\times$) which can then be connected (using \\verb=\\qwx=) to another instance of \\verb=\\qswap= to create a swap gate.\n\nHere is a circuit that shows how to construct swap, decorate wires, and use \\verb=\\push= to make an invisible prop.\n\\[\\Qcircuit @C=1em @R=.3em {\n     &  & \\mbox{Defective Circuit}\\\\\n     & \\qswap & \\qw & \\push{\\rule{0em}{1em}} \\qw \\\\\n     & \\qswap \\qwx & \\push{X} \\qw & \\qw \\\\\n     & {/} \\qw & \\gate{H^{\\otimes n}} & \\qw\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.3em {\n     &  & \\mbox{Defective Circuit}\\\\\n     & \\qswap & \\qw & \\push{\\rule{0em}{1em}} \\qw \\\\\n     & \\qswap \\qwx & \\push{X} \\qw & \\qw \\\\\n     & {/} \\qw & \\gate{H^{\\otimes n}} & \\qw\n}\\end{verbatim}}\n\nTo indicate a generalized circuit with $n$ iterations of something, you could use the \\verb=\\cds= command.\n\\[\\Qcircuit @C=1em @R=.7em {\n     & \\targ & \\targ & \\cds{4}{\\cdots} & \\targ & \\qw\\\\\n     & \\ctrl{-1} & \\qw &\\qw & \\qw & \\qw \\\\\n     & \\qw & \\ctrl{-2} & \\qw & \\qw & \\qw \\\\\n     & & & & & \\\\\n     & \\qw & \\qw & \\qw & \\ctrl{-4} & \\qw \\\\\n}\\]\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.3em {\n     & \\targ & \\targ & \\cds{4}{\\cdots} & \\targ & \\qw\\\\\n     & \\ctrl{-1} & \\qw &\\qw & \\qw & \\qw \\\\\n     & \\qw & \\ctrl{-2} & \\qw & \\qw & \\qw \\\\\n     & & & & & \\\\\n     & \\qw & \\qw & \\qw & \\ctrl{-4} & \\qw \\\\\n}\\end{verbatim}}\n\n\n\\subsection{Barriers}\n\nYou can use the \\verb=\\barrier= command to draw a barrier in your circuit, represented as a vertical dashed line.\nThe number of bits downard to span is is adjustable and must be specified when adding it to\nthe circuit. If you want to span just a single qubit you use 0.\n\nHere is a simple example that adds a barrier over 2 qubits on a small\ncircuit:\n\n\\[ \\Qcircuit {\n    & \\gate{X} \\barrier{1} & \\qw \\\\\n    & \\gate{X} & \\qw \\\\\n}\\]\n\n{\\small \\begin{verbatim} \\Qcircuit {\n    & \\gate{X} \\barrier{1}  & \\qw \\\\\n    & \\gate{X} & \\qw \\\\\n}\\end{verbatim}}\n\n\nThe other complication with drawing barriers is that because spacing between\nelements on a circuit is not a fixed distance, finding the exact spot to place\na barrier on a circuit may need manual adjustment. There is an optional\nparameter for the \\verb=\\barrier= command to specify the horizontal offset from\nthe location you're placing it. For example, contrast the following three circuits:\n\n\\[ \\Qcircuit {\n    & \\gate{X} \\barrier[-1.95em]{1} & \\meter & \\qw \\\\\n    & \\gate{X} & \\qw & \\qw \\\\\n    & \\cw & \\cw \\cwx[-2] & \\cw \\\\\n}\\]\n\n{\\small \\begin{verbatim} \\Qcircuit  {\n    & \\gate{X} \\barrier[-1.95em]{1} & \\meter & \\qw \\\\\n    & \\gate{X} & \\qw & \\qw \\\\\n    & \\cw & \\cw \\cwx[-2] & \\cw  \\\\\n}\\end{verbatim}}\n \n\n\\[ \\Qcircuit {\n    & \\gate{X} \\barrier[0em]{1} & \\meter & \\qw \\\\\n    & \\gate{X} & \\qw & \\qw \\\\\n    & \\cw & \\cw \\cwx[-2] & \\cw \\\\\n}\\]\n\n{\\small \\begin{verbatim} \\Qcircuit  {\n    & \\gate{X} \\barrier[0em]{1} & \\meter & \\qw \\\\\n    & \\gate{X} & \\qw & \\qw \\\\\n    & \\cw & \\cw \\cwx[-2] & \\cw  \\\\\n}\\end{verbatim}}\n\n\\[ \\Qcircuit {\n    & \\gate{X} \\barrier[1.95em]{1} & \\meter & \\qw \\\\\n    & \\gate{X} & \\qw & \\qw \\\\\n    & \\cw & \\cw \\cwx[-2] & \\cw \\\\\n}\\]\n\n{\\small \\begin{verbatim} \\Qcircuit  {\n    & \\gate{X} \\barrier[1em]{1} & \\meter & \\qw \\\\\n    & \\gate{X} & \\qw & \\qw \\\\\n    & \\cw & \\cw \\cwx[-2] & \\cw  \\\\\n}\\end{verbatim}}\n\nThe default value for the spacing is set to -0.95em.\n\n\\subsection{How to control anything}\n\nControlled-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=.\n\n\\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.\n\nThe 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.\n\nThe 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.\n\nHere is an example circuit using various controls.  \n\\[ \\Qcircuit @C=1em @R=.7em {\n    & \\ctrl{2} & \\ctrlo{1} & \\ctrl{1} & \\qw & \\multigate{1}{U} & \\qw \\\\\n    & \\qw & \\targ & \\ctrlo{2} \\qw & \\ctrl{1} & \\ghost{U} & \\qw\\\\\n    & \\control \\qw & \\ctrl{1} & \\qw & \\meter & \\cctrlo{-1} &\\\\\n    & \\qw & \\control \\qw & \\gate{H} & \\meter & \\cctrl{-1}\n}\\]\n\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=.7em {\n    & \\ctrl{2} & \\ctrlo{1} & \\ctrl{1} \n        & \\qw & \\multigate{1}{U} & \\qw \\\\\n    & \\qw & \\targ & \\ctrlo{2} \\qw \n        & \\ctrl{1} & \\ghost{U} & \\qw \\\\\n    & \\control \\qw & \\ctrl{1} & \\qw \n        & \\meter & \\cctrlo{-1} \\\\\n    & \\qw & \\control \\qw & \\gate{H} \n        & \\meter & \\cctrl{-1}\n}\\end{verbatim}}\n\nNote 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.\n\n\\section{Bells and Whistles: Tweaking Your Diagram to Perfection}\n\nBy now, the reader should be able to quickly and easily typeset almost any QCD.  Nonetheless, it may occasionally be desirable to decorate or modify a circuit in ways not yet discussed.  This section presents additional tricks, options, and commands for putting the final polish on your QCDs.\n\n\\subsection{Spacing\\label{S:spaces}}\n\nThe Q-circuit parameters \\verb+@R+ and \\verb+@C+ were introduced in \\S\\ref{S:basics}; they are examples of a family of spacing parameters that can appear between the text \\verb=\\Qcircuit= and the opening curly brace.  A more complete list of available parameters is given in the table below.\n\n{\\small \\begin{center}\n    \\begin{tabular}{l | l } \n        \\multicolumn{1}{c}{\\itshape Parameter} & \\multicolumn{1}{c}{\\itshape Effect }\\\\ \\hline \n        \\verb+@R=#1+ & Sets the spacing between rows to \\verb=#1=.\\\\\n        \\verb+@C=#1+ & Sets the spacing between columns to \\verb=#1=.\\\\\n        \\verb+@!R+ & \\parbox[t]{6cm}{Sets all rows to the height of the tallest object in the circuit.}\\\\\n        \\verb+@!C+ & \\parbox[t]{6cm}{Sets all columns to the width of the widest object in the circuit.}\\\\\n        \\verb+@!+ & \\parbox[t]{6cm}{Sets all entries to the size of the largest object in the circuit.}\n    \\end{tabular}\n\\end{center}}\n\nThe \\verb=@R= and \\verb=@C= parameters adjust the separation between elements, allowing you to dictate the compactness of your QCD.  \\verb=@!R=, \\verb=@!C=, and \\verb=@!= force the elements of your circuit to have uniform sizes, this helps to prevent bunching that may occur when a particular row or column contains many small elements. \\verb=@!R= is particularly useful for forcing wires to be evenly spaced, as in the following example.\n\\[ \\Qcircuit @C=.7em @R=.3em @!R {\n    & \\qswap & \\qw & \\qswap & \\qw\\\\\n    & \\qswap \\qwx & \\ctrl{1} & \\qswap \\qwx & \\qw \\\\\n    & \\qw & \\gate{T^\\dag} & \\qw & \\qw\n}\\]\n\n{\\small \\begin{verbatim}\\Qcircuit @C=.7em @R=.3em @!R {\n    & \\qswap & \\qw & \\qswap & \\qw\\\\\n    & \\qswap \\qwx & \\ctrl{1} & \\qswap \\qwx & \\qw \\\\\n    & \\qw & \\gate{T^\\dag} & \\qw & \\qw\n}\\end{verbatim}}\n\n\\subsection{Labelling \\label{S:labels2}}\n\nA label can be placed anywhere that a gate command might normally appear.  Unlike gates, however, Q-circuit treats labels as having zero size when determining the layout of a QCD.  This prevents large labels from bending your circuit out of whack, but it also means that labels can overlap with other components.\n\nNormally an element whose size is set to zero is drawn centered on it's entry.  This is what happens when you insert text directly using curly brackets (see \\S\\ref{S:inserts}).  For most labelling, however, it is more useful to have one edge of the label fixed in the center of an entry.  For this reason Q-circuit provides a set of label commands, \\verb=\\lstick=, \\verb=\\rstick=, \\verb=\\ustick=, and \\verb=\\dstick=.  The stick commands each cause their contents to ``stick out\" from the center of an entry in a different direction.  \\verb=\\lstick=, \\verb=\\rstick=, \\verb=\\ustick=, and \\verb=\\dstick= produce labels that project out to the left, right, top, and bottom respectively.\n\nProper usage of \\verb=\\lstick= and \\verb=\\rstick= was demonstrated in \\S\\ref{S:labels}, so the following example focuses on \\verb=\\ustick= and \\verb=\\dstick=.\n\\[ \\Qcircuit @C=.7em @R=.3em {\n    & \\ustick{a} \\qw & \\qw & \\qw & \\qw & \\meter \\\\\n    & \\ustick{b} \\qw & \\qw & \\qw & \\meter \\\\\n    & & & & \\dstick{B} \\cwx & \\dstick{A} \\cwx[-2]\n}\\]\n\\\\\n{\\small \\begin{verbatim}\\Qcircuit @C=.7em @R=.3em {\n    & \\ustick{a} \\qw & \\qw & \\qw & \\qw & \\meter \\\\\n    & \\ustick{b} \\qw & \\qw & \\qw & \\meter \\\\\n    & & & & \\dstick{B} \\cwx & \\dstick{A} \\cwx[-2]\n}\\end{verbatim}}\n\n\\subsection{Grouping}\n\nIt is sometimes useful to box off sections of a circuit to indicate a subcircuit, as in the following example.\n\\[ \\Qcircuit @C=1em @R=1em {\n    & \\ctrl{2} & \\qw & \\gate{H} & \\ctrl{1} & \\gate{H} & \\qw \\\\\n    & \\qw & \\ctrl{1} & \\gate{H} & \\targ & \\gate{H} & \\qw \\\\\n    & \\targ & \\targ & \\gate{Z} & \\qw & \\ctrl{-1} & \\qw \\gategroup{1}{4}{2}{6}{.7em}{--}\n}\\]\nwhich was typeset using\n{\\small \\begin{verbatim}\\Qcircuit @C=1em @R=1em {\n    & \\ctrl{2} & \\qw & \\gate{H} & \\ctrl{1} & \n        \\gate{H} & \\qw \\\\\n    & \\qw & \\ctrl{1} & \\gate{H} & \\targ &\n        \\gate{H} & \\qw \\\\\n    & \\targ & \\targ & \\gate{Z} & \\qw & \\ctrl{-1} &\n        \\qw \\gategroup{1}{4}{2}{6}{.7em}{--} \n}\\end{verbatim}}\nThe command that made the dashed box is in the last line of code and is called \\verb=\\gategroup=.  The \\verb=\\gategroup= command can be placed following any non-empty entry, but, for clarity, it is perhaps best to put it at the end.\n\nBecause it takes six arguments, \\verb=\\gategroup= looks intimidating, but it is actually relatively easy to use.  \\verb=\\gategroup{#1}{#2}{#3}{#4}{#5}{#6}= highlights the entries between rows \\verb=#1= and \\verb=#3= and columns \\verb=#2= and \\verb=#4= by adding a box or a bracket.  Argument \\verb=#6= selects between various highlights, with the available options being:\n\\begin{center} {\\small \\verb=--  .  _\\}  ^\\}  \\{  \\}  _)  ^)  (  )=} \\end{center}\nThese options produce a dashed box, a dotted box, a curly brace on the bottom, top, left, or right, and a normal brace on the bottom, top, left, or right.  Argument \\verb=#5= is twice the spacing from the nearest gate to the box.\n\n\\verb=\\gategroup= only checks that the gates at the four corners of the requested region are properly enclosed.  As a result, gates along the boundary that are bigger than the corner gates will tend to stick out.  This is especially unsightly when the corner entries are wires, though in that case the problem can be fixed by inserting an invisible prop of the desired height (see \\S\\ref{S:inserts}).\n\n\\section{Acknowledgments}\n\nThe authors would like to thank Aaron Smith, Joe Renes, and Andrew Silberfarb for useful discussions, ideas, and debugging.  Thanks to Carl Caves and Michael Nielsen for encouragement on this project.  An extra thanks to Michael Nielsen for suggesting some useful \\LaTeX \\ resources.\n\nThe development of Q-circuit was supported in part by the National Security Agency (NSA) and the Advanced Research and Developement Activity (ARDA) under the Army Research Office (ARO) contract numbers DAAD19-01-1-0648 and W911NF-04-1-0242.\n\n\\appendix\n\\section{Positioning Q-circuit diagrams in \\LaTeX}\nQ-circuit produces \\TeX\\ graphics objects.  In theory these objects should act like any symbol or character.  Thus, they can be placed in equation environments, arrays, and figures.  In practice there are a few, largely unexplained, complications.\n\nOne of these is vertical centering in a line of text.  To center the top line of a circuit, it is sufficient to invoke it in inline math mode using \\verb=$=.  To center the entire circuit, place it inside an array.\n\nHorizontal centering within figures is also problematic.  Typically this can be corrected by placing the \\verb=\\Qcircuit= command inside a \\verb=\\centerline= command, an \\verb=\\mbox= command, or an equation environment.  For some \\LaTeX\\ distributions the commands \\verb=\\leavevmode= and \\verb=\\centering= must be added to center a figure. \n\nFinally, circuits using large labels often appear a bit off center.  This is because labels are not included when calculating the size of a circuit.  The best solution is probably to add white space (see \\S\\ref{S:inserts}) until the labels all fit within the boundaries of the circuit.\n\n\\section{Bugs and Future Work}\n\n\\begin{enumerate}\n\\item Wires often end just short of curved surfaces.\n\\item \\verb=\\gategroup= needs to check all the boundary gates when determining the highlighted area.\n\\item Targets look poor when the font size is set to small.\n\\item It would be nice if the \\verb=\\ghost= command could read the argument of the \\verb=\\multigate= command automatically.\n\\item Larger issues of centering within \\LaTeX\\ need to be addressed.\n\\end{enumerate}\n\n\\section{Code for the Introduction\\label{S:code}}\nThe first QCD depicts a way of decomposing doubly controlled unitaries.\nIt was typeset with\n{\\small \\begin{verbatim}\\Qcircuit @C=.5em @R=0em @!R {\n  & \\ctrl{1} & \\qw & & & \\qw & \\ctrl{1} & \\qw &\n    \\ctrl{1} & \\ctrl{2} & \\qw\\\\\n  & \\ctrl{1} & \\qw & \n    \\push{\\rule{.3em}{0em}=\\rule{.3em}{0em}} & &\n    \\ctrl{1} & \\targ & \\ctrl{1} & \\targ & \\qw &\n    \\qw\\\\\n  & \\gate{U} & \\qw & & & \\gate{V} & \\qw &\n    \\gate{V^\\dag} & \\qw & \\gate{V} & \\qw\n}\n\\end{verbatim}}\n\nThe second QCD depicts quantum teleportation and was typeset with\n{\\small \\begin{verbatim}\\Qcircuit @C=.7em @R=.4em @! {\n  \\lstick{\\ket{\\psi}} & \\qw & \\qw & \\ctrl{1} &\n    \\gate{H} & \\meter & \\control \\cw\\\\\n  \\lstick{\\ket{0}} & \\qw & \\targ & \\targ & \\qw &\n    \\meter & \\cwx\\\\\n  \\lstick{\\ket{0}} & \\gate{H} & \\ctrl{-1} & \\qw &\n    \\qw & \\gate{X} \\cwx & \\gate{Z} \\cwx &\n    \\rstick{\\ket{\\psi}} \\qw\n}\n\\end{verbatim}}\n\nThe third QCD depicts quantum error correction on the bit flip code.  It was typeset with\n{\\small \\begin{verbatim}\\Qcircuit @C=1.3em @R=.6em {\n  & & & & & & \\mbox{Syndrome Measurement} & & & &\n    \\mbox{Recovery}\\\\\n  & \\qw & \\qw & \\ctrl{3} & \\qw & \\qw & \\qw &\n    \\ctrl{5} & \\qw & \\qw &\n    \\multigate{2}{\\ \\mathcal{R}\\ } & \\qw\\\\\n  & \\qw & \\qw & \\qw & \\ctrl{2} & \\ctrl{3} & \\qw &\n    \\qw & \\qw & \\qw & \\ghost{\\ \\mathcal{R}\\ } \\qw &\n    \\qw\\\\\n  & \\qw & \\qw & \\qw & \\qw & \\qw & \\ctrl{2} & \\qw &\n    \\ctrl{3} & \\qw & \\ghost{\\ \\mathcal{R}\\ } \\qw &\n    \\qw\\\\\n  & & \\lstick{\\ket{0}} & \\targ \\qw & \\targ \\qw &\n    \\qw & \\qw & \\qw & \\qw & \\measure{M_a} &\n    \\control \\cw \\cwx\\\\\n  & & \\lstick{\\ket{0}} & \\qw & \\qw & \\targ \\qw &\n    \\targ \\qw & \\qw & \\qw & \\measure{M_b} &\n    \\control \\cw \\cwx\\\\\n  & & \\lstick{\\ket{0}} & \\qw & \\qw & \\qw & \\qw &\n    \\targ \\qw & \\targ \\qw & \\measure{M_c}\n    \\gategroup{2}{2}{7}{10}{.8em}{--} &\n    \\control \\cw \\cwx\n}\n\\end{verbatim}}\n\n\\pagebreak\n\n\\section{Table of Commands}\n\nThe following table is grouped according to the effect of each command.\\\\\n\n{\\small \\begin{center}\n    \\begin{tabular}{l | l } \n        \\multicolumn{1}{c}{\\itshape Subject} & \\multicolumn{1}{c}{\\itshape Command }\\\\ \\hline \n        Loading Q-circuit \\hspace{.5em} & \\verb=\\input{Qcircuit}= \\\\\n        Making Circuits & \\verb=\\Qcircuit= \\\\\n        Spacing & \\parbox[t]{6cm}{\\tt\n                    @C=\\#1 \\\\\n                    @R=\\#1 \\\\\n                    @!R \\\\\n                    @!C \\\\\n                    @! \\\\\n                    \\char92 push\\{\\#1\\} \\\\\n                    \\char92 cds\\{\\#1\\}\\{\\#2\\}}\\\\\n        Wires & \\parbox[t]{6cm}{\\tt\n                    \\char92 qw[\\#1] \\\\\n                    \\char92 qwx[\\#1] \\\\\n                    \\char92 qwa[\\#1] \\\\\n                    \\char92 cw[\\#1] \\\\\n                    \\char92 cwa[\\#1] \\\\\n                    \\char92 cwx[\\#1] }\\\\\n        Gates & \\parbox[t]{6cm}{\\tt\n                    \\char92 gate\\{\\#1\\} \\\\\n                    \\char92 targ \\\\\n                    \\char92 qswap \\\\\n                    \\char92 multigate\\{\\#1\\}\\{\\#2\\} \\\\\n                    \\char92 sgate\\{\\#1\\}\\{\\#2\\}\\\\\n                    \\char92 ghost\\{\\#1\\} \\\\\n                    \\char92 cghost\\{\\#1\\} \\\\\n                    \\char92 nghost\\{\\#1\\} }\\\\\n        Controls & \\parbox[t]{6cm}{\\tt\n                    \\char92 ctrl\\{\\#1\\} \\\\\n                    \\char92 ctrlo\\{\\#1\\} \\\\\n                    \\char92 cctrl\\{\\#1\\} \\\\\n                    \\char92 cctrlo\\{\\#1\\} \\\\\n                    \\char92 control \\\\\n                    \\char92 controlo } \\\\\n        Measurements & \\parbox[t]{6cm}{\\tt\n                    \\char92 meter \\\\\n                    \\char92 meterB\\{\\#1\\} \\\\\n                    \\char92 smeterB\\{\\#1\\}\\{\\#2\\} \\\\\n                    \\char92 measure\\{\\#1\\} \\\\\n                    \\char92 measureD\\{\\#1\\} \\\\\n                    \\char92 measuretab\\{\\#1\\} \\\\\n                    \\char92 multimeasure\\{\\#1\\}\\{\\#2\\} \\\\\n                    \\char92 multimeasureD\\{\\#1\\}\\{\\#2\\} } \\\\\n        Labels & \\parbox[t]{6cm}{\\tt\n                    \\char92 lstick\\{\\#1\\} \\\\\n                    \\char92 rstick\\{\\#1\\} \\\\\n                    \\char92 ustick\\{\\#1\\} \\\\\n                    \\char92 dstick\\{\\#1\\} \\\\\n                    \\char92 bra\\{\\#1\\} \\\\\n                    \\char92 ket\\{\\#1\\} \\\\\n                    \\char92 gategroup\\{\\#1\\}\\{\\#2\\}\\{\\#3\\}\\{\\#4\\}\\{\\#5\\}\\{\\#6\\}\\\\\n                    \\char92 inputgroup\\{\\#1\\}\\{\\#2\\}\\{\\#3\\}\\{\\#4\\}\\\\\n                    \\char92 inputgroupv\\{\\#1\\}\\{\\#2\\}\\{\\#3\\}\\{\\#4\\}\\{\\#5\\}\\\\\n                    \\char92 inputgrouph\\{\\#1\\}\\{\\#2\\}\\{\\#3\\}\\{\\#4\\}\\{\\#5\\}\\\\\n                    }\n    \\end{tabular}\n\\end{center}}\n\n\\end{document} \n"
  },
  {
    "path": "README.md",
    "content": "qcircuit\n==========\n\nA quantum circuit drawing application.\n\nThe original website for this project may be found on the [qcircuit page](http://physics.unm.edu/CQuIC/Qcircuit/) through the Center for Quantum Information and Control. We use the GitHub [wiki](https://github.com/CQuIC/qcircuit/wiki) pages to make more information about qcircuit available.\n\nWe welcome others to fork our project and include enhancements. See the [Issues list](https://github.com/CQuIC/qcircuit/issues?q=is%3Aopen) for requested updates and features.\n\nInstallation\n========\n**Dependencies**\n\nqcircuit depends on the [xy-pic](http://www.tug.org/applications/Xy-pic/) and [ifpdf](http://www.ctan.org/pkg/ifpdf) packages.\n\n**Through a TeX package manager**\n\nqcircuit has been added to the Comprehensive Tex Archive Network (CTAN), and so can be accessed through a package manager for your TeX distribution. The package name is `qcircuit`. Should you be inclined to do so, the source files may be downloaded from [this page](http://ctan.org/pkg/qcircuit), though they contain all the same files available through GitHub.\n\nHow to use this manager varies from distribution to distribution; there is a [Wikipedia page](https://en.wikibooks.org/wiki/LaTeX/Installing_Extra_Packages) which describes some of the more common ways to do so. \n\n**Simple Install**\n\nThe simplest way to use qcircuit is to download the file `qcircuit.sty` and put that file in the same folder as the tex document you are compiling. Within the document preamble, use `\\usepackage[options]{qcircuit}` to enable TeX to compile the circuit. See the Use section of this README for more information.\n\n**More Complicated (but more helpful) Way**\n\n*Note*: Using a TeX package manager takes care of putting the files in the right places in your TeX tree; we recommend users no longer use the approach below, and instead use the manager.\n\nA slightly more complicated way involves putting qcircuit in your TeX tree so that every time you compile your file TeX sees the `qcircuit.sty` file. This avoids the hassle of copying the file all over the place.\n\nTo do so, first locate the `tex/latex` subdirectory of your TeX tree. For Mac OS X users, this is located at `users/user_name/Library/texmf/tex/latex/Qcircuit`, where `user_name` is the user name you use for your login. For Windows users, this folder is located at `C:\\Program Files\\texmf\\tex\\latex\\Qcircuit`. To update the tree, run `initexmf --update-fndb` from your command line.\n\nFor Linux users, one needs to locate the root TeX directory. Use the command `locate:texmf` to find all directories with a `texmf` folder. Then, after finding an appropriate folder into which `qcircuit.sty` can be put, execute the `texhash` command to update the tree.\n\nUse\n======\nUpon successful installation, one simply calls `\\usepackage[options]{qcircuit}` to enable circuit-drawing functionality. Currently, we provide support for two options:\n\n* `braket`: This option provides the standard Dirac bras `\\bra{A}` and kets `\\ket{A}`\n* `qm`: This options provides an inner product `\\ip{A}{B}`, an outer product `\\op{A}{B}`, a matrix element `{j}{M}{k}`, and an expectation value `\\expval{M}`.\n\nBy default, none of these options are enabled, meaning if you want access to these commands, you must explicity provide them in your package call. In this way we avoid clashes with user-defined commands. For users who have defined their own commands, we welcome any feedback you may have regarding how ours are defined. Simply submit an issue and we will take a look at it.\n\nTutorial\n=========\nA simple way to check you successfully installed qcircuit is to download the `Qtutorial.tex` file and run it in your favorite TeX compiler. Should the document compile correctly, you are ready to use qcircuit in your own documents! By inspecting the figures produced and comparing with the source code, you should obtain an understanding of how to typset your own circuits.\n\nHelp\n=======\nA general FAQ can be found [on the wiki](https://github.com/CQuIC-GitHub/qcircuit/wiki/FAQ). Questions can be emailed to user [Travis-S](https://github.com/Travis-S).\n\nLicense\n========\nThis software is licensed under a [GPLv2 license](https://www.gnu.org/licenses/gpl-2.0.html). See the corresponding documentation for a description of your rights and obligations. \n\n"
  },
  {
    "path": "qcircuit.sty",
    "content": "%    qcircuit version 2.7.0\n%    Contributors: Steve Flammia, Bryan Eastin, Travis Scholten\n%    This program is free software; you can redistribute it and/or modify\n%    it under the terms of the GNU General Public License as published by\n%    the Free Software Foundation; either version 2 of the License, or\n%    (at your option) any later version.\n%\n%    This program is distributed in the hope that it will be useful,\n%    but WITHOUT ANY WARRANTY; without even the implied warranty of\n%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n%    GNU General Public License for more details.\n%\n%    You should have received a copy of the GNU General Public License\n%    along with this program; if not, write to the Free Software\n%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n% Thanks to the Xy-pic guys, Kristoffer H Rose, Ross Moore, and Daniel Müllner,\n% for their help in making Qcircuit work with Xy-pic version 3.8.  \n% Thanks also to Dave Clader, Andrew Childs, Rafael Possignolo, Tyson Williams,\n% Sergio Boixo, Cris Moore, Jonas Anderson, and Stephan Mertens for helping us test \n% and/or develop the new version.\n\\ProvidesPackage{qcircuit}[2021/11/04]\n\\RequirePackage{xy}\n\n\\DeclareOption{braket}{\n    \\newcommand{\\bra}[1]{\\ensuremath{\\left\\langle{#1}\\right\\vert}}\n    \\newcommand{\\ket}[1]{\\ensuremath{\\left\\vert{#1}\\right\\rangle}}\n    }\n\n\\DeclareOption{qm}{\n    \\newcommand{\\ip}[2]{\\ensuremath{\\left\\langle{#1}\\middle\\vert{#2}\\right\\rangle}}\n    \\newcommand{\\melem}[3]{\\ensuremath{\\left\\langle{#1}\\middle\\vert{#2}\\middle\\vert{#3}\\right\\rangle}}\n    \\newcommand{\\expval}[1]{\\ensuremath{\\left\\langle #1 \\right\\rangle}}\n    \\newcommand{\\op}[2]{\\ensuremath{\\left\\vert{#1}\\middle\\rangle\\middle\\langle{#2}\\right\\vert}}\n}\n\n\\ProcessOptions\\relax\n\n\\xyoption{matrix}\n\\xyoption{frame}\n\\xyoption{arrow}\n\\xyoption{arc}\n\n\\usepackage{ifpdf}\n\\ifpdf\n\\else\n\\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}\n%    The following option loads all the features in Xy-pic. This\n%    this is included as work-around to ensure documents compile\n%    images correctly when using XeLaTeX.\n\\xyoption{all}\n\\fi\n\n% The following resets Xy-pic matrix alignment to the pre-3.8 default, as\n% required by Qcircuit.\n\\entrymodifiers={!C\\entrybox}\n\n\\newcommand{\\qw}[1][-1]{\\ar @{-} [0,#1]}\n    % Defines a wire that connects horizontally.  By default it connects to the object on the left of the current object.\n    % WARNING: Wire commands must appear after the gate in any given entry.\n\\newcommand{\\qwx}[1][-1]{\\ar @{-} [#1,0]}\n    % Defines a wire that connects vertically.  By default it connects to the object above the current object.\n    % WARNING: Wire commands must appear after the gate in any given entry.\n\\newcommand{\\qwa}[1][-1]{\\ar @{<-} [0,#1]}\n    % 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.\n    % WARNING: Wire commands must appear after the gate in any given entry.\n\\newcommand{\\cw}[1][-1]{\\ar @{=} [0,#1]}\n    % Defines a classical wire that connects horizontally.  By default it connects to the object on the left of the current object.\n    % WARNING: Wire commands must appear after the gate in any given entry.\n\\newcommand{\\cwx}[1][-1]{\\ar @{=} [#1,0]}\n    % Defines a classical wire that connects vertically.  By default it connects to the object above the current object.\n    % WARNING: Wire commands must appear after the gate in any given entry.\n\\newcommand{\\cwa}[1][-1]{\\ar @{<=} [0,#1]}\n    % 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.\n    % WARNING: Wire commands must appear after the gate in any given entry.\n\\newcommand{\\cds}[2]{*+<1em,.9em>{\\hphantom{#2}} \\POS [0,0].[#1,0]=\"e\",!C *{#2};\"e\"+ R \\qw}\n    % Allows the insertion of text without a box and exands circuit around this text.\n    % This is useful for such things as ... to indicate a generalized circuit.\n\\newcommand{\\barrier}[2][-0.95em]{\\ar @{--}[#2,1]+<#1, -1em>;[0,1]+<#1, 1em>}\n    % Defines a barrier that is represented by a horizontal dashed line.\n    % It takes a a single argument to specify how many bits to cover\n    % To center the barrier between gates you can adjust the horizontal offset\n    % with an optional second parameter. This is the horizontal offset in em.\n    % It defaults to -0.95em\n    % WARNING: Be sure to place the barrier on the topmost bit it covers, it only propogates downwards\n\\newcommand{\\gate}[1]{*+<.6em>{#1} \\POS =\"i\",\"i\"+UR;\"i\"+UL **\\dir{-};\"i\"+DL **\\dir{-};\"i\"+DR **\\dir{-};\"i\"+UR **\\dir{-},\"i\" \\qw}\n    % Boxes the argument, making a gate.\n\\newcommand{\\cgate}[1]{*+<.6em>{#1} \\POS =\"i\",\"i\"+UR;\"i\"+UL **\\dir{-};\"i\"+DL **\\dir{-};\"i\"+DR **\\dir{-};\"i\"+UR **\\dir{-},\"i\" \\cw}\n    % Boxes the argument, making a gate, with an incoming classical wire.\n\\newcommand{\\sgate}[2]{\\gate{#1}  \\qwx[#2]}\n    % Creates a gate and a qwx wire going #2 spots below, for a gate split over\n    % non-adjacent rows\n\\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}\n    % Inserts a measurement meter.\n    % In case you're wondering, the constants .778em and .322em specify\n    % one quarter of a circle with radius 1.1em.\n    % The points added at + and - <2.2em,2.2em> are there to strech the\n    % canvas, ensuring that the size is unaffected by erratic spacing issues\n    % with the arc.\n\\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}\n    % A longer meter\n\\newcommand{\\meterB}[1]{*=<1.8em,2.6em>{\\xy 0;<0em,-.8em>:\n0*{\\begingroup\n\\everymath{\\scriptstyle}\n\\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} \n\\endxy} \\POS =\"i\",\"i\"+UR;\"i\"+UL **\\dir{-};\"i\"+DL **\\dir{-};\"i\"+DR **\\dir{-};\"i\"+UR **\\dir{-},\"i\" \\qw}\n    % A meter that allows for a measurement operator to be added below\n\\newcommand{\\smeterB}[2]{\\meterB{#1} \\qwx[#2] \\qw}\n    % A split meter that allows for a measurement operator to be split over non-\n    % adjacent rows\n\\newcommand{\\measure}[1]{*+[F-:<.9em>]{#1} \\qw}\n    % Inserts a measurement bubble with user defined text.\n\\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}\n    % Inserts a measurement tab with user defined text.\n\\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}\n    % Inserts a D-shaped measurement gate with user defined text.\n\\newcommand{\\multimeasure}[2]{*+<1em,.9em>{\\hphantom{#2}} \\qw \\POS[0,0].[#1,0];p !C *{#2},p \\drop\\frm<.9em>{-}}\n    % Draws a multiple qubit measurement bubble starting at the current position and spanning #1 additional gates below.\n    % #2 gives the label for the gate.\n    % You must use an argument of the same width as #2 in \\ghost for the wires to connect properly on the lower lines.\n\\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}\n    % Draws a multiple qubit D-shaped measurement gate starting at the current position and spanning #1 additional gates below.\n    % #2 gives the label for the gate.\n    % You must use an argument of the same width as #2 in \\ghost for the wires to connect properly on the lower lines.\n\\newcommand{\\control}{*!<0em,.025em>-=-<.2em>{\\bullet}}\n    % Inserts an unconnected control.\n\\newcommand{\\controlo}{*+<.01em>{\\xy -<.095em>*\\xycircle<.19em>{} \\endxy}}\n    % Inserts a unconnected control-on-0.\n\\newcommand{\\ctrl}[1]{\\control \\qwx[#1] \\qw}\n    % Inserts a control and connects it to the object #1 wires below.\n\\newcommand{\\ctrlo}[1]{\\controlo \\qwx[#1] \\qw}\n    % Inserts a control-on-0 and connects it to the object #1 wires below.\n\\newcommand{\\cctrl}[1]{\\control \\cwx[#1] \\cw}\n    % Inserts a classical control and connects it to the object #1 wires below. \n\\newcommand{\\cctrlo}[1]{\\controlo \\cwx[#1] \\cw}\n    % Inserts a classical control-on-0 and connects it to the object #1 wires below.    \n\\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}\n    % Inserts a CNOT target.\n\\newcommand{\\qswap}{*=<0em>{\\times} \\qw}\n    % Inserts half a swap gate.\n    % Must be connected to the other swap with \\qwx.\n\\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}\n    % Draws a multiple qubit gate starting at the current position and spanning #1 additional gates below.\n    % #2 gives the label for the gate.\n    % You must use an argument of the same width as #2 in \\ghost for the wires to connect properly on the lower lines.\n\\newcommand{\\ghost}[1]{*+<1em,.9em>{\\hphantom{#1}} \\qw}\n    % Leaves space for \\multigate on wires other than the one on which \\multigate appears.  Without this command wires will cross your gate.\n    % #1 should match the second argument in the corresponding \\multigate.\n\\newcommand{\\cghost}[1]{*+<1em,.9em>{\\hphantom{#1}} \\cw}\n    % Same as ghost but with a classical incoming wire.\n\\newcommand{\\nghost}[1]{*+<1em,.9em>{\\hphantom{#1}}}\n    % Same as ghost but with no incoming wire.\n\\newcommand{\\push}[1]{*{#1}}\n    % Inserts #1, overriding the default that causes entries to have zero size.  This command takes the place of a gate.\n    % Like a gate, it must precede any wire commands.\n    % \\push is useful for forcing columns apart.\n    % 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.\n    % WARNING: \\push must appear before any wire commands and may not appear in an entry with a gate or label.\n\\newcommand{\\gategroup}[6]{\\POS\"#1,#2\".\"#3,#2\".\"#1,#4\".\"#3,#4\"!C*+<#5>\\frm{#6}}\n    % Constructs a box or bracket enclosing the square block spanning rows #1-#3 and columns=#2-#4.\n    % The block is given a margin #5/2, so #5 should be a valid length.\n    % #6 can take the following arguments -- or . or _\\} or ^\\} or \\{ or \\} or _) or ^) or ( or ) where the first two options yield dashed and\n    % 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.\n    % \\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.\n    % 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.\n\\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}}\n    % Constructs an input group with label #5 and a grouping { from rows #1 to #2 with #3 and #4 controlling the spacing\n\\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}}\n    % Constructs an input group with label #4 from rows #1 to #2 with #3 controlling the spacing\n\\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}}\n    % Constructs an input group with label #4 and a grouping /vdots from rows #1 to #2 with #3 and #5 controlling the spacing\n\\newcommand{\\rstick}[1]{*!L!<-.5em,0em>=<0em>{#1}}\n    % Centers the left side of #1 in the cell.  Intended for lining up wire labels.  Note that non-gates have default size zero.\n\\newcommand{\\lstick}[1]{*!R!<.5em,0em>=<0em>{#1}}\n    % Centers the right side of #1 in the cell.  Intended for lining up wire labels.  Note that non-gates have default size zero.\n\\newcommand{\\ustick}[1]{*!D!<0em,-.5em>=<0em>{#1}}\n    % Centers the bottom of #1 in the cell.  Intended for lining up wire labels.  Note that non-gates have default size zero.\n\\newcommand{\\dstick}[1]{*!U!<0em,.5em>=<0em>{#1}}\n    % Centers the top of #1 in the cell.  Intended for lining up wire labels.  Note that non-gates have default size zero.\n\\newcommand{\\Qcircuit}{\\xymatrix @*=<0em>}\n    % Defines \\Qcircuit as an \\xymatrix with entries of default size 0em.\n\\newcommand{\\link}[2]{\\ar @{-} [#1,#2]}\n    % Draws a wire or connecting line to the element #1 rows down and #2 columns forward.\n\\newcommand{\\pureghost}[1]{*+<1em,.9em>{\\hphantom{#1}}}\n    % Same as \\ghost except it omits the wire leading to the left. \n\n\\endinput\n"
  }
]