Commit 92244eb1 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Making the CLIParser extensible for adding new options

parent df801744
......@@ -153,53 +153,7 @@ public:
DWAccelerator() {
}
virtual void initialize(); /* {
auto options = RuntimeOptions::instance();
searchAPIKey(apiKey, url);
auto tempURL = url;
boost::replace_all(tempURL, "https://", "");
boost::replace_all(tempURL, "/sapi", "");
// Set up the extra HTTP headers we are going to need
headers.insert(std::make_pair("X-Auth-Token", apiKey));
headers.insert(std::make_pair("Content-type", "application/x-www-form-urlencoded"));
headers.insert(std::make_pair("Accept", "**"));
// Get the Remote URL Solver data...
auto getSolverClient = fire::util::AsioNetworkingTool<SimpleWeb::HTTPS>(tempURL, false);
auto r = getSolverClient.get("/sapi/solvers/remote", headers);
std::stringstream ss;
ss << r.content.rdbuf();
auto message = ss.str();
std::cout << "MESSAGE:\n" << message << "\n";
Document document;
document.Parse(message.c_str());
if (document.IsArray()) {
for (auto i = 0; i < document.Size(); i++) {
DWSolver solver;
solver.name = document[i]["id"].GetString();
boost::trim(solver.name);
solver.description = document[i]["description"].GetString();
if (document[i]["properties"].FindMember("j_range") != document[i]["properties"].MemberEnd()) {
solver.jRangeMin = document[i]["properties"]["j_range"][0].GetDouble();
solver.jRangeMax = document[i]["properties"]["j_range"][1].GetDouble();
solver.hRangeMin = document[i]["properties"]["h_range"][0].GetDouble();
solver.hRangeMax = document[i]["properties"]["h_range"][1].GetDouble();
}
solver.nQubits = document[i]["properties"]["num_qubits"].GetInt();
// Get the connectivity
auto couplers = document[i]["properties"]["parameters"]["couplers"].GetArray();
std::cout << "HELLO WORLD: " << couplers.Size() << "\n";
std::cout << "INSERTING: " << solver.name << "\n";
availableSolvers.insert(std::make_pair(solver.name, solver));
}
}
}*/
virtual void initialize();
virtual std::shared_ptr<AcceleratorBuffer> createBuffer(
const std::string& varId) {
......
......@@ -75,7 +75,7 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string& src,
// Loop over the lines to create DWQMI
for (auto qmi : qmiStrVec) {
boost::trim(qmi);
if (!qmi.empty()) {
if (!qmi.empty() && (std::string::npos != qmi.find_first_of("0123456789"))) {
std::vector<std::string> splitOnSpaces;
boost::split(splitOnSpaces, qmi, boost::is_any_of(" "));
auto qbit1 = std::stoi(splitOnSpaces[0]);
......
......@@ -10,6 +10,7 @@ class HUBO {
public:
virtual std::shared_ptr<xacc::quantum::DWGraph> reduceToQubo(std::vector<InstructionParameter> parameters) = 0;
virtual void mapResults(std::shared_ptr<AcceleratorBuffer> resultBuffer) = 0;
virtual ~HUBO() {}
};
......
......@@ -49,8 +49,8 @@ public:
return retGraph;
}
std::string toKernelSource() {
std::string src;
std::string toKernelSource(const std::string& kernelName) {
std::string src = "__qpu__ " + kernelName + "() {\n";
for (int i = 0; i < order(); i++) {
src += std::to_string(i) + " " + std::to_string(i) + " "
+ std::to_string(getVertexProperty<0>(i)) + "\n";
......@@ -64,7 +64,7 @@ public:
}
}
return src;
return src + "}\n";
}
virtual ~DWGraph() {}
......
......@@ -44,6 +44,7 @@ namespace xacc {
bool xaccFrameworkInitialized = false;
auto tmpInitConsole = spdlog::stdout_logger_mt("xacc-console");
auto xaccCLParser = std::make_shared<CLIParser>();
/**
* This method should be called by
......@@ -60,8 +61,8 @@ void Initialize(int argc, char** argv) {
auto preprocessorRegistry = xacc::PreprocessorRegistry::instance();
// Parse any user-supplied command line options
CLIParser parser(argc, argv);
parser.parse();
// CLIParser parser(argc, argv);
xaccCLParser->parse(argc, argv);
// Check that we have some
auto s = compilerRegistry->size();
......@@ -85,6 +86,10 @@ void Initialize(int argc, char** argv) {
xacc::xaccFrameworkInitialized = true;
}
void addCommandLineOption(const std::string& optionName, const std::string& optionDescription = "") {
xaccCLParser->addStringOption(optionName, optionDescription);
}
std::shared_ptr<Accelerator> getAccelerator(const std::string& name) {
if (!xacc::xaccFrameworkInitialized) {
XACCError(
......
......@@ -60,19 +60,33 @@ protected:
/**
* Argc, number of arguments
*/
int argc;
// int argc;
/**
* Argv, the command line arguments
*/
char** argv;
// char** argv;
std::shared_ptr<options_description> xaccOptions;
public:
/**
* The constructor
*/
CLIParser(int arc, char** arv) : argc(arc), argv(arv) {}
CLIParser() :
xaccOptions(
std::make_shared<options_description>("XACC Options")) {
xaccOptions->add_options()
("help", "Help Message")
("compiler",value<std::string>()->default_value("scaffold"),"Indicate the compiler to be used.")
("persist-ir",value<std::string>(), "Persist generated IR to provided file name.")
("load-compiler", value<std::string>(), "Load a XACC plugin")
("load-accelerator", value<std::string>(), "Load an XACC Accelerator")
("list-compilers", "List all available XACC Compilers")
("list-accelerators", "List all available XACC Accelerators")
("verbose-registry", "Print registry actions");
}
/**
* Parse the command line options. Provide a Boost options_description
......@@ -80,26 +94,11 @@ public:
* method also loads all Compilers and Accelerators available
* in the XACC_INSTALL_DIR.
*/
void parse() {
void parse(int argc, char** argv) {
// Get a reference to the RuntimeOptions
auto runtimeOptions = RuntimeOptions::instance();
auto inst = PreprocessorRegistry::instance();
// Create a base options_description, we will add
// to this with all OptionsProviders
auto compilerOptions = std::make_shared<options_description>(
"XACC Options");
compilerOptions->add_options()
("help", "Help Message")
("compiler",value<std::string>()->default_value("scaffold"),"Indicate the compiler to be used.")
("persist-ir",value<std::string>(), "Persist generated IR to provided file name.")
("load-compiler", value<std::string>(), "Load a XACC plugin")
("load-accelerator", value<std::string>(), "Load an XACC Accelerator")
("list-compilers", "List all available XACC Compilers")
("list-accelerators", "List all available XACC Accelerators");
// Load all default Compilers and Accelerators,
// ie those in XACC INSTALL DIR/lib
boost::filesystem::path xaccPath(
......@@ -140,17 +139,17 @@ public:
auto registeredCompilerOptions = CompilerRegistry::instance()->getRegisteredOptions();
for (auto s : registeredAccOptions) {
compilerOptions->add(*s.get());
xaccOptions->add(*s.get());
}
for (auto s : registeredCompilerOptions) {
compilerOptions->add(*s.get());
xaccOptions->add(*s.get());
}
// Parse the command line options
variables_map clArgs;
store(parse_command_line(argc, argv, *compilerOptions.get()), clArgs);
store(parse_command_line(argc, argv, *xaccOptions.get()), clArgs);
if (clArgs.count("help")) {
std::cout << *compilerOptions.get() << "\n";
std::cout << *xaccOptions.get() << "\n";
XACCInfo(
"\n[xacc] XACC Finalizing\n[xacc::compiler] Cleaning up Compiler Registry."
"\n[xacc::accelerator] Cleaning up Accelerator Registry.");
......@@ -227,6 +226,10 @@ public:
}
}
void addStringOption(const std::string key, const std::string description = "") {
xaccOptions->add_options()(key.c_str(), value<std::string>(), description.c_str());
}
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment