Ejemplo n.º 1
0
def hybrid_solver():
    workflow = hybrid.LoopUntilNoImprovement(hybrid.RacingBranches(
        hybrid.InterruptableTabuSampler(),
        hybrid.EnergyImpactDecomposer(size=20)
        | hybrid.QPUSubproblemAutoEmbeddingSampler()
        | hybrid.SplatComposer()) | hybrid.ArgMin(),
                                             convergence=3)
    return hybrid.HybridSampler(workflow)
Ejemplo n.º 2
0
    def test_racing_workflow_with_oracle_subsolver(self):
        workflow = hybrid.LoopUntilNoImprovement(hybrid.RacingBranches(
            hybrid.InterruptableTabuSampler(),
            hybrid.EnergyImpactDecomposer(size=1)
            | HybridSubproblemRunnable(dimod.ExactSolver())
            | hybrid.SplatComposer()) | hybrid.ArgMin(),
                                                 convergence=3)
        state = State.from_sample(min_sample(self.bqm), self.bqm)
        response = workflow.run(state)

        self.assertIsInstance(response, concurrent.futures.Future)
        self.assertEqual(response.result().samples.record[0].energy, -3.0)
Ejemplo n.º 3
0
    def test_sampling_parameters_filtering(self):
        class Sampler(dimod.ExactSolver):
            """Exact solver that fails if a sampling parameter is provided."""
            parameters = {}

            def sample(self, bqm):
                return super().sample(bqm)

        workflow = hybrid.LoopUntilNoImprovement(hybrid.RacingBranches(
            hybrid.InterruptableTabuSampler(),
            hybrid.EnergyImpactDecomposer(size=1)
            | HybridSubproblemRunnable(Sampler())
            | hybrid.SplatComposer()) | hybrid.ArgMin(),
                                                 convergence=3)
        state = State.from_sample(min_sample(self.bqm), self.bqm)
        response = workflow.run(state)

        self.assertIsInstance(response, concurrent.futures.Future)
        self.assertEqual(response.result().samples.record[0].energy, -3.0)
Ejemplo n.º 4
0
    # dwave_sampler = LeapHybridSampler(dwave_sampler)
    # sampler = EmbeddingComposite(dwave_sampler)

    # computation = KerberosSampler().sample_qubo(quboDict, max_iter=10, convergence=3)

    # computation = LeapHybridSampler().sample_qubo(quboDict[0],) computation = KerberosSampler().sample_qubo(
    # quboDict,num_reads=num_reads) computation = sampler.sample_qubo(quboDict, label='Test Topology: {0},
    # Nodes: {1}, Num_reads: {2}'.format(topology, NUM_NODES, num_reads), num_reads=num_reads)

    # Define the workflow
    iteration = hybrid.RacingBranches(
        hybrid.InterruptableTabuSampler(),
        hybrid.EnergyImpactDecomposer(size=5)
        | hybrid.QPUSubproblemAutoEmbeddingSampler()
        | hybrid.SplatComposer()) | hybrid.ArgMin()
    workflow = hybrid.LoopUntilNoImprovement(iteration, convergence=20)

    bqm = quboDict
    # Solve the problem
    # init_state = hybrid.State.from_problem(bqm)
    # final_state = workflow.run(init_state).result()
    sampler = HybridSampler(workflow)
    computation = sampler.sample_qubo(quboDict,
                                      label='Hybrid Test Topology: {0}, '
                                      'Nodes: {1}, '
                                      'Num_reads: {2}'.format(
                                          topology, NUM_NODES, num_reads),
                                      num_reads=num_reads)

    # Print results
    # print("Solution: sample={.samples.first}".format(final_state))
Ejemplo n.º 5
0
    iteration = hybrid.RacingBranches(
        # Runs (races) multiple workflows of type Runnable in parallel, stopping all once the first
        # finishes. Returns the results of all, in the specified order.
        hybrid.InterruptableTabuSampler(
        ),  # Tabu algorithm seek of best solutions
        hybrid.EnergyImpactDecomposer(
            size=5
        )  # Selects a subproblem of variables maximally contributing to the
        # problem energy.
        | hybrid.QPUSubproblemAutoEmbeddingSampler(
        )  # A quantum sampler for a subproblem with automated heuristic
        # minor-embedding.
        | hybrid.SplatComposer(
        )  # A composer that overwrites current samples with subproblem samples.
    ) | hybrid.ArgMin()  # Selects the best state from a sequence of States
    workflow = hybrid.LoopUntilNoImprovement(
        iteration, convergence)  # Iterates Runnable for up to max_iter times,
    # or until a state quality metric, defined by the key function, shows no improvement for at least convergence
    # number of iterations.

    # Solve the problem
    init_state = hybrid.State.from_problem(_QUBOdictionary)
    computation = workflow.run(init_state).result()

    # print execution time
    print('Execution time for {0} nodes: {1} milliseconds'.format(
        NUM_NODES, (time.time() - start_time) * 1000))

    # Print results
    print("Solution: sample={.samples.first}".format(computation))

    # sampler = HybridSampler(workflow)