code: def flip_variable(self, v):
          
          adj = self.adj
          linear = self.linear
          quadratic = self.quadratic
  
          if v not in adj:
              return
  
          if self.vartype is Vartype.SPIN:
              # in this case we just multiply by -1
              linear[v] *= -1.
              for u in adj[v]:
                  adj[v][u] *= -1.
                  adj[u][v] *= -1.
  
                  if (u, v) in quadratic:
                      quadratic[(u, v)] *= -1.
                  elif (v, u) in quadratic:
                      quadratic[(v, u)] *= -1.
                  else:
                      raise RuntimeError("quadratic is missing an interaction")
  
          elif self.vartype is Vartype.BINARY:
              self.offset += linear[v]
              linear[v] *= -1
  
              for u in adj[v]:
                  bias = adj[v][u]
  
                  adj[v][u] *= -1.
                  adj[u][v] *= -1.
  
                  linear[u] += bias
  
                  if (u, v) in quadratic:
                      quadratic[(u, v)] *= -1.
                  elif (v, u) in quadratic:
                      quadratic[(v, u)] *= -1.
                  else:
                      raise RuntimeError("quadratic is missing an interaction")
  
          else:
              raise RuntimeError("Unexpected vartype")
  
          try:
              self._counterpart.flip_variable(v)
          except AttributeError:
              pass
docs: Flip variable v in a binary quadratic model.
  
          Args:
              v (variable):
                  Variable in the binary quadratic model. If v is not in the binary
                  quadratic model, it is ignored.
  
          Examples:
              This example creates a binary quadratic model with two variables and inverts
              the value of one.
  
              >>> import dimod
              ...
              >>> bqm = dimod.BinaryQuadraticModel({1: 1, 2: 2}, {(1, 2): 0.5}, 0.5, dimod.SPIN)
              >>> bqm.flip_variable(1)
              >>> bqm.linear[1], bqm.linear[2], bqm.quadratic[(1, 2)]
              (-1.0, 2, -0.5)