DiagramTeX Open DiagramTeX

DiagramTeX/quantikz editor

Quantum circuits for LaTeX

quantikz editor: draw the quantum circuit, copy the LaTeX

Type gates onto a grid of wires, drag controls to their targets and group gates with a box. DiagramTeX writes the quantikz code as you go, ready to paste into Overleaf or any LaTeX document.

Open the editor Open this example
The quantum circuit editor: a palette of gates on the left, a four-qubit quantum Fourier transform in a dashed group, with swaps and measurements, in the middle, and the circuit settings and quantikz code on the right
The quantum circuit editor: gates on the left, the circuit in the middle, the quantikz code on the right.

How to draw a quantum circuit

  1. Add a Quantum circuit block: open DiagramTeX, click the cube on the left rail, pick Quantum and click the canvas. Double-click the block to open its editor.
  2. Type gates: click a cell and type H X Y Z S T U, C for a control, O for an open control, + for a target or M for a meter. The cursor steps right, so a whole wire is quick to type.
  3. Link controls: drag a control’s blue handle to another wire.
  4. Add wires and steps: drop a gate on the dashed row or column, or right-click a cell.
  5. Copy the code: press Done, then CtrlE (⌘E on a Mac) and Copy.

Example: Four-qubit quantum Fourier transform with measurement

This is the code DiagramTeX writes for the circuit in the picture above. The first lines name what to load.

quantikz snippetOpen it in DiagramTeX and edit it
% Requires: \usepackage{tikz} \usetikzlibrary{quantikz2}
% (or \usepackage{quantikz} in place of \usetikzlibrary{quantikz2})
\begin{tikzpicture}[x=1cm, y=1cm]
  \node[font=\large] at (9.41,-4.57) {\pgfinterruptpicture%
  \begin{quantikz}
  \lstick{$\ket{x_3}$} & \gate{H}\gategroup[4,steps=12,style={dashed,rounded corners,inner xsep=2pt},label style={label position=above}]{QFT$_4$} & \gate{R_2} & \gate{R_3} & \gate{R_4} & & & & & & & \swap{3} & & \meter{} \\
  \lstick{$\ket{x_2}$} & & \ctrl{-1} & & & \gate{H} & \gate{R_2} & \gate{R_3} & & & & & \swap{1} & \meter{} \\
  \lstick{$\ket{x_1}$} & & & \ctrl{-2} & & & \ctrl{-1} & & \gate{H} & \gate{R_2} & & & \targX{} & \meter{} \\
  \lstick{$\ket{x_0}$} & & & & \ctrl{-3} & & & \ctrl{-2} & & \ctrl{-1} & \gate{H} & \targX{} & & \meter{}
  \end{quantikz}%
  \endpgfinterruptpicture};
\end{tikzpicture}

The quantikz environment inside can also go straight into your document on its own, with \usepackage{quantikz} in the preamble.

What the quantum circuit editor does

Questions

Is the quantikz editor free?
Yes. DiagramTeX is free and open source (GNU AGPLv3), with no account, no paid tier and no ads. The code it writes for you is yours to use however you like.
quantikz or quantikz2?
The code loads the TikZ library quantikz2, which ships with current TeX Live and Overleaf. On an older installation, use \usepackage{quantikz} instead, as the code’s comment says.
Does it work with Overleaf?
Yes. Copy the code into your project and add what its first lines name. The LaTeX dialog can also download a .zip to upload to Overleaf.
Is my circuit uploaded anywhere?
No. DiagramTeX runs in your browser and keeps your files there. Once it has loaded, it also works offline.
Can I edit quantikz code I already have?
Yes. Paste it onto the canvas or into the editor’s code. What the editor can show becomes gates you can move; anything else is kept and exported as written.

Other editors