Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy cleanup for 0.8.0 #388

Merged
merged 18 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def iad_add_directive_header(self, sig):


# Link to Python standard lib objects
intersphinx_mapping = {'python': ('https://docs.python.org/3', None),
'qbsolv': ('https://docs.ocean.dwavesys.com/projects/qbsolv/en/latest/', None),
'oceandocs': ('https://docs.ocean.dwavesys.com/en/latest/', None),
'sysdocs_gettingstarted': ('https://docs.dwavesys.com/docs/latest/', None)}
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'numpy': ('https://numpy.org/doc/stable/', None),
'oceandocs': ('https://docs.ocean.dwavesys.com/en/stable/', None),
'sysdocs_gettingstarted': ('https://docs.dwavesys.com/docs/latest/', None),
}
78 changes: 3 additions & 75 deletions docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Configuration
It's recommended you set up your D-Wave Cloud Client configuration through the
:std:doc:`interactive CLI utility <oceandocs:docs_cli>`.

As described in the :std:doc:`Using a D-Wave System <oceandocs:overview/dwavesys>` section
of Ocean Documentation, for your code to access remote D-Wave compute resources, you must
configure communication through SAPI; for example, your code needs your API
As described in the :std:doc:`Configuring Access to D-Wave Solvers <oceandocs:overview/sapi>`
section of Ocean Documentation, for your code to access remote D-Wave compute resources,
you must configure communication through SAPI; for example, your code needs your API
token for authentication. D-Wave Cloud Client provides multiple options for configuring
the required information:

Expand Down Expand Up @@ -166,75 +166,3 @@ A typical workflow may include the following steps:
3. Submit your problem, using your solver, and then process the returned
:class:`~dwave.cloud.computation.Future`, instantiated by your solver to handle
remotely executed problem solving.

Terminology
===========

.. glossary::

Ising
Traditionally used in statistical mechanics. Variables are "spin up"
(:math:`\uparrow`) and "spin down" (:math:`\downarrow`), states that
correspond to :math:`+1` and :math:`-1` values. Relationships between
the spins, represented by couplings, are correlations or anti-correlations.
The objective function expressed as an Ising model is as follows:

.. math::

\begin{equation}
\text{E}_{ising}(\pmb{s}) = \sum_{i=1}^N h_i s_i + \sum_{i=1}^N \sum_{j=i+1}^N J_{i,j} s_i s_j
\end{equation}

where the linear coefficients corresponding to qubit biases
are :math:`h_i`, and the quadratic coefficients corresponding to coupling
strengths are :math:`J_{i,j}`.

model
A collection of variables with associated linear and
quadratic biases.

QUBO
Quadratic unconstrained binary optimization.
QUBO problems are traditionally used in computer science. Variables
are TRUE and FALSE, states that correspond to 1 and 0 values.
A QUBO problem is defined using an upper-diagonal matrix :math:`Q`,
which is an :math:`N` x :math:`N` upper-triangular matrix of real weights,
and :math:`x`, a vector of binary variables, as minimizing the function

.. math::

\begin{equation}
f(x) = \sum_{i} {Q_{i,i}}{x_i} + \sum_{i<j} {Q_{i,j}}{x_i}{x_j}
\end{equation}

where the diagonal terms :math:`Q_{i,i}` are the linear coefficients and
the nonzero off-diagonal terms are the quadratic coefficients
:math:`Q_{i,j}`.
This can be expressed more concisely as

.. math::

\begin{equation}
\min_{{x} \in {\{0,1\}^n}} {x}^{T} {Q}{x}.
\end{equation}

In scalar notation, the objective function expressed as a QUBO
is as follows:

.. math::

\begin{equation}
\text{E}_{qubo}(a_i, b_{i,j}; q_i) = \sum_{i} a_i q_i + \sum_{i<j} b_{i,j} q_i q_j.
\end{equation}

sampler
A process that samples from low energy states of a problem’s objective function.
A binary quadratic model (BQM) sampler samples from low energy states in models such
as those defined by an Ising equation or a Quadratic Unconstrained Binary Optimization
(QUBO) problem and returns an iterable of samples, in order of increasing energy. A dimod
sampler provides ‘sample_qubo’ and ‘sample_ising’ methods as well as the generic
BQM sampler method.

solver
A resource that runs a problem. Some solvers interface to the QPU; others leverage CPU
and GPU resources.
18 changes: 9 additions & 9 deletions dwave/cloud/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
default_text_input, click_info_switch, generate_random_ising_problem,
datetime_to_timestamp, utcnow, strtrunc, CLIError, set_loglevel,
get_contrib_packages, user_agent)
from dwave.cloud.coders import encode_problem_as_bq
from dwave.cloud.coders import bqm_as_file
from dwave.cloud.package_info import __title__, __version__
from dwave.cloud.exceptions import (
SolverAuthenticationError, InvalidAPIResponseError, UnsupportedSolverError,
Expand Down Expand Up @@ -473,8 +473,8 @@ def echo(s, maxlen=100):
help='Connection profile (section) name')
@click.option('--problem-id', '-i', default=None,
help='Problem ID (optional)')
@click.option('--format', '-f', default='bq-zlib',
type=click.Choice(['coo', 'bq-zlib'], case_sensitive=False),
@click.option('--format', '-f', default='dimodbqm',
type=click.Choice(['coo', 'dimodbqm'], case_sensitive=False),
help='Problem data encoding')
@click.argument('input_file', metavar='FILE', type=click.File('rb'))
def upload(config_file, profile, problem_id, format, input_file):
Expand All @@ -495,7 +495,7 @@ def upload(config_file, profile, problem_id, format, input_file):
"in {!r} format.").format(input_file.name, format))

