<div dir="ltr">I'm interested in getting working quantum circuit drawings in IPython notebook cells. The current approaches that do this use latex to draw these circuits, so I was hoping this wouldn't be too difficult to make work.<div>
<br></div><div>Ike Chuang has a python program called [qasm2circ](<a href="http://www.media.mit.edu/quanta/qasm2circ/" target="_blank">http://www.media.mit.edu/quanta/qasm2circ/</a>). I wrote a lightweight python class around the object that wraps the basic parsing methods and presents a _repr_latex_ method so that I could display the circuit. This outputs something that looks like:</div>
<div><br></div><div><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\input{xyqcirc.tex}</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">% definitions for the circuit elements</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\def\gAxA{\op{H}\w\A{gAxA}}</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\def\gBxA{\b\w\A{gBxA}}</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\def\gBxB{\o\w\A{gBxB}}</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">% definitions for bit labels and initial states</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\def\bA{ \q{q_{0}}}</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\def\bB{ \q{q_{1}}}</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">% The quantum circuit as an xymatrix</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"><span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\xymatrix@R=5pt@C=10pt{</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap"> \bA & \gAxA &\gBxA &\n </span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\\ \bB & \n &\gBxB &\n </span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">%</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">% Vertical lines and other post-xymatrix latex</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">%</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">\ar@{-}"gBxB";"gBxA"</span><br style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">
<span style="color:rgb(0,0,0);font-family:'Lucinda Grande','Lucinda Sans Unicode',Helvetica,Arial,Verdana,sans-serif;font-size:13px;white-space:nowrap">}</span></div><div><font color="#000000" face="Lucinda Grande, Lucinda Sans Unicode, Helvetica, Arial, Verdana, sans-serif"><span style="white-space:nowrap"><br>
</span></font></div><div><font color="#000000" face="Lucinda Grande, Lucinda Sans Unicode, Helvetica, Arial, Verdana, sans-serif"><span style="white-space:nowrap">which doesn't display, I think because the xyqcirc.tex stuff isn't supported by mathjax.</span></font></div>
<div><font color="#000000" face="Lucinda Grande, Lucinda Sans Unicode, Helvetica, Arial, Verdana, sans-serif"><span style="white-space:nowrap">Does anyone know of a workaround for this, or should I start honing my SVG</span></font></div>
<div><font color="#000000" face="Lucinda Grande, Lucinda Sans Unicode, Helvetica, Arial, Verdana, sans-serif"><span style="white-space:nowrap">skills to generate a more native option?<br clear="all"></span></font><div><br>
</div>-- <br>Rick Muller<br><a href="mailto:rpmuller@gmail.com" target="_blank">rpmuller@gmail.com</a><br><span><span title="Call with Google Voice"><span title="Call with Google Voice"><a href="tel:505-750-7557" value="+15057507557" target="_blank">505-750-7557</a></span></span></span><br>
</div></div>