You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

92 lines
2.5 KiB

#!/usr/bin/env python3
from util.kSAT import kSAT
from util import SAT2QUBO
import util.script as scriptUtils
import pymongo
import ssl
import json
def main():
args = __parseArguments()
dbContext = scriptUtils.getDBContext(args["dbConfigPath"])
__createQubos(dbContext, args["experimentScope"])
def __parseArguments():
parser = scriptUtils.ArgParser()
parser.addArg(alias="experimentScope", shortFlag="s", longFlag="scope",
help="the experiment experiment scope of interest", type=str)
parser.addArg(alias="dbConfigPath", shortFlag="d", longFlag="db_config",
help="path to the database config file", type=str,
default="database.config")
return parser.parse()
def __createQubos(dbContext, experimentScope):
instances = __queryInstancs(dbContext["db"], experimentScope)
for instance in instances:
sat = kSAT()
for clause in instance["clauses"]:
sat.addClause(clause);
qubo = SAT2QUBO.WMISdictQUBO(sat)
doc = {}
doc["instance"] = instance["_id"]
doc["description"] = {"<qubo>": "<entrys>",
"<entrys>": "<entry><entrys> | <entry> | \"\"",
"<entry>": "<coupler><energy>",
"<energy>": "<real_number>",
"<coupler>": "<node><node>",
"<node>": "<clause><literal>",
"<clause>": "<natural_number>",
"<literal>": "<integer>"}
doc["qubo"] = __qubo2JSON(qubo)
dbContext["db"]["wmis_qubos"].insert_one(doc)
def __qubo2JSON(qubo):
quboJSON = []
for coupler, value in qubo.items():
quboJSON.append([coupler, float(value)])
return quboJSON
def __queryInstancs(db, experimentScope):
return db["experiment_scopes"].aggregate([
{
"$match": {"_id": experimentScope}
},
{
"$unwind": "$instances"
},
{
"$lookup":
{
"from": "instances",
"localField": "instances",
"foreignField": "_id",
"as": "instance"
}
},
{
"$unwind": "$instance"
},
{
"$replaceRoot": {"newRoot": "$instance"}
}
])
if __name__ == "__main__":
main()