code: def sample(self, bqm):
          
          M = bqm.binary.to_numpy_matrix()
          off = bqm.binary.offset
  
          if M.shape == (0, 0):
              return SampleSet.from_samples([], bqm.vartype, energy=[])
  
          sample = np.zeros((len(bqm),), dtype=bool)
  
          # now we iterate, flipping one bit at a time until we have
          # traversed all samples. This is a Gray code.
          # https://en.wikipedia.org/wiki/Gray_code
          def iter_samples():
              sample = np.zeros((len(bqm)), dtype=bool)
              energy = 0.0
  
              yield sample.copy(), energy + off
  
              for i in range(1, 1 << len(bqm)):
                  v = _ffs(i)
  
                  # flip the bit in the sample
                  sample[v] = not sample[v]
  
                  # for now just calculate the energy, but there is a more clever way by calculating
                  # the energy delta for the single bit flip, don't have time, pull requests
                  # appreciated!
                  energy = sample.dot(M).dot(sample.transpose())
  
                  yield sample.copy(), float(energy) + off
  
          samples, energies = zip(*iter_samples())
  
          response = SampleSet.from_samples(np.array(samples, dtype='int8'), Vartype.BINARY, energies)
  
          # make sure the response matches the given vartype, in-place.
          response.change_vartype(bqm.vartype, inplace=True)
  
          return response
docs: Sample from a binary quadratic model.
  
          Args:
              bqm (:obj:`~dimod.BinaryQuadraticModel`):
                  Binary quadratic model to be sampled from.
  
          Returns:
              :obj:`~dimod.SampleSet`