data extraction
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from .kSAT import kSAT
|
||||
import bson
|
||||
import dimod
|
||||
|
||||
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))
|
||||
|
||||
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):
|
||||
doc = collection.find_one(
|
||||
@@ -262,3 +302,24 @@ def read_raw_embedding(raw_embedding):
|
||||
emb[tuple(entry[0])] = entry[1]
|
||||
|
||||
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
|
||||
|
||||
|
@@ -9,7 +9,7 @@ from . import queries
|
||||
from . import graph
|
||||
import minorminer
|
||||
from tqdm import tqdm
|
||||
|
||||
import numpy as np
|
||||
|
||||
def readConfig(configFilePath):
|
||||
config = configparser.ConfigParser()
|
||||
@@ -104,7 +104,7 @@ def getDBContext(dbConfigPath):
|
||||
|
||||
return dbContext
|
||||
|
||||
def connect_to_instance_pool(dbConfigPath):
|
||||
def connect_to_instance_pool(dbConfigPath = "database.config"):
|
||||
dbConf = readConfig(dbConfigPath)
|
||||
|
||||
client = pymongo.MongoClient(
|
||||
@@ -119,7 +119,7 @@ def connect_to_instance_pool(dbConfigPath):
|
||||
|
||||
return client[dbConf["INSTANCE_POOL"]["database"]]
|
||||
|
||||
def connect_to_experimetns_db(dbConfigPath):
|
||||
def connect_to_experimetns_db(dbConfigPath = "database.config"):
|
||||
dbConfig = readConfig(dbConfigPath)
|
||||
|
||||
return mysql.connector.connect(
|
||||
@@ -267,3 +267,9 @@ def save_simulated_annealing_result(collection, result, solver_input, emb_list_i
|
||||
|
||||
collection.insert_one(doc)
|
||||
|
||||
def analyze_wmis_sample(sample):
|
||||
data = {}
|
||||
|
||||
data["number_of_assignments"] = np.count_nonzero(list(sample.sample.values()))
|
||||
|
||||
return data
|
||||
|
Reference in New Issue
Block a user