problem = sys.argv[1] with open(problem) as fp: bqm = dimod.BinaryQuadraticModel.from_coo(fp) # 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()
subproblem_size = 100 print("BQM size: {}, subproblem size: {}".format(len(bqm), subproblem_size)) # Classical solvers #subproblem = hybrid.EnergyImpactDecomposer(size=50, rolling_history=0.15) #subproblem = hybrid.EnergyImpactDecomposer(size=1024, rolling_history=0.15, traversal="bfs") # Parallel subproblem subproblem = hybrid.Unwind( #hybrid.EnergyImpactDecomposer(size=subproblem_size, rolling_history=0.15, traversal="bfs") hybrid.EnergyImpactDecomposer(size=subproblem_size, rolling_history=0.1)) # QPU #subsampler = hybrid.QPUSubproblemAutoEmbeddingSampler() | hybrid.SplatComposer() subsampler = hybrid.Map( hybrid.QPUSubproblemAutoEmbeddingSampler()) | hybrid.Reduce( hybrid.Lambda(merge_substates)) | hybrid.SplatComposer() # Define the workflow # iteration = hybrid.RacingBranches( # hybrid.InterruptableTabuSampler(), # hybrid.EnergyImpactDecomposer(size=2) # | hybrid.QPUSubproblemAutoEmbeddingSampler() # | hybrid.SplatComposer() # ) | hybrid.ArgMin() #iteration = hybrid.RacingBranches( iteration = hybrid.Race( hybrid.InterruptableTabuSampler(), #hybrid.SimulatedAnnealingProblemSampler(), subproblem | subsampler) | hybrid.ArgMin()
# define the solver def merge_substates(component, substates): a, b = substates return a.updated( subsamples=hybrid.utils.meld_samplesets(a.subsamples, b.subsamples) ) subproblems = hybrid.Unwind( hybrid.EnergyImpactDecomposer(size=50, silent_rewind=False, 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()