code: def spin_to_binary(linear, quadratic, offset):
          
  
          # the linear biases are the easiest
          new_linear = {v: 2. * bias for v, bias in iteritems(linear)}
  
          # next the quadratic biases
          new_quadratic = {}
          for (u, v), bias in iteritems(quadratic):
              new_quadratic[(u, v)] = 4. * bias
              new_linear[u] -= 2. * bias
              new_linear[v] -= 2. * bias
  
          # finally calculate the offset
          offset += sum(itervalues(quadratic)) - sum(itervalues(linear))
  
          return new_linear, new_quadratic, offset
docs: convert linear, quadratic, and offset from spin to binary.
          Does no checking of vartype. Copies all of the values into new objects.