dwave.cloud.config.load_config#

load_config(config_file: str | bool | None = None, profile: str | None = None, **kwargs) dict[source]#

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

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

  1. Values specified as keyword arguments in load_config(). These values replace values read from a configuration file, and therefore must be strings, including float values for timeouts, boolean flags, and solver feature constraints (a dictionary encoded as JSON).

  2. Values specified as environment variables.

  3. Values specified in the configuration file.

  4. Values specified as Client instance defaults.

  5. Values specified in Client class DEFAULTS.

Configuration-file format is described in dwave.cloud.config.

Available configuration-file options are identical to Client constructor argument names.

If the location of the configuration file is not specified, auto-detection searches for existing configuration files in the standard directories of get_configfile_paths().

If a configuration file explicitly specified, via an argument or environment variable, does not exist or is unreadable, loading fails with ConfigFileReadError. Loading fails with ConfigFileParseError if the file is readable but invalid as a configuration file.

Similarly, if a profile explicitly specified, via an argument or environment variable, is not present in the loaded configuration, loading fails with ValueError. Explicit profile selection also fails if the configuration file is not explicitly specified, detected on the system, or defined via an environment variable.

Environment variables: DWAVE_CONFIG_FILE, DWAVE_PROFILE, DWAVE_API_CLIENT, DWAVE_API_REGION, DWAVE_API_ENDPOINT, DWAVE_API_TOKEN, DWAVE_API_SOLVER, DWAVE_API_PROXY, DWAVE_API_HEADERS, DWAVE_LEAP_API_ENDPOINT, DWAVE_LEAP_CLIENT_ID, DWAVE_METADATA_API_ENDPOINT.

Environment variables are described in dwave.cloud.config.

Parameters:
  • config_file (str/[str]/None/False/True, default=None) –

    Path to configuration file(s).

    If None, the value is taken from DWAVE_CONFIG_FILE environment variable if defined. If the environment variable is undefined or empty, auto-detection searches for existing configuration files in the standard directories of get_configfile_paths().

    If False, loading from file(s) is skipped; if True, forces auto-detection (regardless of the DWAVE_CONFIG_FILE environment variable).

  • profile (str, default=None) –

    Profile name (name of the profile section in the configuration file).

    If undefined, inferred from DWAVE_PROFILE environment variable if defined. If the environment variable is undefined or empty, a profile is selected in the following order:

    1. From the default section if it includes a profile key.

    2. The first section (after the default section).

    3. If no other section is defined besides [defaults], the defaults section is promoted and selected.

  • **kwargs (dict, optional) – Client constructor arguments.

Returns:

Mapping of configuration keys to values for the profile (section), as read from the configuration file and optionally overridden by environment values and specified keyword arguments.

Return type:

dict

Raises:

Note

Prior to 0.8.0, some keyword arguments did not overwrite config variables when their value was None. Now we consistently do dict.update() on the config read from file/env for all kwargs.

Examples

This example loads the configuration from an auto-detected configuration file in the home directory of a Windows system user.

>>> from dwave.cloud import config
>>> config.load_config()         
{'solver': '{"qpu": true, "num_qubits__gt": 5000}',
 'token': 'ABC-123456789123456789123456789'}
>>> # See which configuration file was loaded
>>> config.get_configfile_paths()             
['C:\Users\jane\AppData\Local\dwavesystem\dwave\dwave.conf']

Additional examples are given in dwave.cloud.config.