Configuration#

Configuration for communicating with a solver.

Communicating with a solver—submitting a problem, monitoring its progress, receiving samples—requires configuration of several parameters such as the selected solver, its URL, an API token, etc. D-Wave Cloud Client provides multiple options for configuring those parameters:

  • One or more locally saved configuration files.

  • Environment variables

  • Direct setting of key values in functions

These options can be flexibly used together. The standard use is through the from_config() classmethod.

Configuration values can be specified in multiple ways, ranked in the following order (with 1 the highest ranked):

  1. Values specified as keyword arguments.

  2. Values specified as environment variables.

  3. Values specified in the configuration file.

  4. Values specified in Client instance defaults.

  5. Values specified in Client class DEFAULTS.

Configuration files comply with standard Windows INI-like format, parsable with Python’s configparser. An optional defaults section provides default key-value pairs for all other sections. User-defined key-value pairs (unrecognized keys) are passed through to the client.

Typically configuration files are created, inspected, and changed using interactive CLI commands from your system’s console, such as dwave config create and dwave config inspect (run dwave --help for information on CLI options).

Environment variables:

  • DWAVE_API_CLIENT: API client class. Supported values are qpu, sw and hybrid.

  • DWAVE_API_ENDPOINT: Solver API endpoint URL.

  • DWAVE_API_HEADERS: Optional additional HTTP headers.

  • DWAVE_API_PROXY: URL for proxy connections to D-Wave API.

  • DWAVE_API_REGION: API region code.

  • DWAVE_API_SOLVER: Default solver.

  • DWAVE_API_TOKEN: Solver API authorization token.

  • DWAVE_CONFIG_FILE: Configuration file path.

  • DWAVE_LEAP_API_ENDPOINT: Leap API endpoint URL.

  • DWAVE_LEAP_CLIENT_ID: Leap OAuth client ID.

  • DWAVE_METADATA_API_ENDPOINT: Metadata API endpoint URL.

  • DWAVE_PROFILE: Name of profile (section).

Examples

The following are typical and advanced examples of using from_config() to create a configured client.

  • Example Typical use for QPU and hybrid solvers

This example uses a configuration file in one of the standard paths, ~/.config/dwave/dwave.conf, selected through auto-detection on the local system following the user/system configuration paths of get_configfile_paths(), to provide the following default configuration:

[defaults]
token = ABC-123456789123456789123456789

[default-solver]
solver = {"qpu": true, "num_qubits__gt": 5000}

[bqm]
client = hybrid
solver = {"supported_problem_types__contains": "bqm"}

[cqm]
client = hybrid
solver = {"supported_problem_types__contains": "cqm"}

[europe]
region = eu-central-1

This configuration file sets a default API token used by all following profiles unless overridden, ensures that selecting a solver with the get_solver() method by default returns a QPU solver with at least 5000 qubits, and configures profiles for selecting a quantum-classical hybrid solver and solvers from Leap’s European region.

The code below instantiates clients for a QPU solver and a hybrid CQM solver.

>>> with Client.from_config() as client:   
...     solver_qpu = client.get_solver()
>>> with Client.from_config(profile="cqm") as client:   
...     solver_cqm = client.get_solver()
  • Example: Explicitly specified configuration file, unrecognized parameter

This example explicitly specifies the following configuration file, ~/jane/my_path_to_config/my_cloud_conf.conf:

[defaults]
token = ABC-123456789123456789123456789

[first-qpu]
solver = {"qpu": true}

The code below creates a client that it later explicitly closes. It also passes through to the instantiated client an unrecognized key-value pair my_param="my_value".

>>> from dwave.cloud import Client
>>> client = Client.from_config(config_file='~/jane/my_path_to_config/my_cloud_conf.conf',
...                             my_param="my_value")  
>>> # code that uses client
>>> client.close()   
  • Advanced Example: Multiple auto-detected configuration files

This example uses two configuration files: (1) a user-local file, /usr/local/share/dwave/dwave.conf:

[defaults]
token = ABC-123456789123456789123456789
solver = {"qpu": true}

[advantage]
region = eu-central-1

and (2), a ./dwave.conf file in the current working directory:

[advantage]
token = DEF-987654321987654321987654321

The code below supplements the API token from higher priority file (the ./dwave.conf file in the current working directory), overriding the value from the [defaults] and first ([advantage]) sections of the lower-priority user-local file, /usr/local/share/dwave/dwave.conf. Use of the get_solver() method would select an Advantage from Leap’s European region using the DEF-987 ... token.

>>> from dwave.cloud import Client
>>> client = Client.from_config()  
>>> print(client.config.endpoint)      
https://eu-central-1.cloud.dwavesys.com/sapi/v2/
>>> print(client.config.token)  
DEF-987654321987654321987654321
>>> # code that uses client
>>> client.close() 

Methods#

Most users do not need to use these methods.

Loading Configuration#

These functions deploy D-Wave Cloud Client settings from a configuration file.

load_config([config_file, profile])

Load D-Wave Cloud Client configuration based on a configuration file.

Managing Files#

These functions manage your D-Wave Cloud Client configuration files. It’s recommended you set up your configuration through the interactive CLI utility instead.

get_configfile_paths(*[, system, user, ...])

Return a list of local configuration file paths.

get_configfile_path(**kwargs)

Return the highest-priority local configuration file.

get_default_configfile_path(**kwargs)

Return the default configuration-file path.