Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to typeset things that look like

enter image description here

I'm already aware of

  • Q-circuit, which has nice custom macros for this purpose, but is based on the relatively slow and clunky XyPic
  • TikZ, which I can use to manually set things up (that's how the picture I've hotlinked was drawn)

Are there any other alternatives I should know about?

share|improve this question
    
Quantum circuits are written in a similar way to sheet music. It'd be interesting if LilyPond could be adapted/abused to suit this purpose. –  qubyte Feb 12 '12 at 11:35
add comment

3 Answers

up vote 7 down vote accepted

Apparently Nielsen and Chuang used qasm2circ to produce the figures in Quantum Computation and Quantum Information.

share|improve this answer
    
qasm2circ is also based on xypic, apparently. So it suffers from the same criticisms that the OP gave for qcircuit. –  Seamus Jan 27 '11 at 15:02
5  
OP's primary objection to XyPic was speed, which matters if you're using it every time you build your document (which is the standard workflow for Q-circuit). The workflow for qasm2circ is to build the quantum circuit diagrams beforehand and then use \includegraphics, which offsets the slowness of XyPic (and is a better workflow for preparing documents for publication). And regardless of the OP's objections to XyPic, the fact that qasm2circ was used to produce the quantum circuit diagrams for the book on quantum computation makes it an important alternative to be aware of. –  las3rjock Jan 27 '11 at 19:41
add comment

There is circuitikz for drawing circuits with TiKZ.

share|improve this answer
5  
The circuitikz package is for drawing electrical circuits; quantum circuits are almost completely different. It might be adaptable, but then you probably might as well be using plain TikZ. –  Antal S-Z Jan 28 '11 at 9:04
    
That's fair enough. –  Mikael Vejdemo-Johansson Jan 29 '11 at 9:49
add comment

The image you link to was a diagram I did in TikZ a few years ago. It's not a particularly efficient way of doing it either. These days I'd typeset that using a TikZ matrix environment. The only real option specific to quantum circuits were qasm2circ and q-circuit. I don't like the output they generate though, and TikZ is really the way to go in my opinion. Sure, it may require a few more key strokes, but I think the effort pays off. One important point to make is that TikZ can be slow, but if you get it to externalise TikZ images then it becomes as fast as a normal \includegraphics after a single slow compilation per diagram.

A revised version of the example you link to which may be more inspirational follows:

\documentclass[10pt]{standalone}
\usepackage{tikz}

% TikZ libraries `calc` needed now to tweak bracket.
\usetikzlibrary{backgrounds,fit,decorations.pathreplacing,calc}
% Dirac Kets
\newcommand{\ket}[1]{\ensuremath{\left|#1\right\rangle}}

\begin{document}
    \begin{tikzpicture}[thick]
    % `operator' will only be used by Hadamard (H) gates here.
    % `phase' is used for controlled phase gates (dots).
    % `surround' is used for the background box.
    \tikzstyle{operator} = [draw,fill=white,minimum size=1.5em] 
    \tikzstyle{phase} = [draw,fill,shape=circle,minimum size=5pt,inner sep=0pt]
    \tikzstyle{surround} = [fill=blue!10,thick,draw=black,rounded corners=2mm]
    %
    \matrix[row sep=0.4cm, column sep=0.8cm] (circuit) {
    % First row.
    \node (q1) {\ket{0}}; &[-0.5cm] 
    \node[operator] (H11) {H}; &
    \node[phase] (P12) {}; &
    \node[phase] (P13) {}; &
    &[-0.3cm]
    \coordinate (end1); \\
    % Second row.
    \node (q2) {\ket{0}}; &
    \node[operator] (H21) {H}; &
    \node[phase] (P22) {}; &
    &
    \node[operator] (H24) {H}; &
    \coordinate (end2);\\
    % Third row.
    \node (q3) {\ket{0}}; &
    \node[operator] (H31) {H}; &
    &
    \node[phase] (P33) {}; &
    \node[operator] (H34) {H}; &
    \coordinate (end3); \\
    };
    % Draw bracket on right with resultant state.
    \draw[decorate,decoration={brace},thick]
        ($(circuit.north east)-(0cm,0.3cm)$)
        to node[midway,right] (bracket) {$\displaystyle\frac{\ket{000}+\ket{111}}{\sqrt{2}}$}
        ($(circuit.south east)+(0cm,0.3cm)$);
    \begin{pgfonlayer}{background}
        % Draw background box.
        \node[surround] (background) [fit = (q1) (H31) (bracket)] {};
        % Draw lines.
        \draw[thick] (q1) -- (end1)  (q2) -- (end2) (q3) -- (end3) (P12) -- (P22) (P13) -- (P33);
    \end{pgfonlayer}
    %
    \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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