from __future__ import print_function

import sys

import dimod
import hybrid

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

# construct a Dialectic Search workflow
generate_antithesis = (hybrid.IdentityDecomposer()
                       | hybrid.RandomSubproblemSampler()
                       | hybrid.SplatComposer()
                       | hybrid.TabuProblemSampler())

generate_synthesis = (hybrid.GreedyPathMerge() | hybrid.TabuProblemSampler())

tracker = hybrid.TrackMin()

local_update = hybrid.LoopWhileNoImprovement(
    hybrid.Parallel(hybrid.Identity(), generate_antithesis)
    | generate_synthesis | tracker,
    max_tries=10)

global_update = hybrid.Loop(generate_antithesis | local_update, max_iter=10)

# run the workflow
Пример #2
0

# define a qbsolv-like workflow
def merge_substates(_, substates):
    a, b = substates
    return a.updated(
        subsamples=hybrid.hstack_samplesets(a.subsamples, b.subsamples))


subproblems = hybrid.Unwind(
    hybrid.EnergyImpactDecomposer(size=50, rolling_history=0.15))

qpu = hybrid.Map(hybrid.QPUSubproblemAutoEmbeddingSampler()) | hybrid.Reduce(
    hybrid.Lambda(merge_substates)) | hybrid.SplatComposer()

random = hybrid.Map(hybrid.RandomSubproblemSampler()) | hybrid.Reduce(
    hybrid.Lambda(merge_substates)) | hybrid.SplatComposer()

subsampler = hybrid.Parallel(qpu, random, endomorphic=False) | hybrid.ArgMin()

iteration = hybrid.Race(hybrid.InterruptableTabuSampler(),
                        subproblems | subsampler) | hybrid.ArgMin()

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

# run the workflow
init_state = hybrid.State.from_sample(hybrid.min_sample(bqm), bqm)
solution = main.run(init_state).result()

# show execution profile
hybrid.profiling.print_counters(main)