QubitCircuit dosen't export to png file

581 views
Skip to first unread message

Xiao Liang

unread,
Mar 23, 2015, 7:58:00 AM3/23/15
to qu...@googlegroups.com
Hi, I am trying to visualize quantum circuits. 
After I create a qc0=QubitCircuit(2), added gate 'CNOT' in it. --> "qc0.png"  will occur error: 
>>> qc0.png
This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
==> 1 page written on `qcirc-tmp.pdf'.
sh: 1: convert: not found
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/qutip/qip/circuit.py", line 996, in png
    return Image(self._repr_png_(), embed=True)
  File "/usr/lib/python2.7/dist-packages/qutip/qip/circuit.py", line 988, in _repr_png_
    return _latex_compile(self.latex_code(), format="png")
  File "/usr/lib/python2.7/dist-packages/qutip/qip/circuit_latex.py", line 62, in _latex_compile
    with open("%s.png" % filename, "rb") as f:
IOError: [Errno 2] No such file or directory: 'qcirc.png'


How to solve the problem ? Thanks. 

Paul Nation

unread,
Mar 23, 2015, 9:30:46 PM3/23/15
to qu...@googlegroups.com
You need to have imagemagick installed.

Paul
--
You received this message because you are subscribed to the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this group and stop receiving emails from it, send an email to qutip+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

giangiacomo...@gmail.com

unread,
Apr 17, 2015, 4:42:45 PM4/17/15
to qu...@googlegroups.com
I encountered similar problems (running in Windows 8.1), see below.
Most of them are errors for the command 'rm', but those are not a problem.
I have installed ImageMagick, but that was not the solution..
The file qcirc.pdf was created, the conversion to .png failed.

Thanks for any help you could provide.
G

---------------------------------------------------------------------------------------------------
'rm' is not recognized as an internal or external command,
operable program or batch file.
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (MiKTeX 2.9 64-bit)
entering extended mode
'rm' is not recognized as an internal or external command,
operable program or batch file.

PDFCROP 1.38, 2012/11/02 - Copyright (c) 2002-2012 by Heiko Oberdiek.
Can't use an undefined value as an ARRAY reference at C:/Strawberry/perl/vendor/lib/Win32/TieRegistry.pm line 718.
'mv' is not recognized as an internal or external command,
operable program or batch file.
convert.exe: FailedToExecuteCommand `"gswin32c.exe" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r100x100"  "-sOutputFile=C:/Users/GIANGI~1/AppData/Local/Temp/magick-9740PAIvVq-LzyUe%d" "-fC:/Users/GIANGI~1/AppData/Local/Temp/magick-9740_TlYJq2XHMeD" "-fC:/Users/GIANGI~1/AppData/Local/Temp/magick-9740vbAE60ugFsxF"' (The system cannot find the file specified.

) @ error/delegate.c/ExternalDelegateCommand/480.
convert.exe: PDFDelegateFailed `The system cannot find the file specified.

' @ error/pdf.c/ReadPDFImage/794.
convert.exe: no images defined `qcirc.png' @ error/convert.c/ConvertImageCommand/3212.

Paul Nation

unread,
Apr 17, 2015, 5:33:48 PM4/17/15
to qu...@googlegroups.com
I think it is the missing mv command that is causing issues. The code was written for unix machines and not windows. Some code will need to be rewritten I think. 

Paul
--

Gian Giacomo Guerreschi

unread,
Apr 17, 2015, 6:12:14 PM4/17/15
to qu...@googlegroups.com
For future reference:
Apart the issue with unix commands on windows machines, I found that I needed to install "ghostscript".
This allowed me to generate the .png file from the .pdf file using ImageMagick.

Gian

--
You received this message because you are subscribed to a topic in the Google Groups "QuTiP: Quantum Toolbox in Python" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/qutip/x1LWNS0ij84/unsubscribe.
To unsubscribe from this group and all its topics, send an email to qutip+un...@googlegroups.com.

Paul Nation

unread,
Apr 17, 2015, 9:35:47 PM4/17/15
to qu...@googlegroups.com
Indeed, imagemagick uses ghostscript for converting PDF and PS files.

Fixing issues related to Windows is low on the list of priorities given that I do not have a Windows machine easily available.  As such, if you want this fixed soon, then it is best to do it yourself and make a pull request on Github.

Paul

jnzh...@163.com

unread,
Jul 17, 2017, 9:02:47 AM7/17/17
to QuTiP: Quantum Toolbox in Python
Hi, I encountered similar problem when I try to visualize quantum circuit use qutip.
It seems that the pdf file has not been created even I have pdfTex and pdfcrop.
How can I solve this problem?

Thank you very much in advance.

The code is simply as follows:
>>> qc0 = QubitCircuit(2)
>>> qc0.add_gate('CNOT', 0, 1)
>>> qc0.png

And the error message says:
This is pdfTeX, Version 3.1415926-1.40.10 (MiKTeX 2.8)
entering extended mode
PDFCROP 1.23, 2010/01/09 - Copyright (c) 2002-2010 by Heiko Oberdiek.
!!! Error: Input file `qcirc.pdf' not found!
mv: cannot stat 'qcirc-tmp.pdf': No such file or directory
convert: unable to open image 'qcirc.pdf': No such file or directory @ error/blo
b.c/OpenBlob/3109.
convert: no images defined `qcirc.png' @ error/convert.c/ConvertImageCommand/327
5.
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-6-71261e36abd4> in <module>()
----> 1 qc0.png

D:\Anaconda3\lib\site-packages\qutip\qip\circuit.py in png(self)
   1012     def png(self):
   1013         from IPython.display import Image
-> 1014         return Image(self._repr_png_(), embed=True)
   1015
   1016     @property

D:\Anaconda3\lib\site-packages\qutip\qip\circuit.py in _repr_png_(self)
   1004
   1005     def _repr_png_(self):
-> 1006         return _latex_compile(self.latex_code(), format="png")
   1007
   1008     def _repr_svg_(self):

D:\Anaconda3\lib\site-packages\qutip\qip\circuit_latex.py in _latex_compile(code
, filename, format)
     60         os.system("convert -density %s %s.pdf %s.png" % (100, filename,
     61                                                          filename))
---> 62         with open("%s.png" % filename, "rb") as f:
     63             result = f.read()
     64     else:

FileNotFoundError: [Errno 2] No such file or directory: 'qcirc.png'
Reply all
Reply to author
Forward
0 new messages