def test_beta_progressor(self):
        beta_schedule = [1, 2, 3]

        prog = ProgressBetaAlongSchedule(beta_schedule=beta_schedule)

        betas = []
        while True:
            try:
                betas.append(prog.run(hybrid.State()).result().beta)
            except:
                break

        self.assertEqual(betas, beta_schedule)
# number of generations, or temperatures to progress through
num_iter = 20

# population size
num_samples = 20

# QPU initial sampling: limits the PA workflow to QPU-sized problems
qpu_init = (hybrid.IdentityDecomposer()
            | hybrid.QPUSubproblemAutoEmbeddingSampler(num_reads=num_samples)
            | hybrid.IdentityComposer()) | hybrid.AggregatedSamples(False)

# PA workflow: after initial beta schedule estimation, we do `num_iter` steps
# (one per beta/temperature) of fixed-temperature sampling / weighted resampling
workflow = qpu_init | CalculateAnnealingBetaSchedule(
    length=num_iter) | hybrid.Loop(
        ProgressBetaAlongSchedule() | FixedTemperatureSampler(
            num_sweeps=num_sweeps) | EnergyWeightedResampler(),
        max_iter=num_iter)

# run the workflow
state = hybrid.State.from_problem(bqm)
solution = workflow.run(state).result()

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

# show results
print("Solution: sample={0.samples.first}, energy={0.samples.first.energy}".
      format(solution))
Exemple #3
0
print("BQM: {} nodes, {} edges, {:.2f} density".format(
    len(bqm), len(bqm.quadratic), hybrid.bqm_density(bqm)))

# sweeps per fixed-temperature sampling step
num_sweeps = 1000

# number of generations, or temperatures to progress through
num_iter = 20

# population size
num_samples = 20

# PA workflow: after initial beta schedule estimation, we do `num_iter` steps
# (one per beta/temperature) of fixed-temperature sampling / weighted resampling
workflow = CalculateAnnealingBetaSchedule(length=num_iter) | hybrid.Loop(
    ProgressBetaAlongSchedule()
    | FixedTemperatureSampler(num_sweeps=num_sweeps, num_reads=num_samples)
    | EnergyWeightedResampler(),
    max_iter=num_iter)

# run the workflow
state = hybrid.State.from_problem(bqm)
solution = workflow.run(state).result()

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

# show results
print("Solution: sample={0.samples.first}, energy={0.samples.first.energy}".
      format(solution))