|
@ -1,5 +1,6 @@ |
|
|
from .kSAT import kSAT |
|
|
from .kSAT import kSAT |
|
|
import bson |
|
|
import bson |
|
|
|
|
|
import dimod |
|
|
|
|
|
|
|
|
class Instance_scope_query: |
|
|
class Instance_scope_query: |
|
|
|
|
|
|
|
@ -195,6 +196,45 @@ class WMIS_solver_input_scope_query (WMIS_solver_input_scope_query_raw): |
|
|
data["embeddings"].append(read_raw_embedding(raw_emb)) |
|
|
data["embeddings"].append(read_raw_embedding(raw_emb)) |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|
|
|
|
|
|
|
|
|
|
class WMIS_result_scope_query_raw: |
|
|
|
|
|
def __init__(self, database): |
|
|
|
|
|
self.__database = database |
|
|
|
|
|
self.__query = None |
|
|
|
|
|
|
|
|
|
|
|
def query(self, scope, collection): |
|
|
|
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
|
|
|
|
{ |
|
|
|
|
|
"$match": {"_id": scope} |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$unwind": "$instances" |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$project": {"instance_id": "$instances"} |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$lookup": |
|
|
|
|
|
{ |
|
|
|
|
|
"from": collection, |
|
|
|
|
|
"localField": "instance_id", |
|
|
|
|
|
"foreignField": "instance", |
|
|
|
|
|
"as": "result" |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$unwind": "$result" |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$replaceRoot": {"newRoot": "$result"} |
|
|
|
|
|
} |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
def __iter__(self): |
|
|
|
|
|
return self |
|
|
|
|
|
|
|
|
|
|
|
def __next__(self): |
|
|
|
|
|
return self.__query.next() |
|
|
|
|
|
|
|
|
def load_embedding(collection, qubo_id, solver_graph_id): |
|
|
def load_embedding(collection, qubo_id, solver_graph_id): |
|
|
doc = collection.find_one( |
|
|
doc = collection.find_one( |
|
@ -262,3 +302,24 @@ def read_raw_embedding(raw_embedding): |
|
|
emb[tuple(entry[0])] = entry[1] |
|
|
emb[tuple(entry[0])] = entry[1] |
|
|
|
|
|
|
|
|
return emb |
|
|
return emb |
|
|
|
|
|
|
|
|
|
|
|
def read_raw_wmis_sample_set(raw_sample_set): |
|
|
|
|
|
sample_set_data = raw_sample_set.copy() |
|
|
|
|
|
|
|
|
|
|
|
sample_set_data["variable_labels"] = [] |
|
|
|
|
|
|
|
|
|
|
|
for label in raw_sample_set["variable_labels"]: |
|
|
|
|
|
sample_set_data["variable_labels"].append(tuple(label)) |
|
|
|
|
|
|
|
|
|
|
|
return dimod.SampleSet.from_serializable(sample_set_data) |
|
|
|
|
|
|
|
|
|
|
|
def get_instance_by_id(collection, id): |
|
|
|
|
|
doc = collection.find_one({"_id": bson.ObjectId(id)}) |
|
|
|
|
|
|
|
|
|
|
|
sat = kSAT() |
|
|
|
|
|
|
|
|
|
|
|
for clause in doc["clauses"]: |
|
|
|
|
|
sat.addClause(clause); |
|
|
|
|
|
|
|
|
|
|
|
return sat |
|
|
|
|
|
|