if format == 'coo':
click.echo("Transcoding 'coo' to 'bq-zlib'.")
click.echo("Transcoding 'coo' to 'dimodbqm'.")

try:
import dimod
Expand All @@ -506,17 +506,17 @@ def upload(config_file, profile, problem_id, format, input_file):
# note: `BQM.from_coo` doesn't support files opened in binary (yet);
# fallback to reopen for now
with open(input_file.name, 'rt') as fp:
bqm = dimod.BinaryQuadraticModel.from_coo(fp)
problem = encode_problem_as_bq(bqm, compress=True)['data']
bqm = dimod.AdjVectorBQM.from_coo(fp)
problem_file = bqm_as_file(bqm)

elif format == 'bq-zlib':
problem = input_file
elif format == 'dimodbqm':
problem_file = input_file

click.echo("Uploading...")

try:
future = client.upload_problem_encoded(
problem=problem, problem_id=problem_id)
problem=problem_file, problem_id=problem_id)
remote_problem_id = future.result()
except Exception as e:
click.echo(e)
Expand Down
39 changes: 14 additions & 25 deletions dwave/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import requests
import warnings
import operator
import collections
import queue

import base64
Expand All @@ -58,6 +57,7 @@

from itertools import chain
from functools import partial, wraps
from collections import abc, namedtuple, OrderedDict
from concurrent.futures import ThreadPoolExecutor

from dateutil.parser import parse as parse_datetime
Expand All @@ -66,7 +66,7 @@
from dwave.cloud.package_info import __packagename__, __version__
from dwave.cloud.exceptions import *
from dwave.cloud.computation import Future
from dwave.cloud.config import load_config, legacy_load_config, parse_float
from dwave.cloud.config import load_config, parse_float
from dwave.cloud.solver import Solver, available_solvers
from dwave.cloud.concurrency import PriorityThreadPoolExecutor
from dwave.cloud.upload import ChunkedData
Expand Down Expand Up @@ -186,7 +186,7 @@ class Client(object):
@classmethod
def from_config(cls, config_file=None, profile=None, client=None,
endpoint=None, token=None, solver=None, proxy=None,
headers=None, legacy_config_fallback=False, **kwargs):
headers=None, **kwargs):
"""Client factory method to instantiate a client instance from configuration.

Configuration values can be specified in multiple ways, ranked in the following
Expand Down Expand Up @@ -277,10 +277,6 @@ def from_config(cls, config_file=None, profile=None, client=None,
Newline-separated additional HTTP headers to include with each
API request, or a dictionary of (key, value) pairs.

legacy_config_fallback (bool, default=False):
If True and loading from a standard D-Wave Cloud Client configuration
file (``dwave.conf``) fails, tries loading a legacy configuration file (``~/.dwrc``).

Other Parameters:
Unrecognized keys (str):
All unrecognized keys are passed through to the appropriate client class constructor
Expand Down Expand Up @@ -321,19 +317,6 @@ def from_config(cls, config_file=None, profile=None, client=None,
headers=headers)
logger.debug("Config loaded: %r", config)

# fallback to legacy `.dwrc` if key variables missing
if legacy_config_fallback:
warnings.warn(
"'legacy_config_fallback' is deprecated, and it will be removed "
"in 0.7.0. please convert your legacy .dwrc file to the new "
"config format.", DeprecationWarning)

if not config.get('token'):
config = legacy_load_config(
profile=profile, client=client, endpoint=endpoint,
token=token, solver=solver, proxy=proxy, headers=headers)
logger.debug("Legacy config loaded: %r", config)

# manual override of other (client-custom) arguments
config.update(kwargs)

Expand Down Expand Up @@ -401,7 +384,7 @@ def __init__(self, endpoint=None, token=None, solver=None, proxy=None,
# parse solver
if not solver:
solver_def = {}
elif isinstance(solver, collections.Mapping):
elif isinstance(solver, abc.Mapping):
solver_def = solver
elif isinstance(solver, str):
# support features dict encoded as JSON in our config INI file
Expand All @@ -422,7 +405,7 @@ def __init__(self, endpoint=None, token=None, solver=None, proxy=None,
# parse headers
if not headers:
headers_dict = {}
elif isinstance(headers, collections.Mapping):
elif isinstance(headers, abc.Mapping):
headers_dict = headers
elif isinstance(headers, str):
try:
Expand Down Expand Up @@ -1037,8 +1020,14 @@ def predicate(solver, query, val):
return solvers

def solvers(self, refresh=False, **filters):
"""Deprecated in favor of :meth:`.get_solvers`."""
warnings.warn("'solvers' is deprecated in favor of 'get_solvers'.", DeprecationWarning)
"""Deprecated in favor of :meth:`.get_solvers`.

Scheduled for removal in 0.9.0.
"""
warnings.warn(
"'solvers' is deprecated, and it will be removed "
"in 0.9.0. please convert your code to use 'get_solvers'",
DeprecationWarning)
return self.get_solvers(refresh=refresh, **filters)

def get_solver(self, name=None, refresh=False, **filters):
Expand Down Expand Up @@ -1122,7 +1111,7 @@ def _submit(self, body, future):
This method is thread safe.
"""
self._submission_queue.put(self._submit.Message(body, future))
_submit.Message = collections.namedtuple('Message', ['body', 'future'])
_submit.Message = namedtuple('Message', ['body', 'future'])

def _do_submit_problems(self):
"""Pull problems from the submission queue and submit them.
Expand Down
Loading