dwave.system.composites.ReverseBatchStatesComposite.sample#

ReverseBatchStatesComposite.sample(bqm, initial_states=None, initial_states_generator='random', num_reads=None, seed=None, **parameters)[source]#

Sample the binary quadratic model using reverse annealing from multiple initial states.

Parameters:
  • bqm (BinaryQuadraticModel) – Binary quadratic model to be sampled from.

  • initial_states (samples-like, optional, default=None) – One or more samples, each defining an initial state for all the problem variables. If fewer than num_reads initial states are defined, additional values are generated as specified by initial_states_generator. See dimod.as_samples() for a description of “samples-like”.

  • initial_states_generator ({'none', 'tile', 'random'}, optional, default='random') –

    Defines the expansion of initial_states if fewer than num_reads are specified:

    • ”none”:

      If the number of initial states specified is smaller than num_reads, raises ValueError.

    • ”tile”:

      Reuses the specified initial states if fewer than num_reads or truncates if greater.

    • ”random”:

      Expands the specified initial states with randomly generated states if fewer than num_reads or truncates if greater.

  • num_reads (int, optional, default=len(initial_states) or 1) – Equivalent to number of desired initial states. If greater than the number of provided initial states, additional states will be generated. If not provided, it is selected to match the length of initial_states. If initial_states is not provided, num_reads defaults to 1.

  • seed (int (32-bit unsigned integer), optional) – Seed to use for the PRNG. Specifying a particular seed with a constant set of parameters produces identical results. If not provided, a random seed is chosen.

  • **parameters – Parameters for the sampling method, specified by the child sampler.

Returns:

SampleSet that has an initial_state field.

Examples

This example runs three reverse anneals from two configured and one randomly generated initial states on a problem constructed by setting random \(\pm 1\) values on a clique (complete graph) of 15 nodes, minor-embedded on a D-Wave system using the DWaveCliqueSampler sampler.

>>> import dimod
>>> from dwave.system import DWaveCliqueSampler, ReverseBatchStatesComposite
...
>>> sampler = DWaveCliqueSampler()       
>>> sampler_reverse = ReverseBatchStatesComposite(sampler)   
>>> schedule = [[0.0, 1.0], [10.0, 0.5], [20, 1.0]]
...
>>> bqm = dimod.generators.ran_r(1, 15)
>>> init_samples = [{i: -1 for i in range(15)}, {i: 1 for i in range(15)}]
>>> sampleset = sampler_reverse.sample(bqm,
...                                    anneal_schedule=schedule,
...                                    initial_states=init_samples,
...                                    num_reads=3,
...                                    reinitialize_state=True)