Skip to content

Commit

Permalink
Merge pull request #211 from randomir/master
Browse files Browse the repository at this point in the history
Allow experimental parameters to pass through
  • Loading branch information
randomir authored Jul 9, 2018
2 parents dfd751f + 2f1511a commit 5e51f2b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 1 addition & 9 deletions dwave/cloud/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class Solver(object):
"""

# Special flag to notify the system a solver needs access to special hardware
_PARAMETER_ENABLE_HARDWARE = 'use_hardware'

# Classes of problems the remote solver has to support (at least one of these)
# in order for `Solver` to be able to abstract, or use, that solver
_HANDLED_PROBLEM_TYPES = {"ising", "qubo"}
Expand Down Expand Up @@ -126,11 +123,6 @@ def __init__(self, client, data):
# Create a set of default parameters for the queries
self._params = {}

# As a heuristic to guess if this is a hardware sampler check if
# the 'annealing_time_range' property is set.
if 'annealing_time_range' in self.properties:
self._params[self._PARAMETER_ENABLE_HARDWARE] = True

def __repr__(self):
return "Solver(id={!r})".format(self.id)

Expand Down Expand Up @@ -259,7 +251,7 @@ def _sample(self, type_, linear, quadratic, params):

# Check the parameters before submitting
for key in combined_params:
if key not in self.parameters and key != self._PARAMETER_ENABLE_HARDWARE:
if key not in self.parameters and not key.startswith('x_'):
raise KeyError("{} is not a parameter of this solver.".format(key))

body = json.dumps({
Expand Down
10 changes: 9 additions & 1 deletion tests/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from dwave.cloud.utils import evaluate_ising
from dwave.cloud.qpu import Client
from dwave.cloud.exceptions import CanceledFutureError
from dwave.cloud.exceptions import CanceledFutureError, SolverFailureError
import dwave.cloud.computation

from tests import config
Expand Down Expand Up @@ -44,6 +44,14 @@ def test_submit_invalid_parameter(self):
with self.assertRaises(KeyError):
solver.sample_ising({}, {}, not_a_parameter=True)

def test_submit_experimental_parameter(self):
"""Ensure that the experimental parameters are populated."""
with Client(**config) as client:
solver = client.get_solver()
assert 'x_test' not in solver.parameters
with self.assertRaises(SolverFailureError):
self.assertTrue(solver.sample_ising([0], {}, x_test=123).result())

def test_read_connectivity(self):
"""Ensure that the edge set is populated."""
with Client(**config) as client:
Expand Down

0 comments on commit 5e51f2b

Please sign in to comment.