code: def samples(self, n=None, sorted_by='energy'):
          if n is not None:
              return self.samples(sorted_by=sorted_by)[:n]
          if sorted_by is None:
              samples = self.record.sample
          else:
              order = np.argsort(self.record[sorted_by])
              samples = self.record.sample[order]
          return SamplesArray(samples, self.variables)