Repository: dwavesystems/dwave-system

Issue:
Warning "Some quadratic biases are stronger than the given chain strength" comes up even when there are no chains
The warning is showing up on the bottom, even on a 2-qubit problem with no chains.Please use this code:

import dimod
import dwave.inspector
from dwave.system import DWaveSampler, EmbeddingComposite

Q = {(0, 0): 1, (1, 1): 1, (0, 1): -2}

bqm = dimod.BinaryQuadraticModel.from_qubo(Q)
sampler = EmbeddingComposite(DWaveSampler())
sampleset = sampler.sample(bqm, num_reads=1000)
dwave.inspector.show(bqm, sampleset, sampler)

Discussion:

Patch:
diff --git a/dwave/system/composites/embedding.py b/dwave/system/composites/embedding.py
index 5c4e60d..060906b 100644
--- a/dwave/system/composites/embedding.py
+++ b/dwave/system/composites/embedding.py
@@ -235,7 +235,7 @@ class EmbeddingComposite(dimod.ComposedSampler):
 
         warninghandler = WarningHandler(warnings)
 
-        warninghandler.chain_strength(bqm, chain_strength)
+        warninghandler.chain_strength(bqm, chain_strength, embedding)
         warninghandler.chain_length(embedding)
 
         if bqm and not embedding:
diff --git a/dwave/system/warnings.py b/dwave/system/warnings.py
index fac3baf..e646ce3 100644
--- a/dwave/system/warnings.py
+++ b/dwave/system/warnings.py
@@ -174,12 +174,18 @@ class WarningHandler(object):
                                      sample_index=row),
                            )
 
-    def chain_strength(self, bqm, chain_strength):
+    def chain_strength(self, bqm, chain_strength, embedding=None):
         """Issues a warning when any quadratic biases are greater than the given
         chain strength."""
         if as_action(self.action) is IGNORE:
             return
 
+        if embedding is not None:
+            if not embedding or all(len(chain) <= 1 for chain in embedding.values()):
+                # the chains are all length 1 so don't have to worry about
+                # strength
+                return
+
         interactions = [uv for uv, bias in bqm.quadratic.items()
                         if abs(bias) >= chain_strength]
 


Test patch:
diff --git a/tests/test_embedding_composite.py b/tests/test_embedding_composite.py
index b00a740..bec8048 100644
--- a/tests/test_embedding_composite.py
+++ b/tests/test_embedding_composite.py
@@ -296,7 +296,8 @@ class TestEmbeddingComposite(unittest.TestCase):
         sampler = EmbeddingComposite(
             dimod.StructureComposite(dimod.RandomSampler(), G.nodes, G.edges))
 
-        J = {(0, 1): 100}
+        # use a triangle so there is a chain of length 2
+        J = {(0, 1): 100, (1, 2): 100, (0, 2): 1}
 
         ss = sampler.sample_ising({}, J, warnings='SAVE')
         self.assertIn('warnings', ss.info)
@@ -307,6 +308,24 @@ class TestEmbeddingComposite(unittest.TestCase):
                 count += 1
         self.assertEqual(count, 1)
 
+    def test_warnings_chain_strength_len1(self):
+        G = dnx.chimera_graph(12)
+
+        sampler = EmbeddingComposite(
+            dimod.StructureComposite(dimod.RandomSampler(), G.nodes, G.edges))
+
+        J = {(0, 1): 100}
+
+        ss = sampler.sample_ising({}, J, warnings='SAVE')
+        self.assertIn('warnings', ss.info)
+
+        # should have no chain length
+        count = 0
+        for warning in ss.info['warnings']:
+            if issubclass(warning['type'], ChainStrengthWarning):
+                count += 1
+        self.assertEqual(count, 0)
+
     def test_warnings_as_class_variable(self):
         G = dnx.chimera_graph(12)