コード例 #1
0
    def test_simple(self):
        bqm = dimod.BinaryQuadraticModel({}, {'ab': 1, 'bc': 1, 'ca': -1}, 0, dimod.SPIN)
        sampler = HybridSampler(TabuProblemSampler())
        response = sampler.sample(bqm)

        self.assertEqual(response.record[0].energy, -3.0)
コード例 #2
0
import dimod

from hybrid.samplers import (QPUSubproblemAutoEmbeddingSampler,
                             TabuProblemSampler, InterruptableTabuSampler)
from hybrid.decomposers import EnergyImpactDecomposer
from hybrid.composers import SplatComposer
from hybrid.core import State, SampleSet
from hybrid.flow import RacingBranches, ArgMin, Loop
from hybrid.utils import min_sample, max_sample, random_sample

problem = sys.argv[1]
with open(problem) as fp:
    bqm = dimod.BinaryQuadraticModel.from_coo(fp)

# Run Tabu in parallel with QPU, but post-process QPU samples with very short Tabu
iteration = RacingBranches(
    InterruptableTabuSampler(),
    EnergyImpactDecomposer(max_size=50)
    | QPUSubproblemAutoEmbeddingSampler(num_reads=100)
    | SplatComposer()
    | TabuProblemSampler(timeout=1)) | ArgMin()

main = Loop(iteration, max_iter=10, convergence=3)

init_state = State.from_sample(min_sample(bqm), bqm)

solution = main.run(init_state).result()

print("Solution: energy={s.samples.first.energy}".format(s=solution))
コード例 #3
0
ファイル: perf.py プロジェクト: kslaughter/dwave-hybrid
    def next(self, state):
        response = QBSolv().sample(state.problem, solver=self.sampler)
        return state.updated(samples=response)


problems = chain(
    sorted(glob('problems/qbsolv/bqp100_*'))[:5],
    sorted(glob('problems/qbsolv/bqp2500_*'))[:5],
    sorted(glob('problems/random-chimera/2048*'))[:5],
    sorted(glob('problems/random-chimera/8192*'))[:5],
    sorted(glob('problems/ac3/*'))[:5],
)

solver_factories = [
    ("10 second Tabu", lambda **kw: TabuProblemSampler(timeout=10000)),
    ("10k sweeps Simulated Annealing", lambda **kw: IdentityDecomposer() |
     SimulatedAnnealingSubproblemSampler(sweeps=10000) | SplatComposer()),
    ("qbsolv-like solver", lambda qpu, **kw: Loop(RacingBranches(
        InterruptableTabuSampler(quantum_timeout=200),
        EnergyImpactDecomposer(max_size=50, rolling=True, rolling_history=0.15)
        | QPUSubproblemAutoEmbeddingSampler(qpu_sampler=qpu)
        | SplatComposer()) | ArgMin(),
                                                  max_iter=100,
                                                  convergence=10)),
    ("tiling chimera solver", lambda qpu, **kw: Loop(RacingBranches(
        InterruptableTabuSampler(quantum_timeout=200),
        TilingChimeraDecomposer(size=(16, 16, 4))
        | QPUSubproblemExternalEmbeddingSampler(qpu_sampler=qpu)
        | SplatComposer(),
    ) | ArgMin(),
コード例 #4
0
from hybrid.samplers import (
    QPUSubproblemAutoEmbeddingSampler, TabuProblemSampler, InterruptableTabuSampler)
from hybrid.decomposers import EnergyImpactDecomposer
from hybrid.composers import SplatComposer
from hybrid.core import State, SampleSet
from hybrid.flow import RacingBranches, ArgMin, Loop
from hybrid.utils import min_sample, max_sample, random_sample


problem = sys.argv[1]
with open(problem) as fp:
    bqm = dimod.BinaryQuadraticModel.from_coo(fp)


# Run Tabu in parallel with QPU, but post-process QPU samples with very short Tabu
iteration = RacingBranches(
    InterruptableTabuSampler(),
    EnergyImpactDecomposer(max_size=50, min_diff=50)
    | QPUSubproblemAutoEmbeddingSampler(num_reads=100)
    | SplatComposer()
    | TabuProblemSampler(timeout=1)
) | ArgMin()

main = Loop(iteration, max_iter=10, convergence=3)

init_state = State.from_sample(min_sample(bqm), bqm)

solution = main.run(init_state).result()

print("Solution: energy={s.samples.first.energy}".format(s=solution))