def SimplifiedQbsolv(max_iter=10, max_time=None, convergence=3, energy_threshold=None, max_subproblem_size=30): """Races a Tabu solver and a QPU-based sampler of flip-energy-impact induced subproblems. For arguments description see: :class:`~hybrid.reference.kerberos.Kerberos`. """ energy_reached = None if energy_threshold is not None: energy_reached = lambda en: en <= energy_threshold workflow = hybrid.Loop(hybrid.Race( hybrid.InterruptableTabuSampler(), hybrid.EnergyImpactDecomposer( size=max_subproblem_size, rolling=True, rolling_history=0.15) | hybrid.QPUSubproblemAutoEmbeddingSampler() | hybrid.SplatComposer()) | hybrid.ArgMin() | hybrid.TrackMin(output=True), max_iter=max_iter, max_time=max_time, convergence=convergence, terminate=energy_reached) return workflow
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 init_state = hybrid.State.from_sample(hybrid.min_sample(bqm), bqm) final_state = global_update.run(init_state).result() # show execution profile hybrid.profiling.print_counters(global_update)
import sys import dimod import hybrid # load a problem problem = sys.argv[1] with open(problem) as fp: bqm = dimod.BinaryQuadraticModel.from_coo(fp) # define the workflow iteration = hybrid.Race( hybrid.InterruptableTabuSampler(), hybrid.EnergyImpactDecomposer(size=50, rolling=True, rolling_history=0.15) | hybrid.QPUSubproblemAutoEmbeddingSampler() | hybrid.SplatComposer() ) | hybrid.ArgMin() | hybrid.TrackMin(output=True) 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 results print("Solution: sample={.samples.first}".format(solution))
#subproblem = hybrid.EnergyImpactDecomposer(size=50, rolling_history=0.15) subproblem = hybrid.Unwind( hybrid.EnergyImpactDecomposer(size=100, rolling_history=0.15, traversal='bfs')) # QPU #subsampler = hybrid.QPUSubproblemAutoEmbeddingSampler() | hybrid.SplatComposer() qpu_sampler = hybrid.Map( hybrid.QPUSubproblemAutoEmbeddingSampler()) | hybrid.Reduce( hybrid.Lambda(merge_substates)) | hybrid.SplatComposer() rand_sampler = hybrid.Map(hybrid.RandomSubproblemSampler()) | hybrid.Reduce( hybrid.Lambda(merge_substates)) | hybrid.SplatComposer() iteration = hybrid.RacingBranches( hybrid.InterruptableTabuSampler(), subproblem | qpu_sampler) | hybrid.ArgMin() | hybrid.TrackMin(output=True) workflow = hybrid.LoopUntilNoImprovement(iteration, convergence=5) start_t = time.perf_counter() # Convert to dimod sampler and run workflow result = hybrid.HybridSampler(workflow).sample(bqm) elapsed_t = time.perf_counter() - start_t # show execution profile #hybrid.profiling.print_counters(workflow) print("Solution: sample={}".format(result.first)) # doctest: +SKIP #dwave.inspector.show(result) print("Elapsed time: {}".format(elapsed_t))
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) | hybrid.ArgMin() iteration = hybrid.Race( hybrid.InterruptableTabuSampler(), subproblems | subsampler) | hybrid.ArgMin() | hybrid.TrackMin(output=True) 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) # show results print("Solution: sample={.samples.first}".format(solution))
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import sys import dimod import hybrid # load a problem problem = sys.argv[1] with open(problem) as fp: bqm = dimod.BinaryQuadraticModel.from_coo(fp) # define the workflow iteration = hybrid.Race( hybrid.InterruptableTabuSampler(), hybrid.EnergyImpactDecomposer(size=50, rolling=True, rolling_history=0.15) | hybrid.QPUSubproblemAutoEmbeddingSampler() | hybrid.SplatComposer()) | hybrid.ArgMin() | hybrid.TrackMin(output=True) 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 results print("Solution: sample={.samples.first}".format(solution))