|
@ -10,6 +10,8 @@ from . import graph |
|
|
import minorminer |
|
|
import minorminer |
|
|
from tqdm import tqdm |
|
|
from tqdm import tqdm |
|
|
import numpy as np |
|
|
import numpy as np |
|
|
|
|
|
import random |
|
|
|
|
|
import sys |
|
|
|
|
|
|
|
|
def readConfig(configFilePath): |
|
|
def readConfig(configFilePath): |
|
|
config = configparser.ConfigParser() |
|
|
config = configparser.ConfigParser() |
|
@ -183,13 +185,22 @@ def __qubo_to_JSON(qubo): |
|
|
|
|
|
|
|
|
return quboJSON |
|
|
return quboJSON |
|
|
|
|
|
|
|
|
def write_wmis_embedding_to_pool_db(collection, qubo_id, solver_graph_id, embedding): |
|
|
|
|
|
|
|
|
def write_wmis_embedding_to_pool_db(collection, qubo_id, solver_graph_id, seed, embedding): |
|
|
if not __embedding_entry_exists(collection, qubo_id, solver_graph_id): |
|
|
if not __embedding_entry_exists(collection, qubo_id, solver_graph_id): |
|
|
__prepare_new_wmis_embedding_entry(collection, qubo_id, solver_graph_id) |
|
|
__prepare_new_wmis_embedding_entry(collection, qubo_id, solver_graph_id) |
|
|
|
|
|
|
|
|
collection.update_one( |
|
|
collection.update_one( |
|
|
{"qubo": qubo_id, "solver_graph": solver_graph_id}, |
|
|
{"qubo": qubo_id, "solver_graph": solver_graph_id}, |
|
|
{"$push": {"embeddings": __embedding_to_array(embedding)}} |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
"$push": |
|
|
|
|
|
{ |
|
|
|
|
|
"embeddings": |
|
|
|
|
|
{ |
|
|
|
|
|
"embedding": __embedding_to_array(embedding), |
|
|
|
|
|
"seed": seed |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def __embedding_entry_exists(collection, qubo_id, solver_graph_id): |
|
|
def __embedding_entry_exists(collection, qubo_id, solver_graph_id): |
|
@ -250,20 +261,25 @@ def find_wmis_embeddings_for_scope(db, scope, solver_graph): |
|
|
max_no_improvement = 10 |
|
|
max_no_improvement = 10 |
|
|
for i in range(5): |
|
|
for i in range(5): |
|
|
if __embedding_entry_exists(db["embeddings"], qubo_id, solver_graph_id): |
|
|
if __embedding_entry_exists(db["embeddings"], qubo_id, solver_graph_id): |
|
|
already_found += 1 |
|
|
|
|
|
|
|
|
if i == 0: |
|
|
|
|
|
already_found += 1 |
|
|
break; |
|
|
break; |
|
|
else: |
|
|
else: |
|
|
nx_qubo = graph.qubo_to_nx_graph(qubo) |
|
|
nx_qubo = graph.qubo_to_nx_graph(qubo) |
|
|
|
|
|
|
|
|
|
|
|
seed = random.randint(0, sys.maxsize) |
|
|
|
|
|
|
|
|
emb = minorminer.find_embedding(nx_qubo.edges(), |
|
|
emb = minorminer.find_embedding(nx_qubo.edges(), |
|
|
solver_graph.edges(), |
|
|
solver_graph.edges(), |
|
|
return_overlap=True, |
|
|
return_overlap=True, |
|
|
max_no_improvement=max_no_improvement) |
|
|
|
|
|
|
|
|
max_no_improvement=max_no_improvement, |
|
|
|
|
|
random_seed=seed) |
|
|
|
|
|
|
|
|
if emb[1] == 1: |
|
|
if emb[1] == 1: |
|
|
write_wmis_embedding_to_pool_db(db["embeddings"], |
|
|
write_wmis_embedding_to_pool_db(db["embeddings"], |
|
|
qubo_id, |
|
|
qubo_id, |
|
|
solver_graph_id, |
|
|
solver_graph_id, |
|
|
|
|
|
seed, |
|
|
emb[0]) |
|
|
emb[0]) |
|
|
new_embeddings_found += 1 |
|
|
new_embeddings_found += 1 |
|
|
|
|
|
|
|
|