|
@ -7,6 +7,8 @@ class Instance_scope_query: |
|
|
def __init__(self, database): |
|
|
def __init__(self, database): |
|
|
self.__database = database |
|
|
self.__database = database |
|
|
self.__query = None |
|
|
self.__query = None |
|
|
|
|
|
self.__instance_ids = [] |
|
|
|
|
|
self.__instance_id_iterator = None; |
|
|
|
|
|
|
|
|
def query(self, scope): |
|
|
def query(self, scope): |
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
@ -29,15 +31,23 @@ class Instance_scope_query: |
|
|
"$unwind": "$instance" |
|
|
"$unwind": "$instance" |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$replaceRoot": {"newRoot": "$instance"} |
|
|
|
|
|
|
|
|
"$project": {"instance_id": "$instance._id"} |
|
|
} |
|
|
} |
|
|
]) |
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
self.__instance_ids = [] |
|
|
|
|
|
for doc in self.__query: |
|
|
|
|
|
self.__instance_ids.append(doc["instance_id"]) |
|
|
|
|
|
|
|
|
|
|
|
self.__instance_id_iterator = iter(self.__instance_ids) |
|
|
|
|
|
|
|
|
def __iter__(self): |
|
|
def __iter__(self): |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
def __next__(self): |
|
|
def __next__(self): |
|
|
document = self.__query.next() |
|
|
|
|
|
|
|
|
instance_id = self.__instance_id_iterator.__next__() |
|
|
|
|
|
|
|
|
|
|
|
document = self.__database["instances"].find_one({"_id": instance_id}) |
|
|
|
|
|
|
|
|
return self.__document_to_sat(document) |
|
|
return self.__document_to_sat(document) |
|
|
|
|
|
|
|
@ -54,6 +64,8 @@ class WMIS_scope_query_raw: |
|
|
def __init__(self, database): |
|
|
def __init__(self, database): |
|
|
self.__database = database |
|
|
self.__database = database |
|
|
self.__query = None |
|
|
self.__query = None |
|
|
|
|
|
self.__qubo_ids = [] |
|
|
|
|
|
self.__qubo_id_iterator = None |
|
|
|
|
|
|
|
|
def query(self, scope): |
|
|
def query(self, scope): |
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
@ -76,15 +88,26 @@ class WMIS_scope_query_raw: |
|
|
"$unwind": "$qubo" |
|
|
"$unwind": "$qubo" |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$replaceRoot": {"newRoot": "$qubo"} |
|
|
|
|
|
|
|
|
"$project": {"qubo_id": "$qubo._id"} |
|
|
} |
|
|
} |
|
|
]) |
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
self.__qubo_ids = [] |
|
|
|
|
|
for doc in self.__query: |
|
|
|
|
|
self.__qubo_ids.append(doc["qubo_id"]) |
|
|
|
|
|
|
|
|
|
|
|
self.__qubo_id_iterator = iter(self.__qubo_ids) |
|
|
|
|
|
|
|
|
|
|
|
def __len__(self): |
|
|
|
|
|
return self.query.count_documents({}) |
|
|
|
|
|
|
|
|
def __iter__(self): |
|
|
def __iter__(self): |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
def __next__(self): |
|
|
def __next__(self): |
|
|
return self.__query.next() |
|
|
|
|
|
|
|
|
qubo_filter = {"_id": self.__qubo_id_iterator.__next__()} |
|
|
|
|
|
|
|
|
|
|
|
return self.__database["wmis_qubos"].find_one(qubo_filter) |
|
|
|
|
|
|
|
|
class WMIS_scope_query (WMIS_scope_query_raw): |
|
|
class WMIS_scope_query (WMIS_scope_query_raw): |
|
|
|
|
|
|
|
@ -99,6 +122,8 @@ class WMIS_solver_input_scope_query_raw: |
|
|
def __init__(self, database): |
|
|
def __init__(self, database): |
|
|
self.__database = database |
|
|
self.__database = database |
|
|
self.__query = None |
|
|
self.__query = None |
|
|
|
|
|
self.__ids = [] |
|
|
|
|
|
self.__id_iterator = None; |
|
|
|
|
|
|
|
|
def query(self, scope, solver_graph_id): |
|
|
def query(self, scope, solver_graph_id): |
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
|
self.__query = self.__database["experiment_scopes"].aggregate([ |
|
@ -123,17 +148,31 @@ class WMIS_solver_input_scope_query_raw: |
|
|
{ |
|
|
{ |
|
|
"$unwind": "$wmis_qubo" |
|
|
"$unwind": "$wmis_qubo" |
|
|
}, |
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$project": |
|
|
|
|
|
{ |
|
|
|
|
|
"instance_id": True, |
|
|
|
|
|
"wmis_qubo_id": "$wmis_qubo._id" |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$lookup": |
|
|
"$lookup": |
|
|
{ |
|
|
{ |
|
|
"from": "embeddings", |
|
|
"from": "embeddings", |
|
|
"let": |
|
|
"let": |
|
|
{ |
|
|
{ |
|
|
"qubo_id": "$wmis_qubo._id", |
|
|
|
|
|
|
|
|
"qubo_id": "$wmis_qubo_id", |
|
|
"solver_graph_id": bson.ObjectId(solver_graph_id) |
|
|
"solver_graph_id": bson.ObjectId(solver_graph_id) |
|
|
}, |
|
|
}, |
|
|
"pipeline": |
|
|
"pipeline": |
|
|
[ |
|
|
[ |
|
|
|
|
|
{ |
|
|
|
|
|
"$project": |
|
|
|
|
|
{ |
|
|
|
|
|
"qubo": True, |
|
|
|
|
|
"solver_graph": True, |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$match": |
|
|
"$match": |
|
|
{ |
|
|
{ |
|
@ -148,34 +187,55 @@ class WMIS_solver_input_scope_query_raw: |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$project": { "list": "$embeddings" } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
"$project": |
|
|
|
|
|
{ |
|
|
|
|
|
"_id": True |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
], |
|
|
], |
|
|
"as": "embeddings" |
|
|
|
|
|
|
|
|
"as": "embeddings_id" |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$match": {"embeddings": {"$exists": True, "$not": {"$size": 0}}} |
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
|
|
|
"$unwind": "$embeddings" |
|
|
|
|
|
|
|
|
"$unwind": "$embeddings_id" |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
"$project": |
|
|
"$project": |
|
|
{ |
|
|
{ |
|
|
"_id": False, |
|
|
|
|
|
"instance_id": True, |
|
|
"instance_id": True, |
|
|
"wmis_qubo": True, |
|
|
|
|
|
"embeddings": True |
|
|
|
|
|
|
|
|
"wmis_qubo_id": True, |
|
|
|
|
|
"embeddings_id": "$embeddings_id._id" |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
]) |
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
self.__ids = [] |
|
|
|
|
|
for doc in self.__query: |
|
|
|
|
|
self.__ids.append({ |
|
|
|
|
|
"instance_id": doc["instance_id"], |
|
|
|
|
|
"wmis_qubo_id": doc["wmis_qubo_id"], |
|
|
|
|
|
"embeddings_id": doc["embeddings_id"] |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
self.__id_iterator = iter(self.__ids) |
|
|
|
|
|
|
|
|
def __iter__(self): |
|
|
def __iter__(self): |
|
|
return self |
|
|
return self |
|
|
|
|
|
|
|
|
def __next__(self): |
|
|
def __next__(self): |
|
|
return self.__query.next() |
|
|
|
|
|
|
|
|
ids = self.__id_iterator.__next__() |
|
|
|
|
|
|
|
|
|
|
|
doc = {} |
|
|
|
|
|
|
|
|
|
|
|
doc["instance_id"] = ids["instance_id"] |
|
|
|
|
|
|
|
|
|
|
|
qubo_filter = {"_id": ids["wmis_qubo_id"]} |
|
|
|
|
|
doc["wmis_qubo"] = self.__database["wmis_qubos"].find_one(qubo_filter) |
|
|
|
|
|
|
|
|
|
|
|
embeddings_filter = {"_id": ids["embeddings_id"]} |
|
|
|
|
|
doc["embeddings"] = self.__database["embeddings"].find_one(embeddings_filter) |
|
|
|
|
|
|
|
|
|
|
|
return doc |
|
|
|
|
|
|
|
|
class WMIS_solver_input_scope_query (WMIS_solver_input_scope_query_raw): |
|
|
class WMIS_solver_input_scope_query (WMIS_solver_input_scope_query_raw): |
|
|
|
|
|
|
|
@ -192,7 +252,7 @@ class WMIS_solver_input_scope_query (WMIS_solver_input_scope_query_raw): |
|
|
data["embeddings_id"] = doc["embeddings"]["_id"] |
|
|
data["embeddings_id"] = doc["embeddings"]["_id"] |
|
|
|
|
|
|
|
|
data["embeddings"] = [] |
|
|
data["embeddings"] = [] |
|
|
for raw_emb in doc["embeddings"]["list"]: |
|
|
|
|
|
|
|
|
for raw_emb in doc["embeddings"]["embeddings"]: |
|
|
data["embeddings"].append(read_raw_embedding(raw_emb)) |
|
|
data["embeddings"].append(read_raw_embedding(raw_emb)) |
|
|
|
|
|
|
|
|
return data |
|
|
return data |
|
|