Closed robliou closed 1 year ago
@robliou, thanks for trying out OpenQAOA and for raising the issue. I tried to reproduce the error you described above by following the To Reproduce
. However, I get no errors on following the instructions above. See the attached screenshot below.
Can you please provide more information about your python environment? For instance, your version of python. Also, please verify that the openqaoa
was successfully installed. I am not sure what you meant by "just manually install each required dependency", since you also need to install openqaoa
package and not just the dependencies.
Let me know if something is still unclear!
FYI, I ran the code on python 3.10
and the main
branch of openqaoa
.
Hi @vishal-ph , I appreciate your quick response. :)
So, to take this process a step further, the code in its entirety (based on the example) looks like this:
import networkx
from openqaoa.problems import MinimumVertexCover
g = networkx.circulant_graph(6, [1])
vc = MinimumVertexCover(g, field=1.0, penalty=10)
qubo_problem = vc.qubo
from openqaoa import QAOA
q = QAOA()
q.compile(qubo_problem)
q.optimize()
However, trying to run this code gets the following error:
ModuleNotFoundError: No module named 'openqaoa.problems'; 'openqaoa' is not a package
I'm using Python 3.10.4, And I confirmed that openqaoa
was properly installed (separately from the dependencies, which were also installed).
Note that I just did a full re-install from scratch on a completely separate Windows laptop and am still getting the same error:
@robliou I just tried the process on a clean windows 11 install (with python 3.10.11 installed from the microsoft store) and did not encounter the issue.
I think the first step to figure out whether this is a problem with your installation's site packages or an actual bug. To do this all it takes is for you to create a new environment in the openqaoa
folder.
This can be accomplished by the following steps:
cd \path\to\openqaoa
python -m venv venv
(this will take a while, and create a venv foldervenv\Scripts\activate.bat
4b. If you are using powershell you need to make sure your signing policy is adequate (you need to have launched the terminal as administrator for the first command), first run Set-ExecutionPolicy RemoteSigned
then .\venv\Scripts\Activate.ps1
(venv)
will appear in front of your promptpip install .
command (your new environment is without packages at this stage, we need to reinstall everything)Please let me know if this fixes the issue. If that's the case, I'm afraid your site-packages might be the issue, and you might want to consider cleaning everything up to start fresh.
Heppy thoughts!
@voidburn
Hello!
I appreciate your prompt response. I just followed your suggestions to a T:
... but am still getting the same error:
Note that after trying this, I went ahead and deleted the entire openQAOA
folder, re-cloned from github, and then re-followed the steps above. However, the outcome is the same.
Is it possible that this package doesn't support python version 3.10.4
?
@robliou It was worth a try! I'm going to find the installer for python 3.10.4 and try with that version. Meanwhile a couple of things you can try on your end:
venv
, recreate it but this time upgrade pip: python -m pip install --upgrade pip
before running pip install .
just in case something was not properly built with the older version.python --version
from the command line you get the expected new one)This process of elimination (starting from the more obvious possible causes) will help us zero in on the actual culprit. Thank you for your help!
Let me know if changing the python version helps.
@voidburn
Thanks for your suggestions! I tried both methods, including upgrading to python 3.10.11, as well as upgrading the pip installer.
Then deleted venv file and re-cloned and re-installed.
Still the same issue... :( :( Weird, huh?
I had no luck reproducing it even with python 3.10.4 (https://www.python.org/ftp/python/3.10.4/python-3.10.4-amd64.exe):
I tried both without upgrading pip before the install, and with the new version. It still runs your test.py without issues:
import networkx
from openqaoa.problems import MinimumVertexCover
g = networkx.circulant_graph(6, [1])
vc = MinimumVertexCover(g, field=1.0, penalty=10)
qubo_problem = vc.qubo
This is very weird!
@shahidee44 Any idea what could be causing this issue? You've been developing on windows for a while, maybe you've seen something like this before!
@robliou Can you try and rename your file from openqaoa.py
to test.py
and try again?
Hmmm this looks weird. My suspicion might be there is something funky going on with the python install, maybe something to do with the paths. Other than @voidburn 's suggestion in renaming the openqaoa.py
file to something else like test.py
.
Can you try the following command:
python -c "import os, sys; print(os.path.dirname(sys.executable))"
This should give us a clue on where the python
path you're using is coming from.
If the path in the venv
and outside of the environment is the same, that might be the first clue that something strange is going on at the python install level.
Also possible solution would be to uninstall python locally and try installing python through the windows store. That seemed to fixed some issues in the python install itself when people had issues with missing packages.
Let me know if any of these worked or could help us with a possible lead! :)
@robliou Can you try and rename your file from
openqaoa.py
totest.py
and try again?
@voidburn
Gave that a shot, also didn't work (I can see what you're trying to test with this; it so happens I have another file called openqaoa.py
that is attempting to use the MaximumCut module from openqaoa.problems.problem
):
@shahidee44 OK, so tried both methods suggested. Here are the results:
1) On my work laptop, uninstalled Python 3.10.11 and then downloaded from Microsoft store and installed. Then ran test.py
again. Got the same error.
2) Ran the command line you suggested above, and got the following result:
It looks like the same path as before, but with \venv\Scripts
appended.
Is this indicative of a broader issue?
Tks,
@voidburn @shahidee44
Interestingly enough, it appears somewhere along the way, the original error for the original test.py
file got cleared out. Cool!
By running this code:
import networkx
from openqaoa.problems import MinimumVertexCover
g = networkx.circulant_graph(6, [1])
vc = MinimumVertexCover(g, field=1.0, penalty=10)
qubo_problem = vc.qubo
from openqaoa import QAOA
#Create the QAOA
from openqaoa import QAOA
q = QAOA()
q.compile(qubo_problem)
q.optimize()
print('this is q', q)
I can now get the following output:
Which I guess is a step in the right direction?
After all, my intent is to see whether I can use OpenQAOA to solve MaxCut questions. Running the suggested code for the MaxCut problem, however, still returns an error similar to our original one:
_max_cutsuggested.py
import numpy as np
import networkx as nx
#from openqaoa.utilities import plot_graph
# Generating a graph of nodes
G = nx.generators.fast_gnp_random_graph(n=6, p=0.6, seed=42)
from openqaoa.utilities import plot_graph
plot_graph(G)
from openqaoa.problems.problem import MaximumCut
maxcut_prob = MaximumCut(G)
maxcut_qubo = maxcut_prob.qubo
maxcut_qubo.hamiltonian.expression
returns this:
I'm assuming you guys aren't getting this error when trying to import MaximumCut
?
It is indeed a package name collision issue:
Here's the contents of test.py:
import networkx
from openqaoa.problems import MinimumVertexCover
g = networkx.circulant_graph(6, [1])
vc = MinimumVertexCover(g, field=1.0, penalty=10)
qubo_problem = vc.qubo
Here's my folder structure with test.py
, and the result of launching test.py
:
Now this is what happens when I copy test.py
to openqaoa.py
:
Very interesting, and thanks for posting the suggestion!
Based on my limited understanding, I looked up 'package name collision issue', and it appears it may be the result of when a file name is the same as a package name (in this case openqaoa
)?
However, in my file, I've changed the file named openqaoa.py
to max_cut_suggested.py
,
but am still getting this error:
Perhaps there is a conflict between my project name and the module name? Therefore, I changed my project name from openqaoa
to openqaoa_file
, but the error still did not go away:
Perhaps my understanding of what a package name collision issue means is incorrect. Could you please explain further where I may be going wrong here?
Thanks again,
@robliou Once installed in your environment openqaoa will be available everywhere, try moving your test files to a dedicated folder under you projects\python
one, see if that actually gets rid for good of these issues first! Working from within the openqaoa
cloned folder should only be done if you intend to contribute fixes or new code to it.
If this doesn't fix the maxcut problem please let us know, in which case we should close this issue and you can open another one specifically for that, since we've established that the main topic of this one has been figured out and solved.
Thanks!
Edit: My bad, didn't see that your second screenshot did exactly that. I'd say we should close this issue, and you can open a new one where the guys can try and reproduce that problem and have a look at it! This doesn't look at all like a package name collision anymore, it's likely a different issue!
Please do so!
Thank you
@voidburn
Will do, and thanks for helping to solve the initial issue. At least we got one down!
:)
Prerequisites
Before raising this issue, I have already checked that I am:
Describe the bug
Hello, I am trying to do some basic testing of the openqaoa module. In particular, I am simply going through the initial walkthrough for
MinimumVertexCover
as described in the docs. I began by successfully cloning the OpenQAOA github file, and then usingpip install .
to sucessfully install all dependencies. I verified that all dependencies were succesfully installed, includingopenqaoa
.However, when I run my test file in Python, I get the error:
and the execution fails.
To Reproduce
Steps to reproduce the behavior:
pip install .
or just manually install each required dependencytest.py
and paste the following code into it:g = networkx.circulant_graph(6, [1]) vc = MinimumVertexCover(g, field=1.0, penalty=10) qubo_problem = vc.qubo