def sample(self, bqm, init_solution=None, tenure=None, scale_factor=<NUM_LIT:1>, timeout=<NUM_LIT:20>, num_reads=<NUM_LIT:1>):
<EOL>if init_solution is not None:<EOL><INDENT>if not isinstance(init_solution, dimod.SampleSet):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if len(init_solution.record) < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(init_solution.record[<NUM_LIT:0>].sample) != len(bqm):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>init_sample = self._bqm_sample_to_tabu_sample(<EOL>init_solution.change_vartype(dimod.BINARY, inplace=False).record[<NUM_LIT:0>].sample, bqm.binary)<EOL><DEDENT>else:<EOL><INDENT>init_sample = None<EOL><DEDENT>if not bqm:<EOL><INDENT>return dimod.SampleSet.from_samples([], energy=<NUM_LIT:0>, vartype=bqm.vartype)<EOL><DEDENT>if tenure is None:<EOL><INDENT>tenure = max(min(<NUM_LIT:20>, len(bqm) // <NUM_LIT:4>), <NUM_LIT:0>)<EOL><DEDENT>if not isinstance(tenure, int):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if not <NUM_LIT:0> <= tenure < len(bqm):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if not isinstance(num_reads, int):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if num_reads < <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>qubo = self._bqm_to_tabu_qubo(bqm.binary)<EOL>samples = []<EOL>energies = []<EOL>for _ in range(num_reads):<EOL><INDENT>if init_sample is None:<EOL><INDENT>init_sample = self._bqm_sample_to_tabu_sample(self._random_sample(bqm.binary), bqm.binary)<EOL><DEDENT>r = TabuSearch(qubo, init_sample, tenure, scale_factor, timeout)<EOL>sample = self._tabu_sample_to_bqm_sample(list(r.bestSolution()), bqm.binary)<EOL>energy = bqm.binary.energy(sample)<EOL>samples.append(sample)<EOL>energies.append(energy)<EOL><DEDENT>response = dimod.SampleSet.from_samples(<EOL>samples, energy=energies, vartype=dimod.BINARY)<EOL>response.change_vartype(bqm.vartype, inplace=True)<EOL>return response<EOL>
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.

            >>> from tabu import TabuSampler
            >>> import dimod
            >>> sampler = TabuSampler()
            >>> Q = {(0, 0): -1, (1, 1): -1, (0, 1): 2}
            >>> bqm = dimod.BinaryQuadraticModel.from_qubo(Q, offset=0.0)
            >>> samples = sampler.sample(bqm)
            >>> samples.record[0].energy
            -1.0