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

Is this plugin up to date? #20

Open
chorusg opened this issue Apr 15, 2024 · 20 comments
Open

Is this plugin up to date? #20

chorusg opened this issue Apr 15, 2024 · 20 comments

Comments

@chorusg
Copy link

chorusg commented Apr 15, 2024

Is this plugin up to date? Can we use it?

@arcondello
Copy link
Member

Hi @chorusg, yes it is. Unless there was some bug you were seeing to prevent you from using it?

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024 via email

@arcondello
Copy link
Member

There are a few examples in the README. If you would like additional help, I would recommend creating a post in our community.

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

It didnt work when I copied the source code in Readme and run in cloud codespace. Any change needs to be made?

@arcondello
Copy link
Member

Can you be more specific? Specifically can you provide a minimal, reproducible example , as well as the full traceback that your are seeing?

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

  1. Open codespace on D-Wave scikit-learn Plugin
  2. Run: pip install dwave-scikit-learn-plugin
  3. Run: pip install dwave-system
  4. Run: pip install -r requirements.txt
  5. Run: python setup.py install
  6. Run: dwave auth login --oob
    Returned

Usage: dwave [OPTIONS] COMMAND [ARGS]...
Try 'dwave --help' for help.

Error: No such command 'auth'.

What is wrong with the process?

@arcondello
Copy link
Member

I see, in this case you are installing the package twice. The first with pip install dwave-scikit-learn-plugin and the second with requirements.txt/setup.py. The second is a source install it pulls in an older dwave-cloud-client version that does not have the auth feature.

Try running just

pip install dwave-scikit-learn-plugin --upgrade
dwave auth login --oob

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

After running 2 of them, this issue appears:
bash: dwave: command not found

@arcondello
Copy link
Member

It looks like somehow dwave-cloud-client got uninstalled. Can you try

pip install dwave-scikit-learn-plugin --upgrade --force

which will install everything from scratch. Also, if there is an error can you please post the entire install output as well as the entire error traceback?

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

Created a file name: rtest.py with content:

from sklearn.datasets import load_breast_cancer
from dwave.plugins.sklearn import SelectFromQuadraticModel

X, y = load_breast_cancer(return_X_y=True)

X_new = SelectFromQuadraticModel(num_features=20).fit_transform(X, y)


Then run: python rtest.py

The terminal showed this result:

Traceback (most recent call last):
File "/workspaces/dwave-scikit-learn-plugin/rtest.py", line 6, in
X_new = SelectFromQuadraticModel(num_features=20).fit_transform(X, y)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/sklearn/utils/_set_output.py", line 295, in wrapped
data_to_wrap = f(self, X, *args, **kwargs)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/sklearn/base.py", line 1101, in fit_transform
return self.fit(X, y, **fit_params).transform(X)
File "/workspaces/dwave-scikit-learn-plugin/dwave/plugins/sklearn/transformers.py", line 286, in fit
sampler = LeapHybridCQMSampler()
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/dwave/system/samplers/leap_hybrid_sampler.py", line 616, in init
self.client = Client.from_config(**config)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/dwave/cloud/client/base.py", line 430, in from_config
return _clients_client
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/dwave/cloud/events.py", line 105, in wrapped
rval = fn(*pargs, **kwargs)
File "/usr/local/python/3.10.13/lib/python3.10/site-packages/dwave/cloud/client/base.py", line 488, in init
raise ValueError("API token not defined")
ValueError: API token not defined

@arcondello
Copy link
Member

You need access to the D-Wave quantum computers and hybrid solvers. You can get access by running

dwave auth login --oob

I believe with the fresh install that should work now.

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

It was authorised but still show the above error.

@arcondello
Copy link
Member

What is the output of dwave ping?

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

We had got : Authorization completed successfully. You can now use "dwave auth get" to fetch your token.

then "dwave ping" returned: Error: Invalid configuration: API token not defined (code: 1)

@arcondello
Copy link
Member

arcondello commented Apr 15, 2024

As the message states you need to run dwave auth get to get an authorization token which will give you access to the
solver.

Or you can do this in one step with dwave auth login --oob && dwave config create --auto-token.

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

"dwave ping" works now. We have tried: python rtest.py
The result showed this issue:

Traceback (most recent call last):
File "/workspaces/dwave-scikit-learn-plugin/rtest.py", line 1, in
from sklearn.datasets import load_breast_cancer
ModuleNotFoundError: No module named 'sklearn'

@arcondello
Copy link
Member

scikit-learn is installed as part of the pip install dwave-scikit-learn-plugin install process. It seems like there may be some issues with your install path or your environment, but I think they are unrelated to this package. For general help on installing and using Python packages I would encourage you to checkout Installing packages as well as stackoverflow and other resources.

@randomir
Copy link
Member

@chorusg, this seems to be a bug in the default image used by Codespaces.

On codespace creation, they will pip install requirements.txt if present in the repo. However, python user-base seems to be off during this install (ran via Oryx), so our dwave executable console script ends up in a directory that's not in PATH.

If you uninstall it, and install again, from the initialized codespace, dwave is installed in the proper/accessible bin directory.

So, to fix this, run:

pip uninstall -y dwave-cloud-client && pip install dwave-cloud-client

Please note that this issue is not specific to this repo, or Ocean SDK. Any python package installed from the requirements.txt during codespace init is affected in the same way.

@chorusg
Copy link
Author

chorusg commented Apr 15, 2024

It works for us with this code:

import numpy as np

from sklearn.datasets import load_breast_cancer
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.pipeline import Pipeline
from dwave.plugins.sklearn import SelectFromQuadraticModel

X, y = load_breast_cancer(return_X_y=True)

num_features = X.shape[1]
searchspace = np.linspace(1, num_features, num=5, dtype=int, endpoint=True)

pipe = Pipeline([
('feature_selection', SelectFromQuadraticModel()),
('classification', RandomForestClassifier())
])

clf = GridSearchCV(pipe, param_grid=dict(feature_selection__num_features=searchspace))
search = clf.fit(X, y)
print(search.best_params_)


Questions:

  1. How do we calculate the required computing time with dwave for this program or certain program before executing it?
  2. Can we use dwave sklearn plugin the same way we use sklearn, only the difference is it will be executed with dwave?
  3. Do you have any guides or rules any where to read for using dwave sklearn plugin for ML?
  4. What is the max data size we can fit the model per time?

@arcondello
Copy link
Member

Hi @chorusg,

For your remaining questions, I'll direct you to our Ocean docs, our system docs, and our community.

GitHub issues are used for feature requests and bug reports. For more general questions about how to use our packages as well as our hybrid solvers and quantum computers, our community is a far better place.

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