in src/qbsolv_community.py [0:0]
def solve_hybrid(self, num_comm, s3_folder, device_arn):
"""
Call QUBO hybrid solver for community detection
:param num_comm: int, number of communities to solve for
:param s3_folder: str, the Amazon Braket S3 path to store solver response files
:return: dict, two dictionaries for graph's community results and QBSolv reponse results
:param device_arn: str, D-Wave QPU Device ARN (only needed for QBSolv Hybrid solver)
"""
q_dict = create_qubo_dict(self.graph, num_comm, self.alpha)
self.qpu_cost_warning()
execution = input("Continue to execute QBSolv Hybrid job: Y or N?")
if execution.lower() in ["y", "yes"]:
t0 = time.time()
system = BraketDWaveSampler(s3_folder, device_arn)
# find embedding of subproblem-sized complete graph to the QPU
G_sub = nx.complete_graph(self.solver_limit)
embedding = minorminer.find_embedding(G_sub.edges, system.edgelist)
# use the FixedEmbeddingComposite() method with a fixed embedding
solver = FixedEmbeddingComposite(system, embedding)
# execute optimization task using QBSolv hybrid on D-Wave QPU
response_hybrid = QBSolv().sample_qubo(q_dict, solver=solver, num_repeats=self.num_repeats,
solver_limit=self.solver_limit, num_reads=self.num_reads,
seed=self.seed)
print(f"Mode: Hybrid, time spent is {round(time.time()-t0, 2)} seconds for {self.num_repeats} repeats")
print(response_hybrid)
# extract the best solution that has the lowest energy
sample_hybrid = np.array(list(response_hybrid.first.sample.values()))
comm_hybrid = qbsolv_response_to_community(self.graph, sample_hybrid, num_comm)
return comm_hybrid, response_hybrid
else:
raise ValueError("Hybrid job execution declined by the user!")