pyquil icon indicating copy to clipboard operation
pyquil copied to clipboard

CCNOT and CONTROLLED CNOT not rendering the same LaTeX diagrams.

Open hiyaryan opened this issue 2 years ago • 0 comments

Issue Description

The quil gates CCNOT and CONTROLLED CNOT are equivalent and therefore should render the same LaTeX diagrams, however, they don't. CCNOT abstracts away which qubit is the control and which are the targets suggesting that CCNOT may have yet to be implemented. The diagrams associated with the following pyQuil programs are produced.

CONTROLLED CNOT 2 0 1

p = Program()
p += CNOT(0, 1).controlled(2)
\begin{tikzcd}
\lstick{\ket{q_{0}}} & \gate[wires=2]{CNOT} & \qw \\
\lstick{\ket{q_{1}}} & \qw & \qw \\
\lstick{\ket{q_{2}}} & \ctrl{-2} & \qw
\end{tikzcd}
Screenshot 2023-01-23 at 12 36 13 PM

CCNOT 0 1 2

p = Program()
p += CCNOT(0, 1, 2)
\begin{tikzcd}
\lstick{\ket{q_{0}}} & \gate[wires=3]{CCNOT} & \qw \\
\lstick{\ket{q_{1}}} & \qw & \qw \\
\lstick{\ket{q_{2}}} & \qw & \qw
\end{tikzcd}
Screenshot 2023-01-23 at 12 35 54 PM

How to Reproduce

To reproduce, use the to_latex method in the pyquil.latex module. See below for the code snippet and toggle comments between CCNOT and CNOT lines.

Code Snippet

from pyquil.quil import Program
from pyquil.gates import CNOT, CCNOT
from pyquil import latex

p = Program()
p += CCNOT(0, 1, 2)
# p += CNOT(0, 1).controlled(2)

print(p)
print(latex.to_latex(p))

CCNOT Output

CCNOT 0 1 2

\documentclass[convert={density=300,outext=.png}]{standalone}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\begin{document}
\begin{tikzcd}
\lstick{\ket{q_{0}}} & \gate[wires=3]{CCNOT} & \qw \\
\lstick{\ket{q_{1}}} & \qw & \qw \\
\lstick{\ket{q_{2}}} & \qw & \qw
\end{tikzcd}
\end{document}

CONTROLLED CNOT Output

CONTROLLED CNOT 2 0 1

\documentclass[convert={density=300,outext=.png}]{standalone}
\usepackage[margin=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{quantikz}
\begin{document}
\begin{tikzcd}
\lstick{\ket{q_{0}}} & \gate[wires=2]{CNOT} & \qw \\
\lstick{\ket{q_{1}}} & \qw & \qw \\
\lstick{\ket{q_{2}}} & \ctrl{-2} & \qw
\end{tikzcd}
\end{document}

hiyaryan avatar Jan 23 '23 20:01 hiyaryan