Dimod Conversion#
These classes handle conversion between dwave-hybrid Runnable
classes and dimod samplers.
Classes#
- class HybridSampler(workflow)[source]#
Produces a dimod.Sampler from a hybrid.Runnable-based sampler.
- Parameters:
workflow (Runnable) – Hybrid workflow, likely composed, that accepts a binary quadratic model in the input state and produces sample(s) in the output state.
Example
This example produces a dimod sampler from
TabuProblemSampler
and uses its sample_ising mixin to solve a simple Ising problem.>>> hybrid_sampler = TabuProblemSampler() >>> dimod_sampler = HybridSampler(hybrid_sampler) >>> solution = dimod_sampler.sample_ising({}, {'ab': 0.5, 'bc': 0.5, 'ca': 0.5}) >>> solution.first.energy -0.5
- class HybridRunnable(sampler, fields, **sample_kwargs)[source]#
Produces a hybrid.Runnable from a dimod.Sampler (dual of HybridSampler).
The runnable samples from a problem defined in a state field named fields[0] and populates the state field referred to by fields[1].
- Parameters:
sampler (
dimod.Sampler
) – dimod-compatible sampler which is run on every iteration of the runnable.fields (tuple(str, str)) – Input and output state field names.
**sample_kwargs (dict) – Sampler-specific parameters passed to sampler on every call.
Example
This example creates a
Runnable
from dimod sampler TabuSampler, runs it on an Ising model, and finds the lowest energy.>>> from tabu import TabuSampler >>> import dimod >>> bqm = dimod.BinaryQuadraticModel.from_ising({}, {'ab': 0.5, 'bc': 0.5, 'ca': 0.5}) >>> runnable = HybridRunnable(TabuSampler(), fields=('subproblem', 'subsamples'), timeout=100) >>> state0 = State(subproblem=bqm, subsamples=SampleSet.from_samples_bqm(min_sample(bqm), bqm)) >>> state = runnable.run(state0) >>> state.result()['subsamples'].first.energy -0.5
- class HybridProblemRunnable(sampler, **sample_kwargs)[source]#
Produces a hybrid.Runnable from a dimod.Sampler (dual of HybridSampler).
The runnable that samples from state.problem and populates state.samples.
See an example in
hybrid.core.HybridRunnable
. An example of the duality with HybridSampler is:HybridProblemRunnable(HybridSampler(TabuProblemSampler())) == TabuProblemSampler()
- class HybridSubproblemRunnable(sampler, **sample_kwargs)[source]#
Produces a hybrid.Runnable from a dimod.Sampler (dual of HybridSampler).
The runnable that samples from state.subproblem and populates state.subsamples.
See an example in
hybrid.core.HybridRunnable
.