dimod.reference.composites.spin_transform.SpinReversalTransformComposite.sample

SpinReversalTransformComposite.sample(bqm, num_spin_reversal_transforms=2, spin_reversal_variables=None, **kwargs)[source]

Sample from the binary quadratic model.

Parameters:
  • bqm (BinaryQuadraticModel) – Binary quadratic model to be sampled from.
  • num_spin_reversal_transforms (integer, optional, default=2) – Number of spin reversal transform runs.
  • spin_reversal_variables (list/dict, optional) – Deprecated and no longer functional.
Returns:

SampleSet

Examples

This example runs 100 spin reversals applied to one variable of a QUBO problem.

>>> import dimod
...
>>> base_sampler = dimod.ExactSolver()
>>> composed_sampler = dimod.SpinReversalTransformComposite(base_sampler)
>>> Q = {('a', 'a'): -1, ('b', 'b'): -1, ('a', 'b'): 2}
>>> response = composed_sampler.sample_qubo(Q,
...               num_spin_reversal_transforms=100,
...               spin_reversal_variables={'a'})
>>> len(response)
400
>>> print(next(response.data()))           # doctest: +SKIP
Sample(sample={'a': 0, 'b': 1}, energy=-1.0)