dwave-cloud-client 0.12.0.dev0__tar.gz → 0.12.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. {dwave-cloud-client-0.12.0.dev0/dwave_cloud_client.egg-info → dwave-cloud-client-0.12.1}/PKG-INFO +1 -1
  2. dwave-cloud-client-0.12.1/dwave/cloud/__init__.py +45 -0
  3. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/api/client.py +3 -3
  4. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/api/models.py +1 -1
  5. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/api/resources.py +1 -1
  6. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/auth/flows.py +2 -1
  7. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/cli.py +10 -10
  8. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/client/base.py +12 -31
  9. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/coders.py +56 -5
  10. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/computation.py +17 -35
  11. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/package_info.py +1 -1
  12. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/regions.py +1 -1
  13. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/solver.py +39 -15
  14. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/testing/mocks.py +91 -15
  15. dwave-cloud-client-0.12.1/dwave/cloud/utils/__init__.py +26 -0
  16. dwave-cloud-client-0.12.1/dwave/cloud/utils/cli.py +105 -0
  17. dwave-cloud-client-0.12.1/dwave/cloud/utils/coders.py +70 -0
  18. dwave-cloud-client-0.12.1/dwave/cloud/utils/decorators.py +438 -0
  19. dwave-cloud-client-0.12.1/dwave/cloud/utils/dist.py +94 -0
  20. dwave-cloud-client-0.12.1/dwave/cloud/utils/exception.py +93 -0
  21. dwave-cloud-client-0.12.1/dwave/cloud/utils/http.py +160 -0
  22. dwave-cloud-client-0.12.0.dev0/dwave/cloud/__init__.py → dwave-cloud-client-0.12.1/dwave/cloud/utils/logging.py +84 -42
  23. dwave-cloud-client-0.12.1/dwave/cloud/utils/qubo.py +145 -0
  24. dwave-cloud-client-0.12.1/dwave/cloud/utils/time.py +72 -0
  25. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1/dwave_cloud_client.egg-info}/PKG-INFO +1 -1
  26. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave_cloud_client.egg-info/SOURCES.txt +11 -1
  27. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave_cloud_client.egg-info/requires.txt +1 -1
  28. dwave-cloud-client-0.12.1/pyproject.toml +6 -0
  29. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/setup.py +1 -1
  30. dwave-cloud-client-0.12.0.dev0/dwave/cloud/utils.py +0 -1069
  31. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/LICENSE +0 -0
  32. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/README.rst +0 -0
  33. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/__init__.py +0 -0
  34. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/api/__init__.py +0 -0
  35. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/api/constants.py +0 -0
  36. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/api/exceptions.py +0 -0
  37. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/auth/__init__.py +0 -0
  38. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/auth/_creds.py +0 -0
  39. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/auth/config.py +0 -0
  40. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/auth/creds.py +0 -0
  41. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/auth/server.py +0 -0
  42. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/client/__init__.py +0 -0
  43. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/client/hybrid.py +0 -0
  44. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/client/qpu.py +0 -0
  45. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/client/sw.py +0 -0
  46. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/concurrency.py +0 -0
  47. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/config/__init__.py +0 -0
  48. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/config/loaders.py +0 -0
  49. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/config/models.py +0 -0
  50. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/events.py +0 -0
  51. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/exceptions.py +0 -0
  52. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/testing/__init__.py +0 -0
  53. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave/cloud/upload.py +0 -0
  54. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave_cloud_client.egg-info/dependency_links.txt +0 -0
  55. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave_cloud_client.egg-info/entry_points.txt +0 -0
  56. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave_cloud_client.egg-info/not-zip-safe +0 -0
  57. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/dwave_cloud_client.egg-info/top_level.txt +0 -0
  58. {dwave-cloud-client-0.12.0.dev0 → dwave-cloud-client-0.12.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dwave-cloud-client
3
- Version: 0.12.0.dev0
3
+ Version: 0.12.1
4
4
  Summary: A minimal client for interacting with D-Wave cloud resources.
5
5
  Home-page: https://github.com/dwavesystems/dwave-cloud-client
6
6
  Author: D-Wave Systems Inc.
@@ -0,0 +1,45 @@
1
+ # Copyright 2017 D-Wave Systems Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import sys
16
+ import logging
17
+ import importlib
18
+
19
+ from dwave.cloud.client import Client
20
+ from dwave.cloud.solver import Solver
21
+ from dwave.cloud.computation import Future
22
+ from dwave.cloud.utils.logging import add_loglevel, configure_logging_from_env
23
+
24
+ __all__ = ['Client', 'Solver', 'Future']
25
+
26
+
27
+ # prevent log output (from library) when logging not configured by user/app
28
+ logger = logging.getLogger(__name__)
29
+ logger.addHandler(logging.NullHandler())
30
+
31
+ # make sure TRACE level is available
32
+ add_loglevel('TRACE', 5)
33
+
34
+ # configure logger if DWAVE_LOG_LEVEL present in environment
35
+ configure_logging_from_env(logger)
36
+
37
+
38
+ # alias dwave.cloud.client.{qpu,sw,hybrid} as dwave.cloud.*
39
+ def _alias_old_client_submodules():
40
+ for name in ('qpu', 'sw', 'hybrid'):
41
+ # note: create both module and local attribute
42
+ globals()[name] = sys.modules['dwave.cloud.{}'.format(name)] = \
43
+ importlib.import_module('dwave.cloud.client.{}'.format(name))
44
+
45
+ _alias_old_client_submodules()
@@ -24,10 +24,10 @@ from packaging.specifiers import SpecifierSet
24
24
  from werkzeug.http import parse_options_header, dump_options_header
25
25
 
26
26
  from dwave.cloud.api import constants, exceptions
27
- from dwave.cloud.config import load_config, validate_config_v1, update_config
27
+ from dwave.cloud.config import load_config, validate_config_v1
28
28
  from dwave.cloud.config.models import ClientConfig
29
- from dwave.cloud.utils import (
30
- PretimedHTTPAdapter, BaseUrlSession, default_user_agent, is_caused_by)
29
+ from dwave.cloud.utils.exception import is_caused_by
30
+ from dwave.cloud.utils.http import PretimedHTTPAdapter, BaseUrlSession, default_user_agent
31
31
 
32
32
  __all__ = ['DWaveAPIClient', 'SolverAPIClient', 'MetadataAPIClient', 'LeapAPIClient']
33
33
 
@@ -20,7 +20,7 @@ from pydantic import BaseModel, RootModel, Field
20
20
  from pydantic.functional_validators import AfterValidator
21
21
 
22
22
  from dwave.cloud.api import constants
23
- from dwave.cloud.utils import coerce_numpy_to_python
23
+ from dwave.cloud.utils.coders import coerce_numpy_to_python
24
24
 
25
25
 
26
26
  # coerce common numpy types to python types on validation (parsing)
@@ -23,7 +23,7 @@ from dwave.cloud.api.client import (
23
23
  DWaveAPIClient, SolverAPIClient, MetadataAPIClient, LeapAPIClient)
24
24
  from dwave.cloud.api import constants, models
25
25
  from dwave.cloud.config.models import ClientConfig
26
- from dwave.cloud.utils import NumpyEncoder
26
+ from dwave.cloud.utils.coders import NumpyEncoder
27
27
 
28
28
  __all__ = ['Solvers', 'Problems', 'Regions']
29
29
 
@@ -33,7 +33,8 @@ from dwave.cloud.auth.creds import Credentials
33
33
  from dwave.cloud.auth.server import SingleRequestAppServer, RequestCaptureAndRedirectApp
34
34
  from dwave.cloud.config.models import ClientConfig
35
35
  from dwave.cloud.regions import resolve_endpoints
36
- from dwave.cloud.utils import pretty_argvalues, default_user_agent
36
+ from dwave.cloud.utils.http import default_user_agent
37
+ from dwave.cloud.utils.logging import pretty_argvalues
37
38
 
38
39
  __all__ = ['AuthFlow', 'LeapAuthFlow', 'OAuthError']
39
40
 
@@ -28,14 +28,16 @@ import click
28
28
  import requests.exceptions
29
29
 
30
30
  import dwave.cloud
31
- from dwave.cloud import Client, configure_logging
31
+ from dwave.cloud import Client
32
32
  from dwave.cloud import api
33
33
  from dwave.cloud.solver import StructuredSolver, BaseUnstructuredSolver
34
- from dwave.cloud.utils import (
35
- default_text_input, generate_random_ising_problem,
36
- datetime_to_timestamp, utcnow, strtrunc, CLIError, set_loglevel,
37
- get_contrib_packages, user_agent, epochnow,
38
- get_distribution, PackageNotFoundError, VersionNotFoundError)
34
+ from dwave.cloud.utils.cli import default_text_input, strtrunc, CLIError
35
+ from dwave.cloud.utils.dist import (
36
+ get_contrib_packages, get_distribution, PackageNotFoundError, VersionNotFoundError)
37
+ from dwave.cloud.utils.http import user_agent
38
+ from dwave.cloud.utils.logging import configure_logging
39
+ from dwave.cloud.utils.qubo import generate_random_ising_problem
40
+ from dwave.cloud.utils.time import datetime_to_timestamp, utcnow, epochnow
39
41
  from dwave.cloud.coders import bqm_as_file
40
42
  from dwave.cloud.package_info import __title__, __version__
41
43
  from dwave.cloud.exceptions import (
@@ -55,13 +57,11 @@ click.option = partial(click.option, show_default=True)
55
57
 
56
58
  def enable_logging(ctx, param, value):
57
59
  if value and not ctx.resilient_parsing:
58
- configure_logging()
59
- set_loglevel(dwave.cloud.logger, param.name)
60
+ configure_logging(level=param.name)
60
61
 
61
62
  def enable_loglevel(ctx, param, value):
62
63
  if value and not ctx.resilient_parsing:
63
- configure_logging()
64
- set_loglevel(dwave.cloud.logger, value)
64
+ configure_logging(level=value)
65
65
 
66
66
  def show_platform(ctx, param, value):
67
67
  if value and not ctx.resilient_parsing:
@@ -54,7 +54,7 @@ from itertools import chain, zip_longest
54
54
  from functools import partial, wraps
55
55
  from collections import namedtuple
56
56
  from concurrent.futures import ThreadPoolExecutor
57
- from typing import Dict, Optional, Union
57
+ from typing import Dict, Optional
58
58
 
59
59
  import requests
60
60
  import urllib3
@@ -72,9 +72,10 @@ from dwave.cloud.concurrency import PriorityThreadPoolExecutor
72
72
  from dwave.cloud.regions import get_regions, resolve_endpoints
73
73
  from dwave.cloud.upload import ChunkedData
74
74
  from dwave.cloud.events import dispatches_events
75
- from dwave.cloud.utils import (
76
- PretimedHTTPAdapter, BaseUrlSession, default_user_agent,
77
- datetime_to_timestamp, utcnow, cached, retried, is_caused_by)
75
+ from dwave.cloud.utils.http import PretimedHTTPAdapter, BaseUrlSession, default_user_agent
76
+ from dwave.cloud.utils.time import datetime_to_timestamp, utcnow
77
+ from dwave.cloud.utils.decorators import cached, retried
78
+ from dwave.cloud.utils.exception import is_caused_by
78
79
 
79
80
  __all__ = ['Client']
80
81
 
@@ -247,14 +248,14 @@ class Client(object):
247
248
 
248
249
  Instance-level defaults can be specified via ``defaults`` argument.
249
250
 
250
- .. deprecated:: 0.10.0
251
- Positional arguments in :class:`.Client` constructor are deprecated and
252
- will be removed in 0.12.0.
253
-
254
251
  .. deprecated:: 0.11.0
255
252
  Config attributes on :class:`.Client` are deprecated in favor of config
256
253
  model attributes available on ``Client.config`` and will be removed
257
- in 0.12.0.
254
+ in 0.13.0.
255
+
256
+ .. versionremoved:: 0.12.0
257
+ Positional arguments in :class:`.Client` constructor, deprecated in 0.10.0,
258
+ are removed in 0.12.0. Use keyword arguments instead.
258
259
 
259
260
  Examples:
260
261
  This example directly initializes a :class:`.Client`.
@@ -358,7 +359,7 @@ class Client(object):
358
359
  def _legacy_config_property_proxy(self, legacy_property, config_path):
359
360
  warnings.warn(
360
361
  f"`Client.{legacy_property}` property is deprecated since "
361
- f"dwave-cloud-client 0.11.0, and will be removed in 0.12.0. "
362
+ f"dwave-cloud-client 0.11.0, and will be removed in 0.13.0. "
362
363
  f"Use `Client.config.{config_path}` instead.",
363
364
  DeprecationWarning, stacklevel=2)
364
365
  return pluck(self.config, config_path)
@@ -434,27 +435,7 @@ class Client(object):
434
435
  return _clients[_client](**config)
435
436
 
436
437
  @dispatches_events('client_init')
437
- def __init__(self, *args, **kwargs):
438
- # for (reasonable) backwards compatibility, accept only the first few
439
- # positional args.
440
- if len(args) > 3:
441
- raise TypeError(
442
- "Client constructor takes up to 3 positional "
443
- f"arguments, but {len(args)} were given")
444
-
445
- if len(args) > 0:
446
- warnings.warn(
447
- "Positional arguments in Client constructor are deprecated "
448
- "since dwave-cloud-client 0.10.0, and will be removed in 0.12.0. "
449
- "Use keyword arguments instead.",
450
- DeprecationWarning, stacklevel=3)
451
-
452
- argsdict = dict(zip(('endpoint', 'token', 'solver'), args))
453
- intersection = argsdict.keys() & kwargs
454
- if intersection:
455
- raise TypeError(f"Client() got multiple values for {intersection}")
456
- kwargs.update(argsdict)
457
-
438
+ def __init__(self, **kwargs):
458
439
  logger.debug("Client init called with: %r", kwargs)
459
440
 
460
441
  # insert deprecated config properties that proxy values from the new `Client.config`
@@ -14,20 +14,43 @@
14
14
 
15
15
  import struct
16
16
  import base64
17
- from typing import Callable
17
+ from typing import Callable, Dict, List, Tuple, Union
18
18
 
19
- from dwave.cloud.utils import uniform_get, active_qubits
19
+ try:
20
+ # note: TypedDict is available in py38+, but NotRequired only in py311+
21
+ from typing import NotRequired, TypedDict
22
+ except ImportError:
23
+ from typing_extensions import NotRequired, TypedDict
24
+
25
+ from dwave.cloud.utils.qubo import uniform_get, active_qubits
20
26
 
21
27
  __all__ = [
22
- 'encode_problem_as_qp', 'decode_qp', 'decode_qp_numpy',
28
+ 'encode_problem_as_qp', 'decode_qp', 'decode_qp_numpy', 'decode_qp_problem',
23
29
  'encode_problem_as_bq', 'decode_bq',
24
30
  'encode_problem_as_ref', 'decode_binary_ref',
25
31
  'bqm_as_file',
26
32
  ]
27
33
 
28
34
 
29
- def encode_problem_as_qp(solver, linear, quadratic, offset=0,
30
- undirected_biases=False):
35
+ # a plain dict version of `dwave.cloud.api.models.StructuredProblemData`
36
+ class EncodedQP(TypedDict):
37
+ format: str
38
+ lin: str
39
+ quad: str
40
+ offset: NotRequired[float]
41
+
42
+ class QuadraticProblem(TypedDict):
43
+ linear: Dict[int, float]
44
+ quadratic: Dict[Tuple[int, int], float]
45
+ offset: NotRequired[float]
46
+
47
+
48
+ def encode_problem_as_qp(solver: 'dwave.cloud.solver.StructuredSolver',
49
+ linear: Union[List[float], Dict[int, float]],
50
+ quadratic: Dict[Tuple[int, int], float],
51
+ offset: float = 0,
52
+ undirected_biases: bool = False
53
+ ) -> EncodedQP:
31
54
  """Encode the binary quadratic problem for submission to a given solver,
32
55
  using the `qp` format for data.
33
56
 
@@ -90,6 +113,34 @@ def encode_problem_as_qp(solver, linear, quadratic, offset=0,
90
113
  }
91
114
 
92
115
 
116
+ def decode_qp_problem(solver: 'dwave.cloud.solver.StructuredSolver',
117
+ qp: EncodedQP,
118
+ undirected_edges: bool = True
119
+ ) -> QuadraticProblem:
120
+ """Decode quadratic unconstrained binary problem encoded using SAPI's
121
+ ``qp`` format."""
122
+
123
+ encoding_qubits = solver._encoding_qubits
124
+ encoding_couplers = solver._encoding_couplers
125
+
126
+ lin = base64.decodebytes(qp['lin'].encode('ascii'))
127
+ lin = struct.unpack('<' + ('d' * int(len(lin)/8)), lin)
128
+ linear = {qubit: lin[idx] for idx, qubit in enumerate(encoding_qubits)}
129
+
130
+ quad = base64.decodebytes(qp['quad'].encode('ascii'))
131
+ quad = struct.unpack('<' + ('d' * int(len(quad)/8)), quad)
132
+ quadratic = {(q1,q2): quad[idx] for idx, (q1,q2) in enumerate(encoding_couplers)}
133
+
134
+ # return quadratic as upper triangular (regardless of encoding couplers)
135
+ if undirected_edges:
136
+ quadratic = {(q1,q2): quadratic.get((q1,q2), 0) + quadratic.get((q2,q1), 0)
137
+ for (q1,q2) in solver.undirected_edges}
138
+
139
+ offset = qp.get('offset', 0.0)
140
+
141
+ return QuadraticProblem(linear=linear, quadratic=quadratic, offset=offset)
142
+
143
+
93
144
  def decode_qp(msg):
94
145
  """Decode SAPI response that uses `qp` format, without numpy.
95
146
 
@@ -34,11 +34,9 @@ import weakref
34
34
 
35
35
  from concurrent.futures import TimeoutError
36
36
  from dateutil.parser import parse
37
- from operator import itemgetter
38
37
 
39
- from dwave.cloud.utils import (
40
- utcnow, datetime_to_timestamp, aliasdict, deprecated)
41
38
  from dwave.cloud.exceptions import InvalidAPIResponseError
39
+ from dwave.cloud.utils.time import utcnow, datetime_to_timestamp
42
40
 
43
41
  # Use numpy if available for fast decoding
44
42
  try:
@@ -566,21 +564,21 @@ class Future(object):
566
564
  `'num_occurrences'`. Better yet, use :meth:`Future.samples` and
567
565
  :meth:`Future.num_occurrences` instead.
568
566
 
569
- .. deprecated:: 0.8.0
570
-
571
- Alias keys ``samples`` and ``occurrences`` in the result dict are
572
- deprecated and will be removed in 0.12.0. We'll try to keep the
573
- result dict as close to raw data returned by SAPI as possible.
574
- Postprocessed data is available via
575
- :class:`~dwave.cloud.computation.Future` properties.
576
-
577
567
  .. versionchanged:: 0.8.0
578
568
 
579
569
  Instead of adding copies of ``solutions`` and ``num_occurrences``
580
570
  keys (as ``samples`` and ``occurrences``), we alias them using
581
- :class:`~dwave.cloud.utils.aliasdict`. Values are available under
571
+ :class:`~dwave.cloud.utils.decorators.aliasdict`. Values are available under
582
572
  alias keys, but the keys themselves are not stored or visible.
583
573
 
574
+ .. versionremoved:: 0.12.0
575
+
576
+ Alias keys ``samples`` and ``occurrences`` in the result dict,
577
+ deprecated in 0.8.0, are removed in 0.12.0. We'll try to keep the
578
+ result dict as close to raw data returned by SAPI as possible.
579
+ Postprocessed data is available via
580
+ :class:`~dwave.cloud.computation.Future` properties.
581
+
584
582
  Examples:
585
583
  This example creates a solver using the local system's default
586
584
  D-Wave Cloud Client configuration file, submits a simple QUBO
@@ -916,7 +914,6 @@ class Future(object):
916
914
  # extract results from the response
917
915
  # note: decoding might mutate `self._message`, so it should be only called once
918
916
  self._decode()
919
- self._alias_result()
920
917
 
921
918
  # signal answer data downloaded
922
919
  if 'answer' in self._result:
@@ -962,25 +959,10 @@ class Future(object):
962
959
  self.parse_time = time.time() - start
963
960
  return self._result
964
961
 
965
- def _alias_result(self):
966
- """Alias `solutions` and `num_occurrences`.
967
-
968
- Deprecated in version 0.8.0.
969
-
970
- Scheduled for removal in 0.12.0.
971
- """
972
- if not self._result:
973
- return
974
-
975
- msg = "'{}' alias has been deprecated in favor of '{}'"
976
- samples_msg = msg.format('samples', 'solutions')
977
- occurrences_msg = msg.format('occurrences', 'num_occurrences')
978
-
979
- aliases = dict(
980
- samples=deprecated(samples_msg)(itemgetter('solutions')),
981
- occurrences=deprecated(occurrences_msg)(itemgetter('num_occurrences')))
982
-
983
- self._result = aliasdict(self._result)
984
- self._result.alias(aliases)
985
-
986
- return self._result
962
+ def __del__(self):
963
+ # note: here we close the answer buffer (typically a file on disk)
964
+ # even though it's closed by a file destructor anyway just for explicitness sake.
965
+ # TODO: consider lazy answer data download, so that the buffer/file can be released
966
+ # immediately after use.
967
+ if self._answer_data is not None:
968
+ self._answer_data.close()
@@ -14,7 +14,7 @@
14
14
 
15
15
  __packagename__ = 'dwave-cloud-client'
16
16
  __title__ = 'D-Wave Cloud Client'
17
- __version__ = '0.12.0.dev0'
17
+ __version__ = '0.12.1'
18
18
  __author__ = 'D-Wave Systems Inc.'
19
19
  __description__ = 'A minimal client for interacting with D-Wave cloud resources.'
20
20
  __url__ = 'https://github.com/dwavesystems/dwave-cloud-client'
@@ -25,7 +25,7 @@ from dwave.cloud.api.constants import (
25
25
  DEFAULT_REGION, DEFAULT_SOLVER_API_ENDPOINT, DEFAULT_LEAP_API_ENDPOINT,
26
26
  DEFAULT_METADATA_API_ENDPOINT)
27
27
  from dwave.cloud.config.models import ClientConfig, validate_config_v1
28
- from dwave.cloud.utils import cached
28
+ from dwave.cloud.utils.decorators import cached
29
29
 
30
30
  __all__ = ['get_regions']
31
31
 
@@ -44,14 +44,15 @@ from dwave.cloud.exceptions import (
44
44
  from dwave.cloud.coders import (
45
45
  encode_problem_as_qp, encode_problem_as_ref, decode_binary_ref,
46
46
  decode_qp_numpy, decode_qp, decode_bq, bqm_as_file)
47
- from dwave.cloud.utils import reformat_qubo_as_ising, NumpyEncoder
48
47
  from dwave.cloud.computation import Future
49
48
  from dwave.cloud.concurrency import Present
50
49
  from dwave.cloud.events import dispatches_events
50
+ from dwave.cloud.utils.coders import NumpyEncoder
51
+ from dwave.cloud.utils.qubo import reformat_qubo_as_ising
51
52
 
52
53
  # Use numpy if available for fast encoding/decoding
53
54
  try:
54
- import numpy as np
55
+ import numpy
55
56
  _numpy = True
56
57
  except ImportError:
57
58
  _numpy = False
@@ -392,7 +393,7 @@ class BaseUnstructuredSolver(BaseSolver):
392
393
  Optional problem encoding and upload parameters.
393
394
 
394
395
  Returns:
395
- :class:`concurrent.futures.Future`[str]:
396
+ :class:`concurrent.futures.Future`\ [str]:
396
397
  Problem ID in a Future. Problem ID can be used to submit
397
398
  problems by reference.
398
399
  """
@@ -553,19 +554,19 @@ class BQMSolver(BaseUnstructuredSolver):
553
554
  return self.sample_problem(bqm, label=label, **params)
554
555
 
555
556
  def upload_bqm(self, bqm):
556
- """Upload the specified :term:`BQM` to SAPI, returning a Problem ID
557
+ r"""Upload the specified :term:`BQM` to SAPI, returning a Problem ID
557
558
  that can be used to submit the BQM to this solver (i.e. call the
558
- `.sample_bqm` method).
559
+ :meth:`~BQMSolver.sample_bqm` method).
559
560
 
560
561
  Args:
561
- bqm (:class:`~dimod.BinaryQuadraticModel`/bytes-like/file-like):
562
+ bqm (:class:`~dimod.binary.BinaryQuadraticModel`\ /bytes-like/file-like):
562
563
  A binary quadratic model given either as an in-memory
563
- :class:`~dimod.BinaryQuadraticModel` object, or as raw data
564
+ :class:`~dimod.binary.BinaryQuadraticModel` object, or as raw data
564
565
  (encoded serialized model) in either a file-like or a bytes-like
565
566
  object.
566
567
 
567
568
  Returns:
568
- :class:`concurrent.futures.Future`[str]:
569
+ :class:`concurrent.futures.Future`\ [str]:
569
570
  Problem ID in a Future. Problem ID can be used to submit
570
571
  problems by reference.
571
572
 
@@ -593,6 +594,30 @@ class DQMSolver(BaseUnstructuredSolver):
593
594
  _handled_problem_types = {"dqm"}
594
595
  _handled_encoding_formats = {"bq"}
595
596
 
597
+ @staticmethod
598
+ def _bqm_to_dqm(bqm):
599
+ """Represent a :class:`dimod.BQM` as a :class:`dimod.DQM`."""
600
+ try:
601
+ from dimod import DiscreteQuadraticModel
602
+ except ImportError: # pragma: no cover
603
+ raise RuntimeError(
604
+ "dimod package with support for DiscreteQuadraticModel required."
605
+ "Re-install the library with 'dqm' support.")
606
+
607
+ dqm = DiscreteQuadraticModel()
608
+
609
+ ising = bqm.spin
610
+
611
+ for v, bias in ising.linear.items():
612
+ dqm.add_variable(2, label=v)
613
+ dqm.set_linear(v, [-bias, bias])
614
+
615
+ for (u, v), bias in ising.quadratic.items():
616
+ biases = numpy.array([[bias, -bias], [-bias, bias]], dtype=numpy.float64)
617
+ dqm.set_quadratic(u, v, biases)
618
+
619
+ return dqm
620
+
596
621
  def _encode_problem_for_upload(self, dqm):
597
622
  try:
598
623
  data = dqm.to_file()
@@ -607,10 +632,9 @@ class DQMSolver(BaseUnstructuredSolver):
607
632
 
608
633
  def sample_bqm(self, bqm, label=None, **params):
609
634
  """Use for testing."""
610
- from dwave.cloud.utils import bqm_to_dqm
611
635
 
612
636
  # to sample BQM problems, we need to convert them to DQM
613
- dqm = bqm_to_dqm(bqm)
637
+ dqm = self._bqm_to_dqm(bqm)
614
638
 
615
639
  # TODO: convert sampleset back
616
640
  return self.sample_dqm(dqm, label=label, **params)
@@ -651,7 +675,7 @@ class DQMSolver(BaseUnstructuredSolver):
651
675
  object.
652
676
 
653
677
  Returns:
654
- :class:`concurrent.futures.Future`[str]:
678
+ :class:`concurrent.futures.Future`\ [str]:
655
679
  Problem ID in a Future. Problem ID can be used to submit
656
680
  problems by reference.
657
681
 
@@ -739,7 +763,7 @@ class CQMSolver(BaseUnstructuredSolver):
739
763
  object.
740
764
 
741
765
  Returns:
742
- :class:`concurrent.futures.Future`[str]:
766
+ :class:`concurrent.futures.Future`\ [str]:
743
767
  Problem ID in a Future. Problem ID can be used to submit
744
768
  problems by reference.
745
769
 
@@ -885,7 +909,7 @@ class NLSolver(BaseUnstructuredSolver):
885
909
  like ``max_num_states``.
886
910
 
887
911
  Returns:
888
- :class:`concurrent.futures.Future`[str]:
912
+ :class:`concurrent.futures.Future`\ [str]:
889
913
  Problem ID in a Future. Problem ID can be used to submit
890
914
  problems by reference.
891
915
 
@@ -1502,9 +1526,9 @@ class StructuredSolver(BaseSolver):
1502
1526
  q = readout_time_model_parameters[:n//2]
1503
1527
  t = readout_time_model_parameters[n//2:]
1504
1528
  if readout_time_model == 'pwl_log_log':
1505
- readout_time = pow(10, np.interp(np.emath.log10(num_qubits), q, t))
1529
+ readout_time = pow(10, numpy.interp(numpy.emath.log10(num_qubits), q, t))
1506
1530
  elif readout_time_model == 'pwl_linear':
1507
- readout_time = np.interp(num_qubits, q, t)
1531
+ readout_time = numpy.interp(num_qubits, q, t)
1508
1532
  else:
1509
1533
  raise ValueError("``estimate_qpu_access_time`` does not support "
1510
1534
  f"``readout_time_model`` value {readout_time_model} "