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

Handle exception when BQM is passed to DQM sampler #444

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 6 additions & 2 deletions dwave/system/samplers/leap_hybrid_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,12 @@ def min_time_limit(self, dqm):
first two pairs that represent problems with "density" between 1 to
100).
"""
ec = (dqm.num_variable_interactions() * dqm.num_cases() /
max(dqm.num_variables(), 1))
from dimod.discrete.discrete_quadratic_model import DiscreteQuadraticModel
Abdullahjavednesar marked this conversation as resolved.
Show resolved Hide resolved
if isinstance(dqm, DiscreteQuadraticModel):
Abdullahjavednesar marked this conversation as resolved.
Show resolved Hide resolved
ec = (dqm.num_variable_interactions() * dqm.num_cases() /
max(dqm.num_variables(), 1))
else:
raise TypeError(f"Expecting DiscreteQuadraticModel object, got {type(dqm)}")
limits = np.array(self.properties['minimum_time_limit'])
t = np.interp(ec, limits[:, 0], limits[:, 1])
return max([5, t])
Expand Down
4 changes: 4 additions & 0 deletions tests/test_leaphybriddqmsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ def get_solver(self, *args, **kwargs):
sampler = LeapHybridDQMSampler()

dqm = dimod.DQM()
bqm = dimod.BinaryQuadraticModel('SPIN')

with self.assertRaises(ValueError):
sampler.sample_dqm(dqm, time_limit=1)

with self.assertRaises(ValueError):
sampler.sample_dqm(dqm, time_limit=10000000)

with self.assertRaises(TypeError):
sampler.sample_dqm(bqm)

def test_DQM_subclass_without_serialization_can_be_sampled(self):
"""Test that DQM subclasses that do not implement serialization can
still be sampled by LeapHybridDQMSampler.
Expand Down