embedding data extraction
This commit is contained in:
@@ -4,6 +4,9 @@ import dimod
|
||||
import random
|
||||
import numpy as np
|
||||
|
||||
from bson.objectid import ObjectId
|
||||
import pandas as pd
|
||||
|
||||
from tqdm import tqdm
|
||||
|
||||
def extract_wmis_qpu_results():
|
||||
@@ -213,3 +216,73 @@ def extract_instance_parameters():
|
||||
edb.commit()
|
||||
edb_cursor.close()
|
||||
edb.close()
|
||||
|
||||
def extract_embedding_data():
|
||||
edb = script.connect_to_experimetns_db()
|
||||
edb_cursor = edb.cursor()
|
||||
|
||||
idb = script.connect_to_instance_pool()
|
||||
|
||||
scope = input("scope: ")
|
||||
table_name = input("table name: ")
|
||||
|
||||
qubo_collection = input("qubo collection: ")
|
||||
solver_graph_id = ObjectId(input("solver graph id: "))
|
||||
|
||||
solver_input = queries.WMIS_solver_input_scope_query(idb, qubo_collection)
|
||||
solver_input.query(scope, solver_graph_id)
|
||||
|
||||
results = pd.DataFrame(columns=["instance_id",
|
||||
"embedding_list_id",
|
||||
"emb_list_index",
|
||||
"num_qubits",
|
||||
"avgr_chain_length",
|
||||
"median_chain_length"]);
|
||||
|
||||
for soin in solver_input:
|
||||
emb_index = 0;
|
||||
for emb in soin["embeddings"]:
|
||||
chain_lengths = []
|
||||
qubits = set()
|
||||
|
||||
for node, chain in emb.items():
|
||||
|
||||
chain_lengths.append(len(chain))
|
||||
|
||||
qubits = qubits.union(set(chain))
|
||||
|
||||
results = results.append({"instance_id": soin["instance_id"],
|
||||
"embedding_list_id": soin["embeddings_id"],
|
||||
"emb_list_index": emb_index,
|
||||
"num_qubits": len(qubits),
|
||||
"avgr_chain_length": np.mean(chain_lengths),
|
||||
"median_chain_length": np.median(chain_lengths)},
|
||||
ignore_index=True)
|
||||
|
||||
insert_row = ('''INSERT INTO {}
|
||||
(instance_id,
|
||||
embedding_list_id,
|
||||
emb_list_index,
|
||||
num_qubits,
|
||||
avgr_chain_length,
|
||||
median_chain_length)
|
||||
VALUES(%s, %s, %s, %s, %s, %s)''').format(table_name)
|
||||
|
||||
for index, row in results.iterrows():
|
||||
edb_cursor.execute(insert_row, (str(row["instance_id"]),
|
||||
str(row["embedding_list_id"]),
|
||||
int(row["emb_list_index"]),
|
||||
int(row["num_qubits"]),
|
||||
float(row["avgr_chain_length"]),
|
||||
float(row["median_chain_length"])))
|
||||
|
||||
edb.commit()
|
||||
edb_cursor.close()
|
||||
edb.close()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user