I checked the source code in the qasm2tex.py
file. On line 410 the if
structure goes like:
if(m):
(name,nctrl) = m.group(1).split(',')
tex = m.group(2)
if(tex=='bullet'): # special for bullet, no \op{}
texsym = r'\b'
elif(tex.find(r'\dmeter')>=0): # if meas, don't put in \op{}
texsym = tex
else:
texsym = '\op{%s}' % tex
nctrl = int(nctrl)
if GateMasterDef.has_key(name):
print "[qasm_parser] oops! duplicate def for op %s" % line
else:
GateMasterDef[name] = (nctrl+1, nctrl, texsym)
# print "definition: %s" % m.group(1)
continue
So there are no cases for handling oplus
and times
is handled, although they're defined along with bullet
in the xyqcirc.tex
file, as single qubit operations, i.e.
% single qubit operations
\def\op#1{*+[F]{\rule[-0.2ex]{0ex}{2.1ex}#1}} % operator in box
\def\b{*={\bullet}}
\def\o{*={\oplus}}
\def\t{*={\times}} % for swap gate
\def\sq{*=<6pt,6pt>[F]{}} % square, for controlled-phase
\def\m#1{\left[\matrix{#1}\right]} % matrix shortcut
\def\z{*+[]{\rule[-0.2ex]{0ex}{2.1ex}~|0\>}} % re-init to |0>
\def\discard{*[]{\rule[-0.2ex]{0.75pt}{2.1ex}~}} % vertical ``|''
\def\slash{*={/}} % slash for wire bundles
This is most likely a bug. However, according to the qasm2tex.py
docstring it was last updated by Ike (Isaac Chuang) on 2004/03/25 15:36:59, so I'm not hoping that it'll ever be officially fixed. Anyhow, the fix is just a four-line addition to qasm2tex.py
, so I'm writing it down here just in case someone finds it helpful or wishes to write their own extension to the code:
if(m):
(name,nctrl) = m.group(1).split(',')
tex = m.group(2)
if(tex=='bullet'): # special for bullet, no \op{}
texsym = r'\b'
if(tex=='oplus'):
texsym = r'\o' # special for oplus, no \op{}
if(tex=='times'):
texsym = r'\t' # special for times, no \op{}
elif(tex.find(r'\dmeter')>=0): # if meas, don't put in \op{}
texsym = tex
else:
texsym = '\op{%s}' % tex
nctrl = int(nctrl)
if GateMasterDef.has_key(name):
print "[qasm_parser] oops! duplicate def for op %s" % line
else:
GateMasterDef[name] = (nctrl+1, nctrl, texsym)
# print "definition: %s" % m.group(1)
continue
Now to answer the original question, after the above fix has been made, the required QASM code and the corresponding TeX output is:
% def cccnot,3,'oplus'
%
% qubit j0
% qubit j1
% qubit j2
% qubit j3
%
% toffoli j0,j1,j2
% X j0
% cccnot j2,j3,j0,j1
% H j2
% measure j3
%
% Time 01:
% Gate 00 toffoli(j0,j1,j2)
% Time 02:
% Gate 01 X(j0)
% Time 03:
% Gate 02 cccnot(j2,j3,j0,j1)
% Time 04:
% Gate 03 H(j2)
% Gate 04 measure(j3)
% Qubit circuit matrix:
%
% j0: gAxA, gBxA, gCxA, n , n
% j1: gAxB, n , gCxB, n , n
% j2: gAxC, n , gCxC, gDxC, n
% j3: n , n , gCxD, gDxD, N
\documentclass[11pt]{article}
\input{xyqcirc.tex}
% definitions for the circuit elements
\def\gAxA{\b\w\A{gAxA}}
\def\gAxB{\b\w\A{gAxB}}
\def\gAxC{\o\w\A{gAxC}}
\def\gBxA{\op{X}\w\A{gBxA}}
\def\gCxC{\b\w\A{gCxC}}
\def\gCxD{\b\w\A{gCxD}}
\def\gCxA{\b\w\A{gCxA}}
\def\gCxB{\o\w\A{gCxB}}
\def\gDxC{\op{H}\w\A{gDxC}}
\def\gDxD{\meter\w\A{gDxD}}
% definitions for bit labels and initial states
\def\bA{ \q{j_{0}}}
\def\bB{ \q{j_{1}}}
\def\bC{ \q{j_{2}}}
\def\bD{ \q{j_{3}}}
% The quantum circuit as an xymatrix
\xymatrix@R=5pt@C=10pt{
\bA & \gAxA &\gBxA &\gCxA &\n &\n
\\ \bB & \gAxB &\n &\gCxB &\n &\n
\\ \bC & \gAxC &\n &\gCxC &\gDxC &\n
\\ \bD & \n &\n &\gCxD &\gDxD &\N
%
% Vertical lines and other post-xymatrix latex
%
\ar@{-}"gAxC";"gAxA"\ar@{-}"gAxC";"gAxB"
\ar@{-}"gCxB";"gCxC"\ar@{-}"gCxB";"gCxD"\ar@{-}"gCxB";"gCxA"
}
\end{document}
Circuit Diagram:
