def test_concurrent_tabu_samples(self):
        t1 = hybrid.TabuProblemSampler(timeout=1000)
        t2 = hybrid.TabuProblemSampler(timeout=2000)
        workflow = hybrid.Parallel(t1, t2)

        bqm = dimod.BinaryQuadraticModel({'a': 1}, {}, 0, 'BINARY')
        state = hybrid.State.from_problem(bqm)

        with self.assertRuntimeWithin(1900, 2500):
            workflow.run(state).result()
Ejemplo n.º 2
0
# 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)

# run Tabu in parallel with QPU, but post-process QPU samples with very short Tabu
iteration = hybrid.Race(
    hybrid.InterruptableTabuSampler(),
    hybrid.EnergyImpactDecomposer(size=50)
    | hybrid.QPUSubproblemAutoEmbeddingSampler(num_reads=100)
    | hybrid.SplatComposer()
    | hybrid.TabuProblemSampler(timeout=1)) | hybrid.ArgMin()

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

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

# show results
print("Solution: sample={.samples.first}".format(solution))
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
init_state = hybrid.State.from_sample(hybrid.min_sample(bqm), bqm)
final_state = global_update.run(init_state).result()
import dimod
import hybrid


# load a problem
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 = hybrid.Race(
    hybrid.InterruptableIdentity(),
    hybrid.InterruptableTabuSampler(),
    hybrid.EnergyImpactDecomposer(size=50)
    | hybrid.QPUSubproblemAutoEmbeddingSampler(num_reads=100)
    | hybrid.SplatComposer()
    | hybrid.TabuProblemSampler(timeout=1)
) | hybrid.ArgMin()

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


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

# show results
print("Solution: sample={.samples.first}".format(solution))
Ejemplo n.º 5
0
problems = list(
    chain(
        sorted(glob('../problems/qbsolv/bqp50_*'))[:problems_per_group],
        sorted(glob('../problems/qbsolv/bqp100_*'))[:problems_per_group],
        sorted(glob('../problems/qbsolv/bqp250_*'))[:problems_per_group],
        sorted(glob('../problems/qbsolv/bqp500_*'))[:problems_per_group],
        sorted(glob('../problems/qbsolv/bqp1000_*'))[:problems_per_group],
        sorted(glob('../problems/qbsolv/bqp2500_*'))[:problems_per_group],
        sorted(glob('../problems/random-chimera/2048*'))[:problems_per_group],
        sorted(glob('../problems/random-chimera/8192*'))[:problems_per_group],
        sorted(glob('../problems/ac3/*'))[:problems_per_group],
    ))

workflows = [
    ("10s-tabu", lambda **kw: hybrid.TabuProblemSampler(timeout=10000)),
    ("10k-sa", lambda **kw:
     (hybrid.IdentityDecomposer()
      | hybrid.SimulatedAnnealingSubproblemSampler(sweeps=10000)
      | hybrid.SplatComposer())),
    ("qbsolv-like",
     lambda qpu, energy_threshold, **kw: hybrid.Loop(hybrid.Race(
         hybrid.InterruptableTabuSampler(timeout=200),
         hybrid.EnergyImpactDecomposer(
             size=50, rolling=True, rolling_history=0.15)
         | hybrid.QPUSubproblemAutoEmbeddingSampler(qpu_sampler=qpu)
         | hybrid.SplatComposer()) | hybrid.ArgMin(),
                                                     max_iter=100,
                                                     convergence=10,
                                                     terminate=None
                                                     if energy_threshold is