diff --git a/dwave/system/samplers/leap_hybrid_sampler.py b/dwave/system/samplers/leap_hybrid_sampler.py index fb331a39..a466e4c3 100644 --- a/dwave/system/samplers/leap_hybrid_sampler.py +++ b/dwave/system/samplers/leap_hybrid_sampler.py @@ -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 @@ -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): diff --git a/tests/test_leaphybriddqmsolver.py b/tests/test_leaphybriddqmsolver.py index 28ce1335..22adad26 100644 --- a/tests/test_leaphybriddqmsolver.py +++ b/tests/test_leaphybriddqmsolver.py @@ -54,6 +54,7 @@ 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) @@ -61,6 +62,9 @@ def get_solver(self, *args, **kwargs): 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.