Repository: dwavesystems/dimod

Issue:
Allow scaling of subset of bqm biases
**Application**
In the case of embedded bqm's, it would be useful to be able to scale the original biases without scaling the chain biases

**Proposed Solution/Alternatives Considered**
Pattern A:
```
bqm.lock_interactions([('a', 'b'), ('b', 'c')])
bqm.scale(.5)
```

Pattern B:
```
bqm.scale(.5, exclude_interactions=[('a', 'b'), ('b', 'c')])
```

@conta877 

Discussion:
arcondello: Specifically looking for feedback on the parameter name
m3ller: Perhaps `ignored_variables` and `ignored_interactions`? I like "ignore" more than "exclude" because "exclude" seems like an active thing you're doing to the list, while "ignore" just means you won't be touching that list.
arcondello: `skip_*` sounds boolean to me. I'll go with `ignored_*`

Patch:
diff --git a/dimod/binary_quadratic_model.py b/dimod/binary_quadratic_model.py
index 27118b1c..c8e57ec2 100644
--- a/dimod/binary_quadratic_model.py
+++ b/dimod/binary_quadratic_model.py
@@ -844,13 +844,19 @@ class BinaryQuadraticModel(Sized, Container, Iterable):
         """
         self.add_offset(-self.offset)
 
-    def scale(self, scalar):
+    def scale(self, scalar, ignored_variables=None, ignored_interactions=None):
         """Multiply by the specified scalar all the biases and offset of a binary quadratic model.
 
         Args:
             scalar (number):
                 Value by which to scale the energy range of the binary quadratic model.
 
+            ignored_variables (iterable, optional):
+                Biases associated with these variables are not scaled.
+
+            ignored_interactions (iterable[tuple], optional):
+                As an iterable of 2-tuples. Biases associated with these interactions are not scaled.
+
         Examples:
 
             This example creates a binary quadratic model and then scales it to half
@@ -871,23 +877,40 @@ class BinaryQuadraticModel(Sized, Container, Iterable):
         if not isinstance(scalar, Number):
             raise TypeError("expected scalar to be a Number")
 
+        if ignored_variables is None:
+            ignored_variables = set()
+        elif not isinstance(ignored_variables, Container):
+            ignored_variables = set(ignored_variables)
+
+        if ignored_interactions is None:
+            ignored_interactions = set()
+        elif not isinstance(ignored_interactions, Container):
+            ignored_interactions = set(ignored_interactions)
+
         linear = self.linear
         for v in linear:
+            if v in ignored_variables:
+                continue
             linear[v] *= scalar
 
         quadratic = self.quadratic
-        for edge in quadratic:
-            quadratic[edge] *= scalar
+        for u, v in quadratic:
+            if (u, v) in ignored_interactions or (v, u) in ignored_interactions:
+                continue
+            quadratic[(u, v)] *= scalar
 
         adj = self.adj
         for u in adj:
             for v in adj[u]:
+                if (u, v) in ignored_interactions or (v, u) in ignored_interactions:
+                    continue
                 adj[u][v] *= scalar
 
         self.offset *= scalar
 
         try:
-            self._counterpart.scale(scalar)
+            self._counterpart.scale(scalar, ignored_variables=ignored_variables,
+                                    ignored_interactions=ignored_interactions)
         except AttributeError:
             pass
 


Test patch:
diff --git a/tests/test_binary_quadratic_model.py b/tests/test_binary_quadratic_model.py
index 16278de4..a64f6b76 100644
--- a/tests/test_binary_quadratic_model.py
+++ b/tests/test_binary_quadratic_model.py
@@ -746,6 +746,17 @@ class TestBinaryQuadraticModel(unittest.TestCase):
         with self.assertRaises(TypeError):
             bqm.scale('a')
 
+    def test_scale_exclusions(self):
+        bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN)
+        bqm.scale(.5, ignored_variables=[0])
+        self.assertConsistentBQM(bqm)
+        self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: -2, 1: 1}, {(0, 1): -.5}, .5, dimod.SPIN))
+
+        bqm = dimod.BinaryQuadraticModel({0: -2, 1: 2}, {(0, 1): -1}, 1., dimod.SPIN)
+        bqm.scale(.5, ignored_interactions=[(1, 0)])
+        self.assertConsistentBQM(bqm)
+        self.assertEqual(bqm, dimod.BinaryQuadraticModel({0: -1, 1: 1}, {(0, 1): -1.}, .5, dimod.SPIN))
+
     def test_fix_variable(self):
         # spin model, fix variable to +1
         bqm = dimod.BinaryQuadraticModel({'a': .3}, {('a', 'b'): -1}, 1.2, dimod.SPIN)