dwavesystems / dwave-scikit-learn-plugin

A plugin to scikit-learn for quantum-classical hybrid solving
Apache License 2.0
14 stars 12 forks source link

Is this plugin up to date? #20

Open chorusg opened 7 months ago

chorusg commented 7 months ago

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

arcondello commented 7 months ago

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

chorusg commented 7 months ago

Do you have any simple code example to use this plugin?

On Mon, Apr 15, 2024, 21:24 Alexander Condello @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/dwavesystems/dwave-scikit-learn-plugin/issues/20#issuecomment-2056987819, or unsubscribe https://github.com/notifications/unsubscribe-auth/AS2T3K243JWIPPFK754DYIDY5PPIRAVCNFSM6AAAAABGHAIV2WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJWHE4DOOBRHE . You are receiving this because you were mentioned.Message ID: @.***>

arcondello commented 7 months ago

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

chorusg commented 7 months ago

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

arcondello commented 7 months ago

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

chorusg commented 7 months ago
  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 commented 7 months ago

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 commented 7 months ago

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

arcondello commented 7 months ago

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 commented 7 months ago

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](config) 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 commented 7 months ago

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 commented 7 months ago

It was authorised but still show the above error.

arcondello commented 7 months ago

What is the output of dwave ping?

chorusg commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

"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 commented 7 months ago

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 commented 7 months ago

@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 commented 7 months ago

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.bestparams)


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 commented 7 months ago

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.