Samplers

A sampler accepts a binary quadratic model (BQM) and returns variable assignments. Samplers generally try to find minimizing values but can also sample from distributions defined by the BQM.

DWaveSampler

class DWaveSampler(failover=False, retry_interval=-1, **config)[source]

A class for using the D-Wave system as a sampler.

Uses parameters set in a configuration file, as environment variables, or explicitly as input arguments for selecting and communicating with a D-Wave system. For more information, see D-Wave Cloud Client.

Inherits from dimod.Sampler and dimod.Structured.

Parameters:
  • failover (bool, optional, default=False) – Switch to a new QPU in the rare event that the currently connected system goes offline. Note that different QPUs may have different hardware graphs and a failover will result in a regenerated nodelist, edgelist, properties and parameters.
  • retry_interval (number, optional, default=-1) – The amount of time (in seconds) to wait to poll for a solver in the case that no solver is found. If retry_interval is negative then it will instead propogate the SolverNotFoundError to the user.
  • config_file (str, optional) – Path to a configuration file that identifies a D-Wave system and provides connection information.
  • profile (str, optional) – Profile to select from the configuration file.
  • endpoint (str, optional) – D-Wave API endpoint URL.
  • token (str, optional) – Authentication token for the D-Wave API to authenticate the client session.
  • solver (dict/str, optional) – Solver (a D-Wave system on which to run submitted problems) to select given as a set of required features. Supported features and values are described in get_solvers(). For backward compatibility, a solver name, formatted as a string, is accepted.
  • proxy (str, optional) – Proxy URL to be used for accessing the D-Wave API.
  • **config – Keyword arguments passed directly to from_config().

Examples

This example submits a two-variable Ising problem mapped directly to qubits 0 and 1 on a D-Wave system selected by explicitly requiring that it have these two active qubits. Other required parameters for communication with the system, such as its URL and an autentication token, are implicitly set in a configuration file or as environment variables, as described in Configuring a D-Wave System. Given sufficient reads (here 100), the quantum computer should return the best solution, \({1, -1}\) on qubits 0 and 1, respectively, as its first sample (samples are ordered from lowest energy).

>>> from dwave.system import DWaveSampler
>>> sampler = DWaveSampler(solver={'qubits__issuperset': {0, 1}})
>>> sampleset = sampler.sample_ising({0: -1, 1: 1}, {}, num_reads=100)
>>> sampleset.first.sample[0] == 1 and sampleset.first.sample[1] == -1
True

See Ocean Glossary for explanations of technical terms in descriptions of Ocean tools.

Properties

For parameters and properties of D-Wave systems, see D-Wave System Documentation.

DWaveSampler.properties D-Wave solver properties as returned by a SAPI query.
DWaveSampler.parameters D-Wave solver parameters in the form of a dict, where keys are keyword parameters accepted by a SAPI query and values are lists of properties in DWaveSampler.properties for each key.
DWaveSampler.nodelist List of active qubits for the D-Wave solver.
DWaveSampler.edgelist List of active couplers for the D-Wave solver.
DWaveSampler.adjacency Adjacency structure formatted as a dict, where keys are the nodes of the structured sampler and values are sets of all adjacent nodes for each key node.
DWaveSampler.structure Structure of the structured sampler formatted as a namedtuple, Structure(nodelist, edgelist, adjacency), where the 3-tuple values are the nodelist, edgelist and adjacency attributes.

Methods

DWaveSampler.sample(bqm[, warnings]) Sample from the specified Ising model.
DWaveSampler.sample_ising(h, *args, **kwargs) Sample from an Ising model using the implemented sample method.
DWaveSampler.sample_qubo(Q, **parameters) Sample from a QUBO using the implemented sample method.
DWaveSampler.validate_anneal_schedule(…) Raise an exception if the specified schedule is invalid for the sampler.

LeapHybridSampler

class LeapHybridSampler(solver=None, connection_close=True, **config)[source]

A class for using Leap’s cloud-based hybrid solvers.

Uses parameters set in a configuration file, as environment variables, or explicitly as input arguments for selecting and communicating with a hybrid solver. For more information, see D-Wave Cloud Client.

Inherits from dimod.Sampler.

Parameters:
  • config_file (str, optional) – Path to a configuration file that identifies a hybrid solver and provides connection information.
  • profile (str, optional) – Profile to select from the configuration file.
  • endpoint (str, optional) – D-Wave API endpoint URL.
  • token (str, optional) – Authentication token for the D-Wave API to authenticate the client session.
  • solver (dict/str, optional) – Solver (a hybrid solver on which to run submitted problems) to select, formatted as a string.
  • proxy (str, optional) – Proxy URL to be used for accessing the D-Wave API.
  • **config – Keyword arguments passed directly to from_config().

Examples

This example builds a random sparse graph and uses a hybrid solver to find a maximum independent set.

>>> import dimod
>>> import networkx as nx
>>> import dwave_networkx as dnx
>>> import numpy as np
>>> from dwave.system import LeapHybridSampler
...
>>> # Create a maximum-independent set problem from a random graph
>>> problem_node_count = 300
>>> G = nx.random_geometric_graph(problem_node_count, radius=0.0005*problem_node_count)
>>> qubo = dnx.algorithms.independent_set.maximum_weighted_independent_set_qubo(G)
>>> bqm = dimod.BQM.from_qubo(qubo)
...
>>> # Find a good solution
>>> sampler = LeapHybridSampler()    # doctest: +SKIP
>>> sampleset = sampler.sample(bqm)           # doctest: +SKIP

Properties

LeapHybridSampler.properties solver properties as returned by a SAPI query.
LeapHybridSampler.parameters solver parameters in the form of a dict, where keys are keyword parameters accepted by a SAPI query and values are lists of properties in LeapHybridSampler.properties for each key.

Methods

LeapHybridSampler.sample(bqm[, time_limit]) Sample from the specified binary quadratic model.
LeapHybridSampler.sample_ising(h, J, …) Sample from an Ising model using the implemented sample method.
LeapHybridSampler.sample_qubo(Q, **parameters) Sample from a QUBO using the implemented sample method.