Closed eunjongkim closed 5 years ago
Thrilled to hear back from some users of QNET!
Unfortunately, I'm unable to reproduce your error. Can you give more information about your environment?
I'm running Ubuntu 18.04, using conda to manage python environments. I set up an environment to investigate your issue as follows:
conda create -n test python=3.6 ipykernel
conda activate test
python -m ipykernel install --user --name test --display-name "Python 3 (test)"
git clone https://github.com/mabuchilab/QNET.git
pip install -e ./QNET
pip install pyx
jupyter notebook
Then I ran your code in a new notebook created with the new Python 3 (test)
kernel, and here's what it looks like:
If you're using a text console and not a jupyter notebook or qtconsole, you will not see the graphics, but just a text repr that says <IPython.core.display.Image object>
.
Note: the warning messages from PyX that are showing in my notebook can be suppressed by running the following code at the top of the notebook:
import logging
logging.getLogger("pyx").setLevel("ERROR")
This is a nuisance that QNET should take care of itself in the not too far future.
Thanks for the reply @danielwe , I followed the exact same steps as you mentioned, and I still get the same error:
Perhaps this is a windows-specific bug that needs to be addressed. One possible culprit is this part
c:\users\ekim7\qnet\src\qnet\algebra\core\circuit_algebra.py in render(self, fname)
221 fname = tmp_dir + "/tmp_{}.png".format(hash(time))
I think for windows path must be expressed as
fname = tmp_dir + "\\tmp_{}.png".format(hash(time))
But that was insufficient for me to get rid of this error..
Yeah, incompatibility with Windows is definitely the culprit here. Those path concatenations should be done with os.path.join
. I don't really have access to any Windows machine, so this will be tricky for me to test at the moment.
I think there are some Continuous-Integration services available for Github that test on Windows, and we should probably look into those if we want to support Windows.
Good news, I was able to reproduce the error in a Windows VM. It occurs already in the import statement. I will look further into it as time allows over the next days, and see if Windows support is a realistic goal.
So here's the problem: on Windows, neither MikTeX nor TeX Live installations expose the ghostscript executable gs
, which is called by pyx, the visualization library used by QNET. The FileNotFoundError
comes from trying to call gs
, not from the slightly malformed temp file path---turns out, Windows can usually handle file paths with forward slashes, and even mixed forward and backward slashes (still, we should eventually change to using os.path
or pathlib
to construct such paths).
Both distributions do however expose a ghostscript executable/wrapper: MikTeX calls it mgs
, and TeX Live rungs
. So if you have MikTeX, one way to make QNET visualizations work on Windows is to change the following line in src/qnet/visualization/circuit_pyx.py
:
c.writeGSfile(filename)
to
c.writeGSfile(filename, gs="mgs")
If you have TeX Live, replace mgs
with rungs
.
I guess we should implement a check for which of gs
, mgs
, rungs
, or perhaps gswin32c
, is available and executable upon import.
Does the latest commit solve the problem on your system, @eunjongkim?
@danielwe I just checked that the latest commit, together with a minor change
fname = tmp_dir + "\\tmp_{}.png".format(hash(time))
to take into account windows path worked. Thanks for the update!
Have you tried without your manual modification? On my Windows setup, it works regardless. I'll soon go through and fix this and any similar instances I can find, but I'm curious whether the current code actually fails on certain setups or not.
It seems to work for me as well without the manual modification.
Description
Hi, I'm trying to learn the qnet package for my research. I was wondering if I'm doing this in a right way or this method is broken. I assume the error is related to filepath of the temporary file generated..
What I Did
This is the command I ran:
and this is what I got: