diff --git a/docs/reference/resources.rst b/docs/reference/resources.rst index e95752d6..f5bac83a 100644 --- a/docs/reference/resources.rst +++ b/docs/reference/resources.rst @@ -7,7 +7,7 @@ Resources The :term:`solver`\ s that provide sampling for solving :term:`Ising` and :term:`QUBO` problems, such as a D-Wave 2000Q QPU or a software :term:`sampler` such as the `dimod `_ simulated annealing sampler, are typically remote resources. The D-Wave Cloud Client -:class:`~dwave.cloud.client.Client` class manages the solver resources. +:class:`~dwave.cloud.client.Client` class manages such remote solver resources. Preferred use is with a context manager (a :code:`with Client.from_config(...) as` construct) to ensure proper closure of all resources. The following example snippet diff --git a/dwave/cloud/qpu.py b/dwave/cloud/qpu.py index 7c55bd10..39ac97ef 100644 --- a/dwave/cloud/qpu.py +++ b/dwave/cloud/qpu.py @@ -3,7 +3,7 @@ SAPI servers provide authentication, queuing, and scheduling services, and provide a network interface to :term:`solver`\ s. This API enables you submit -a binary quadratic (\ :term:`Ising` or :term:QUBO`\ ) model +a binary quadratic (\ :term:`Ising` or :term:`QUBO`\ ) model and receive samples from a distribution over the model as defined by a selected solver. diff --git a/dwave/cloud/sw.py b/dwave/cloud/sw.py index 63930ae3..1fcd9ac6 100644 --- a/dwave/cloud/sw.py +++ b/dwave/cloud/sw.py @@ -1,8 +1,8 @@ """ -Interface to software samplers available via D-Wave API. +Interface to software :term:`sampler`\ s available through the D-Wave API. -Software samplers have the same interface (response) as the QPU sampler, but -the samples are generated with classical software solvers. +Software samplers have the same interface (response) as QPU samplers, with +classical software resources generating samples. """ from __future__ import absolute_import @@ -15,13 +15,59 @@ class Client(BaseClient): - """D-Wave API client specialized to work with the remote software solvers - (samplers).""" + """D-Wave API client specialized to work with remote software solvers + (samplers). + + This class is instantiated by default, or explicitly when `client=sw`, with the + typical base client instantiation :code:`with Client.from_config() as client:` of + a client. + + Examples: + This example indirectly instantiates a :class:`dwave.cloud.sw.client` based + on the local system`s default D-Wave Cloud Client configuration file to sample + a random Ising problem tailored to fit the client`s default solver`s graph. + + .. code-block:: python + + import random + from dwave.cloud import Client + + # Use context manager to ensure resources (thread pools used by Client) are released + with Client.from_config(client='sw') as client: + + solver = client.get_solver() + + # Build problem to exactly fit the solver graph + linear = {index: random.choice([-1, 1]) for index in solver.nodes} + quad = {key: random.choice([-1, 1]) for key in solver.undirected_edges} + + # Sample 100 times and print out the first sample + computation = solver.sample_ising(linear, quad, num_reads=100) + print(computation.samples[0]) + + """ @staticmethod def is_solver_handled(solver): - """Predicate function used from superclass to filter solvers. - In the software client we're handling only remote software solvers. + """Determine if the specified solver should be handled by this client. + + This predicate function overrides superclass to allow only remote software solvers. + + Current implementation allows only D-Wave software clients with solver IDs + prefixed with `c4-sw`. If needed, update this method to suit your solver + naming scheme. + + Examples: + This example filters solvers for those prefixed My_SW_Solver. + + .. code:: python + + @staticmethod + def is_solver_handled(solver): + if not solver: + return False + return solver.id.startswith('My_SW_Solver') + """ if not solver: return False