Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example from the README fails: No module named 'dwave.samplers.greedy.descent' #31

Closed
yurivict opened this issue Aug 14, 2022 · 17 comments

Comments

@yurivict
Copy link

yurivict commented Aug 14, 2022

$ cat x.py 
from dwave.samplers import RandomSampler
sampler = RandomSampler()

$ python3.9 x.py 
Traceback (most recent call last):
  File "/disk-samsung/freebsd-ports/science/py-dwave-samplers/x.py", line 1, in <module>
    from dwave.samplers import RandomSampler
  File "/usr/local/lib/python3.9/site-packages/dwave/samplers/__init__.py", line 17, in <module>
    from dwave.samplers.greedy import *
  File "/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__init__.py", line 15, in <module>
    from dwave.samplers.greedy.sampler import *
  File "/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/sampler.py", line 25, in <module>
    from dwave.samplers.greedy.descent import steepest_gradient_descent
ModuleNotFoundError: No module named 'dwave.samplers.greedy.descent'

Version: 1.0.0.dev1

@arcondello
Copy link
Member

Hi @yurivict you need to install the package first. This can be done with

pip install dwave-samplers

to install from pypi.

Or, if you want to build locally and intend to run the code from the top-level directory of the repo.

python setup.py build_ext --inplace

Or, finally if you want to build locally and want to run from a different directory

pip install .

@yurivict
Copy link
Author

The package is installed:

$ pkg info -l py39-dwave-samplers
py39-dwave-samplers-1.0.0.d1:
	/usr/local/lib/python3.9/site-packages/dwave/samplers/__init__.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/__pycache__/__init__.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/__pycache__/__init__.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__init__.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__pycache__/__init__.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__pycache__/__init__.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__pycache__/composite.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__pycache__/composite.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__pycache__/sampler.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/__pycache__/sampler.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/composite.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/decl.pxd
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/descent.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/descent.pyx
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/sampler.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/src/descent.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/greedy/src/descent.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/__init__.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/__pycache__/__init__.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/__pycache__/__init__.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/__pycache__/sampler.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/__pycache__/sampler.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/cyrandom.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/cyrandom.pyx
	/usr/local/lib/python3.9/site-packages/dwave/samplers/random/sampler.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/__init__.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/__pycache__/__init__.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/__pycache__/__init__.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/__pycache__/sampler.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/__pycache__/sampler.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/sampler.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/simulated_annealing.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/simulated_annealing.pyx
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/src/cpu_sa.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/sa/src/cpu_sa.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__init__.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__pycache__/__init__.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__pycache__/__init__.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__pycache__/sampler.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__pycache__/sampler.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__pycache__/utils.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/__pycache__/utils.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/sampler.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/bqp.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/bqp.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/common.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/tabu_search.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/tabu_search.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/tabu_utils.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/src/tabu_utils.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/tabu.pxd
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/tabu_search.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/tabu_search.pyx
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tabu/utils.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/__init__.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/__pycache__/__init__.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/__pycache__/__init__.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/__pycache__/samplers.cpython-39.opt-1.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/__pycache__/samplers.cpython-39.pyc
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/orang.pxd
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/sample.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/sample.pyx
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/samplers.py
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/solve.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/solve.pyx
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/base.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/buckettree.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/combine.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/exception.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/graph.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/marginalizer.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/merger.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/operations/count.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/operations/dummy.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/operations/logsumprod.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/operations/min.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/orang.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/sample.hpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/solve.hpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/table.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/task.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/treedecomp.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/utils.hpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/src/include/varorder.h
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/utilities.cpp
	/usr/local/lib/python3.9/site-packages/dwave/samplers/tree/utilities.pyx
	/usr/local/lib/python3.9/site-packages/dwave_samplers-1.0.0.dev1-py3.9.egg-info/PKG-INFO
	/usr/local/lib/python3.9/site-packages/dwave_samplers-1.0.0.dev1-py3.9.egg-info/SOURCES.txt
	/usr/local/lib/python3.9/site-packages/dwave_samplers-1.0.0.dev1-py3.9.egg-info/dependency_links.txt
	/usr/local/lib/python3.9/site-packages/dwave_samplers-1.0.0.dev1-py3.9.egg-info/not-zip-safe
	/usr/local/lib/python3.9/site-packages/dwave_samplers-1.0.0.dev1-py3.9.egg-info/requires.txt
	/usr/local/lib/python3.9/site-packages/dwave_samplers-1.0.0.dev1-py3.9.egg-info/top_level.txt
	/usr/local/lib/python3.9/site-packages/samplers/greedy/descent.cpython-39.so
	/usr/local/lib/python3.9/site-packages/samplers/random/cyrandom.cpython-39.so
	/usr/local/lib/python3.9/site-packages/samplers/sa/simulated_annealing.cpython-39.so
	/usr/local/lib/python3.9/site-packages/samplers/tabu/tabu_search.cpython-39.so
	/usr/local/lib/python3.9/site-packages/samplers/tree/sample.cpython-39.so
	/usr/local/lib/python3.9/site-packages/samplers/tree/solve.cpython-39.so
	/usr/local/lib/python3.9/site-packages/samplers/tree/utilities.cpython-39.so

