# How to draw a circuit using quantikz?

How can one draw this complicated-looking circuit with quantikz?

Edit: Here is my attempt:

 \documentclass[english]{revtex4}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usepackage{braket}

\begin{document}
\begin{quantikz}[thin lines]
\lstick{$\ket{\psi_0}$}&    \gate{U}    &              \ctrl{1}               &   \qw     & \ctrl{1}                              &  \gate{V_1} & \gate{V_2} & \qw \\
\lstick{$\ket{0}$}          &        \qw        & \gate{R_y(\theta_1)}  &    \qw    & \gate{R_y(\theta_2)}   &             &             & \qw
\end{quantikz}

\end{document}

• Have you tried something looking the manual? Jul 25 at 12:17
• Yep...still trying: \begin{quantikz}[thin lines] \lstick{$\ket{\psi_0}$}& \gate{U} & \ctrl{1} & \qw & \ctrl{1} & \qw & \gate{V_1} & \gate{V_2} & \qw \\ \lstick{$\ket{0}$} & \qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \qw & & & \qw \end{quantikz} Jul 25 at 12:30
• Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
– DG'
Jul 25 at 12:31
• Thanks @Sebastiano. I have just updated my questioin. Jul 25 at 12:59

I couldn't make ot work with your chosen document class, but in standalone it's working. Here are two versions, one without the dotted outline and one with it.

\documentclass[border=3.14mm,tikz]{standalone}
\usepackage{graphicx}
\usepackage{amsmath}
\usetikzlibrary{quantikz}
\usepackage{braket}

\begin{document}

\begin{quantikz}[thin lines]
\lstick{$\ket{\psi_0}$}&  \gate{U} & \octrl{1} & \qw & \ctrl{1} &  \gate{V_1} & \gate{V_2} & \qw \\
\lstick{$\ket{0}$} & \qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \octrl{-1} & \ctrl{-1} & \qw
\end{quantikz}

\begin{quantikz}[thin lines]
\lstick{$\ket{\psi_0}$}& \qw &  \gate{U} \gategroup[wires=2,steps=6,style={dotted,cap=round,inner sep=10pt}]{} & \octrl{1} & \qw & \ctrl{1} &  \gate{V_1} & \gate{V_2} & \qw & \qw \\
\lstick{$\ket{0}$} & \qw &\qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \octrl{-1} & \ctrl{-1} & \qw  & \qw
\end{quantikz}

\end{document}


### EDIT: works on revtex4-2 document class

\documentclass[english]{revtex4-2}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usepackage{braket}

\begin{document}

\begin{quantikz}[thin lines]
\lstick{$\ket{\psi_0}$}&  \gate{U} & \octrl{1} & \qw & \ctrl{1} &  \gate{V_1} & \gate{V_2} & \qw \\
\lstick{$\ket{0}$} & \qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \octrl{-1} & \ctrl{-1} & \qw
\end{quantikz}

\begin{quantikz}[thin lines,node distance=2pt]
\lstick{$\ket{\psi_0}$}& \qw &  \gate{U} \gategroup[wires=2,steps=6,style={dotted,cap=round,inner sep=10pt}]{} & \octrl{1} & \qw & \ctrl{1} &  \gate{V_1} & \gate{V_2} & \qw & \qw \\
\lstick{$\ket{0}$} & \qw &\qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \octrl{-1} & \ctrl{-1} & \qw  & \qw
\end{quantikz}

\end{document}


• Thanks, @SebGlav. Is it possible to reduce the size such that this fits in one column in a two-column format? Jul 25 at 13:32
• Or any other better way of drawing the same circuit? Jul 25 at 13:34
• I don't know about resizing with quantikz. I tried several obvious solutions that failed. You can try and design with older packages, like circuitikz, or qcircuit, but I don' master them to say if a resizing is possible. You could ask this as a new question, and I'm sure you'll get answers. Jul 25 at 13:42

Your code is very close to the solution.

(1) Need to use revtex4-2.

(2) For two columns, you can use \resizebox.

(I used the code from SebGlav answer)

\documentclass[aps,reprint]{revtex4-2}

\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\usepackage{braket}

\begin{document}

1.  \kant[11]

\noindent   \resizebox{\columnwidth}{!}{% code from SebGlav answer
\begin{quantikz}[thin lines]
\lstick{$\ket{\psi_0}$}& \qw &  \gate{U} \gategroup[wires=2,steps=6,style={dotted,cap=round,inner sep=10pt}]{} & \octrl{1} & \qw & \ctrl{1} &  \gate{V_1} & \gate{V_2} & \qw & \qw \\
\lstick{$\ket{0}$} & \qw &\qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \octrl{-1} & \ctrl{-1} & \qw  & \qw
\end{quantikz}
}

\medskip
2.  \kant[2]

\tikzset{operator/.append style={fill=red!20}}

\noindent   \resizebox{\columnwidth}{!}{% code from SebGlav answer
\begin{quantikz}[thin lines]
\lstick{$\ket{\psi_0}$}& \qw &  \gate{U} \gategroup[2,steps=6,style={dashed,rounded corners,fill=blue!20,inner sep=10pt},background]{} & \octrl{1} & \qw & \ctrl{1} &  \gate{V_1} & \gate{V_2} & \qw & \qw \\
\lstick{$\ket{0}$} & \qw &\qw & \gate{R_y(\theta_1)} & \qw & \gate{R_y(\theta_2)} & \octrl{-1} & \ctrl{-1} & \qw  & \qw
\end{quantikz}
}

\medskip
3.  \kant[3]

\end{document}

• Thanks, @Simon. Is there a better way of drawing the same circuit, by compacting its size (to fit in a single column of a two column format) and maybe beautify it a little bit? Jul 25 at 14:05
• @Zubin I updated my answer. Beauty is in the eye of the beholder Jul 25 at 14:12