Skip to content

Commit

Permalink
moved import on top and exception handling in sample_dqm
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdullahjavednesar committed Mar 1, 2022
1 parent dc53ec4 commit ff432b4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions dwave/system/samplers/leap_hybrid_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

bqm_to_file = FileView

from dimod.discrete.discrete_quadratic_model import DiscreteQuadraticModel
from dwave.cloud import Client
from dwave.system.utilities import classproperty, FeatureFlags

Expand Down Expand Up @@ -465,6 +466,8 @@ def sample_dqm(self, dqm, time_limit=None, compress=False, compressed=None, **kw
See the example in :class:`LeapHybridDQMSampler`.
"""
if not isinstance(dqm, DiscreteQuadraticModel):
raise TypeError(f"Expecting DiscreteQuadraticModel object, got {type(dqm)}")
if time_limit is None:
time_limit = self.min_time_limit(dqm)
elif time_limit < self.min_time_limit(dqm):
Expand Down Expand Up @@ -533,12 +536,8 @@ def min_time_limit(self, dqm):
first two pairs that represent problems with "density" between 1 to
100).
"""
from dimod.discrete.discrete_quadratic_model import DiscreteQuadraticModel
if isinstance(dqm, DiscreteQuadraticModel):
ec = (dqm.num_variable_interactions() * dqm.num_cases() /
max(dqm.num_variables(), 1))
else:
raise TypeError(f"Expecting DiscreteQuadraticModel object, got {type(dqm)}")
ec = (dqm.num_variable_interactions() * dqm.num_cases() /
max(dqm.num_variables(), 1))
limits = np.array(self.properties['minimum_time_limit'])
t = np.interp(ec, limits[:, 0], limits[:, 1])
return max([5, t])
Expand Down

0 comments on commit ff432b4

Please sign in to comment.