@arcondello
Copy link
Member

If your current working directory is the repo root, then Python will try to use the local version rather than the one in site-packages. I would try navigating to a different directory if you want to use the version in site-packages.

@yurivict
Copy link
Author

No, my work directory isn't repo root.

@arcondello
Copy link
Member

How did you install the package?

@yurivict
Copy link
Author

setup.py build
setup.py install

This was done within the FreeBSD ports framework.

@arcondello
Copy link
Member

arcondello commented Aug 14, 2022

Try running

python setup.py build_ext --inplace
python setup.py install

I am not 100% sure that just build will do the Cython/C++ step.

@yurivict
Copy link
Author

This way build fails:

c++ -shared -fstack-protector-strong -O2 -pipe -fno-omit-frame-pointer -fstack-protector-strong -fno-strict-aliasing -fno-omit-frame-pointer build/temp.freebsd-13.1-STABLE-amd64-cpython-39/dwave/samplers/tree/utilities.o -L/usr/local/lib -o build/lib.freebsd-13.1-STABLE-amd64-cpython-39/samplers/tree/utilities.cpython-39.so
copying build/lib.freebsd-13.1-STABLE-amd64-cpython-39/samplers/greedy/descent.cpython-39.so -> samplers/greedy
error: could not create 'samplers/greedy/descent.cpython-39.so': No such file or directory
*** Error code 1

@arcondello
Copy link
Member

And what about

pip install .

preferably after updating pip and setuptools

pip install pip setuptools -U

@yurivict
Copy link
Author

I am trying to create the FreeBSD port for dwave-samplers.

pip is never involved in port's build process. setuptools is already installed from the package.

@arcondello
Copy link
Member

I have not been able to reproduce locally. The only clue I have is that it looks like the .so files are being put in the wrong directory, /usr/local/lib/python3.9/site-packages/samplers/ rather than /usr/local/lib/python3.9/site-packages/dwave/samplers/.
You could try moving the manually to confirm.

@yurivict
Copy link
Author

Yes, it looks like directories are messed up.

I also tried to build w/out distutils - using build/installer modules. build/installer install the package with the same problem.

This looks to me like a bug in the project.

@arcondello
Copy link
Member

I suppose that is possible. But the only places such paths are specified are here which is the standard Python/Cython build pattern.

Also, running

python setup.py build_ext --inplace
python setup.py install

puts everything in the correct place on my local system.

I am using setuptools 58.1.0, Cython 0.29.28 for what it's worth.

@arcondello
Copy link
Member

arcondello commented Aug 14, 2022

Have you, by chance, added an __init__.py to the top level? i.e.

.circleci/
docs/
dwave/
releasenotes/
tests/
__init__.py
LICENSE
pyproject.toml
MANIFEST.in
README.rst
requirements.txt
setup.cfg
setup.py

if that's the case, you may be running into pypa/setuptools#3343. I was able to get an error similar to yours by adding that file.

@yurivict
Copy link
Author

No, I didn't add any files.

I use setuptools-63.1.0, cython-0.29.32.

Your setuptools and cython packages are outdated.

@arcondello
Copy link
Member

Updating both does not change the behavior - still works fine locally.

@yurivict
Copy link
Author

Correcting paths fixes the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants