<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sample(self, bqm, init_solution=None, tenure=None, scale_factor=1, timeout=20, num_reads=1):
 """Run a tabu search on a given binary quadratic model. Args: bqm (:obj:`~dimod.BinaryQuadraticModel`):
 The binary quadratic model (BQM) to be sampled. init_solution (:obj:`~dimod.SampleSet`, optional):
 Single sample that sets an initial state for all the problem variables. Default is a random initial state. tenure (int, optional):
 Tabu tenure, which is the length of the tabu list, or number of recently explored solutions kept in memory. Default is a quarter of the number of problem variables up to a maximum value of 20. scale_factor (number, optional):
 Scaling factor for linear and quadratic biases in the BQM. Internally, the BQM is converted to a QUBO matrix, and elements are stored as long ints using ``internal_q = long int (q * scale_factor)``. timeout (int, optional):
 Total running time in milliseconds. num_reads (int, optional):
 Number of reads. Each run of the tabu algorithm generates a sample. Returns: :obj:`~dimod.SampleSet`: A `dimod` :obj:`.~dimod.SampleSet` object. Examples: This example provides samples for a two-variable QUBO model. -1.0 """


        # input checking and defaults calculation
        # TODO: one "read" per sample in init_solution sampleset
        if init_solution is not None:
            if not isinstance(init_solution, dimod.SampleSet):
                raise TypeError("'init_solution' should be a 'dimod.SampleSet' instance")
            if len(init_solution.record) < 1:
                raise ValueError("'init_solution' should contain at least one sample")
            if len(init_solution.record[0].sample) != len(bqm):
                raise ValueError("'init_solution' sample dimension different from BQM")
            init_sample = self._bqm_sample_to_tabu_sample(
                init_solution.change_vartype(dimod.BINARY, inplace=False).record[0].sample, bqm.binary)
        else:
            init_sample = None

        if not bqm:
            return dimod.SampleSet.from_samples([], energy=0, vartype=bqm.vartype)

        if tenure is None:
            tenure = max(min(20, len(bqm) // 4), 0)
        if not isinstance(tenure, int):
            raise TypeError("'tenure' should be an integer in range [0, num_vars - 1]")
        if not 0 <= tenure < len(bqm):
            raise ValueError("'tenure' should be an integer in range [0, num_vars - 1]")

        if not isinstance(num_reads, int):
            raise TypeError("'num_reads' should be a positive integer")
        if num_reads < 1:
            raise ValueError("'num_reads' should be a positive integer")

        qubo = self._bqm_to_tabu_qubo(bqm.binary)

        # run Tabu search
        samples = []
        energies = []
        for _ in range(num_reads):
            if init_sample is None:
                init_sample = self._bqm_sample_to_tabu_sample(self._random_sample(bqm.binary), bqm.binary)
            r = TabuSearch(qubo, init_sample, tenure, scale_factor, timeout)
            sample = self._tabu_sample_to_bqm_sample(list(r.bestSolution()), bqm.binary)
            energy = bqm.binary.energy(sample)
            samples.append(sample)
            energies.append(energy)

        response = dimod.SampleSet.from_samples(
            samples, energy=energies, vartype=dimod.BINARY)
        response.change_vartype(bqm.vartype, inplace=True)
        return response