Skip to content

Commit

Permalink
Update sw/client and method
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelPasvolsky committed Apr 27, 2018
1 parent e3fb031 commit 93ef096
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/reference/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/dwavesystems/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
Expand Down
2 changes: 1 addition & 1 deletion dwave/cloud/qpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
60 changes: 53 additions & 7 deletions dwave/cloud/sw.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down

0 comments on commit 93ef096

Please sign in to comment.