Q[(i, j)] += 2

# ------- Run our QUBO on the QPU -------
# Set up QPU parameters
chain_strength = 0.1
num_reads = 10

# Run the QUBO on a solver with the specified topology
QPU = DWaveSampler(solver={'topology__type__eq': 'chimera'})
embedding = find_embedding(Q, QPU.edgelist)

print("\nEmbedding found:\n", embedding)

sampler = FixedEmbeddingComposite(QPU, embedding)
response = sampler.sample_qubo(Q,
                               chain_strength=chain_strength,
                               num_reads=num_reads,
                               label='Training - Embedding')

print("\nSampleset:")
print(response)

# ------- Print results to user -------
print("\nSolutions:")
print('-' * 60)
print('{:>15s}{:>15s}{:^15s}{:^15s}'.format('Set 0', 'Set 1', 'Energy',
                                            'Cut Size'))
print('-' * 60)
for sample, E in response.data(fields=['sample', 'energy']):
    S0 = [k for k, v in sample.items() if v == 0]
    S1 = [k for k, v in sample.items() if v == 1]
    print('{:>15s}{:>15s}{:^15s}{:^15s}'.format(str(S0), str(S1), str(E),
예제 #2
0
    # Sampler/Annealing parameters
    params["chainstrength_P"] = float(0.5)
    params["chainstrength"] = float(
        params["chainstrength_P"] * params["max_bias_final"]
    )  # Default 1 | Good rule of thumb is to have the same order of magnitude as Qubo.
    params["numruns"] = 10  # Default 1000
    params["anneal_time"] = 20  # Default 20
    #-----------------------------

    print(
        f"Running D-Wave w/ chainstrength {params['chainstrength_P']:.2f}|{params['chainstrength']:.2f} (%|final) & numruns {params['numruns']:d} & anneal_time {params['anneal_time']:d}"
    )

    composite = FixedEmbeddingComposite(sampler, embedding=embedding)
    response = composite.sample_qubo(Qubo,
                                     annealing_time=params["anneal_time"],
                                     chain_strength=params["chainstrength"],
                                     num_reads=params["numruns"])

    print("Results:\n")
    print_result(response, params, time=0, mute=0, file=1)

    #dwave.inspector.show(response)

# ---------------------- \| Utility Functions |/ ---------------------- #

# minimum possible energy: -283987.43787980796 |\ 173.045734368

# maximum possible energy: -2466607.9822456012  |\  480.1178932


def extra():