cleaned up generateRandomKsatDataSet_db.py / fixed type casting bug in ArgumentParser
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -98,3 +98,7 @@ ENV/
|
|||||||
#### config files
|
#### config files
|
||||||
#
|
#
|
||||||
database.config
|
database.config
|
||||||
|
|
||||||
|
### vim
|
||||||
|
#
|
||||||
|
*.swp
|
||||||
|
@@ -3,19 +3,35 @@
|
|||||||
from util import randomSAT
|
from util import randomSAT
|
||||||
from util import kSAT
|
from util import kSAT
|
||||||
import util.script as scriptUtils
|
import util.script as scriptUtils
|
||||||
import h5py
|
|
||||||
import numpy as np
|
|
||||||
import pymongo
|
import pymongo
|
||||||
import ssl
|
import ssl
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = __parseArguments()
|
args = __parseArguments()
|
||||||
|
|
||||||
dbClient = __getDBClient(args["dbConfigPath"]);
|
|
||||||
db = dbClient["experiments"]
|
|
||||||
dbInstances = db["instances"]
|
|
||||||
dbExperimentScopes = db["experiment_scopes"]
|
|
||||||
|
|
||||||
|
dbContext = __getDBContext(args["dbConfigPath"])
|
||||||
|
|
||||||
|
__generateExperiment(args, dbContext)
|
||||||
|
|
||||||
|
dbContext["client"].close()
|
||||||
|
|
||||||
|
def __generateExperiment(args, dbContext):
|
||||||
|
experimentScope = __prepareExperimentScope(args)
|
||||||
|
|
||||||
|
for i in range(args["instances"]):
|
||||||
|
sat = randomSAT.generateRandomKSAT(args["clauses"],
|
||||||
|
args["variables"],
|
||||||
|
args["variablesPerClause"])
|
||||||
|
|
||||||
|
instanceId = dbContext["instances"].insert_one(sat.writeJSONLike()).inserted_id
|
||||||
|
|
||||||
|
experimentScope["instances"].append(instanceId)
|
||||||
|
|
||||||
|
dbContext["experimentScopes"].insert_one(experimentScope)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def __prepareExperimentScope(args):
|
||||||
experimentScope = {}
|
experimentScope = {}
|
||||||
experimentScope["instances"] = []
|
experimentScope["instances"] = []
|
||||||
|
|
||||||
@@ -28,21 +44,8 @@ def main():
|
|||||||
|
|
||||||
experimentScope["description"] = description
|
experimentScope["description"] = description
|
||||||
|
|
||||||
|
return experimentScope
|
||||||
|
|
||||||
for i in range(args["instances"]):
|
|
||||||
print("loop", i)
|
|
||||||
|
|
||||||
sat = randomSAT.generateRandomKSAT(args["clauses"],
|
|
||||||
args["variables"],
|
|
||||||
args["variablesPerClause"])
|
|
||||||
|
|
||||||
instanceId = dbInstances.insert_one(sat.writeJSONLike()).inserted_id
|
|
||||||
|
|
||||||
experimentScope["instances"].append(instanceId)
|
|
||||||
|
|
||||||
dbExperimentScopes.insert_one(experimentScope)
|
|
||||||
|
|
||||||
dbClient.close()
|
|
||||||
|
|
||||||
def __getDBClient(dbConfigPath):
|
def __getDBClient(dbConfigPath):
|
||||||
dbConf = scriptUtils.readConfig(dbConfigPath)
|
dbConf = scriptUtils.readConfig(dbConfigPath)
|
||||||
@@ -58,6 +61,17 @@ def __getDBClient(dbConfigPath):
|
|||||||
ssl=True,
|
ssl=True,
|
||||||
ssl_cert_reqs=ssl.CERT_NONE)
|
ssl_cert_reqs=ssl.CERT_NONE)
|
||||||
|
|
||||||
|
|
||||||
|
def __getDBContext(dbConfigPath):
|
||||||
|
dbContext = {}
|
||||||
|
|
||||||
|
dbContext["client"] = __getDBClient(dbConfigPath)
|
||||||
|
dbContext["db"] = dbContext["client"]["experiments"]
|
||||||
|
dbContext["instances"] = dbContext["db"]["instances"]
|
||||||
|
dbContext["experimentScopes"] = dbContext["db"]["experiment_scopes"]
|
||||||
|
|
||||||
|
return dbContext
|
||||||
|
|
||||||
def __parseArguments():
|
def __parseArguments():
|
||||||
parser = scriptUtils.ArgParser()
|
parser = scriptUtils.ArgParser()
|
||||||
|
|
||||||
@@ -84,17 +98,5 @@ def __parseArguments():
|
|||||||
|
|
||||||
return parser.parse()
|
return parser.parse()
|
||||||
|
|
||||||
def __initFile(args):
|
|
||||||
f = h5py.File(args["fileName"], "w")
|
|
||||||
|
|
||||||
__SAT_TYPE__ = np.dtype([('bindings', (np.int32, (args["clauses"],
|
|
||||||
args["variablesPerClause"])))])
|
|
||||||
|
|
||||||
instances = f.create_dataset(name="instances",
|
|
||||||
shape=(args["instances"],),
|
|
||||||
dtype=__SAT_TYPE__)
|
|
||||||
|
|
||||||
return f, __SAT_TYPE__
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
@@ -28,7 +28,8 @@ class ArgParser:
|
|||||||
|
|
||||||
self.__flags[alias] = {"longFlag": longFlag,
|
self.__flags[alias] = {"longFlag": longFlag,
|
||||||
"hasDefault": False,
|
"hasDefault": False,
|
||||||
"ignoreDatabaseConfig": ignoreDatabaseConfig}
|
"ignoreDatabaseConfig": ignoreDatabaseConfig,
|
||||||
|
"type": type}
|
||||||
|
|
||||||
if default != None:
|
if default != None:
|
||||||
self.__flags[alias]["hasDefault"] = True
|
self.__flags[alias]["hasDefault"] = True
|
||||||
@@ -79,7 +80,8 @@ class ArgParser:
|
|||||||
tmpValue = args[longFlag]
|
tmpValue = args[longFlag]
|
||||||
|
|
||||||
if tmpValue == None:
|
if tmpValue == None:
|
||||||
tmpValue == input("pass arguement %s: " % longFlag)
|
tmpValue = flag["type"](input("pass arguement %s: " % longFlag))
|
||||||
|
|
||||||
|
|
||||||
return tmpValue
|
return tmpValue
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user