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

If I use Jupyter or Colab how can I put token API? #14

Open juanramonua opened 1 year ago

juanramonua commented 1 year ago

D-wave system functions have a parameter called 'token' to pass it. But I don't know how pass this parameter to run the simple example of this web with SelectFromQuadraticModel(num_features=20).fit_transform(X_tmp.values, y.values)

Regards,

randomir commented 1 year ago

Long-term we might want to introduce **params argument to fit() that we'll pass to LeapHybridCQMSampler(), initializing it on construction.

But as a quick fix, for now, you can leverage environment variables to configure Ocean. In particular, you can set the token via DWAVE_API_TOKEN:

import os
os.environ['DWAVE_API_TOKEN'] = '<token>'

...
SelectFromQuadraticModel(num_features=20).fit_transform(X_tmp.values, y.values)

However, you should never store your secrets/tokens in your code, or commit them.

Instead, on Google Colab, you could use something like colab-env to pull and initialize env vars from your Google Drive.

On Jupyter, depending on your environment/setup, you can set/expose DWAVE_API_TOKEN either in your shell, or container, or similar.