Commit 28028256 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Fixing bug (#45) regarding error handling and ipython / jupyter



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 10e087d5
......@@ -52,6 +52,7 @@ def initialize():
file.write(contents)
file.close()
setIsPyApi()
def setCredentials(opts):
defaultUrls = {'ibm':'https://quantumexperience.ng.bluemix.net','rigetti':'https://api.rigetti.com/qvm', 'dwave':'https://cloud.dwavesys.com'}
......
......@@ -283,6 +283,7 @@ PYBIND11_MODULE(_pyxacc, m) {
m.def("hasAccelerator", &xacc::hasAccelerator, "Does XACC have the given Accelerator installed?");
m.def("hasCompiler", &xacc::hasCompiler, "Does XACC have the given Accelerator installed?");
m.def("optionExists", &xacc::optionExists, "Set an XACC framework option.");
m.def("setIsPyApi", &xacc::setIsPyApi, "Indicate that this is using XACC via the Python API.");
m.def("Finalize", &xacc::Finalize, "Finalize the framework");
m.def("compileKernel", [](std::shared_ptr<Accelerator> acc, const std::string& src, const std::string& compilerName = "") -> std::shared_ptr<Function>{
......
......@@ -17,6 +17,7 @@
namespace xacc {
bool isPyApi = false;
bool xaccFrameworkInitialized = false;
std::shared_ptr<CLIParser> xaccCLParser = std::make_shared<CLIParser>();
std::shared_ptr<ServiceRegistry> serviceRegistry = std::make_shared<ServiceRegistry>();
......@@ -117,6 +118,8 @@ void Initialize(int arc, char** arv) {
}
}
void setIsPyApi() { isPyApi = true; }
void setGlobalLoggerPredicate(MessagePredicate predicate) {
XACCLogger::instance()->setGlobalLoggerPredicate(predicate);
XACCLogger::instance()->dumpQueue();
......@@ -135,10 +138,14 @@ void debug(const std::string& msg, MessagePredicate predicate) {
}
void error(const std::string& msg, MessagePredicate predicate) {
XACCLogger::instance()->error(msg, predicate);
XACCLogger::instance()->error("Framework Exiting", predicate);
xacc::Finalize();
exit(-1);
if (isPyApi) {
throw std::runtime_error(msg);
} else {
XACCLogger::instance()->error(msg, predicate);
XACCLogger::instance()->error("Framework Exiting", predicate);
xacc::Finalize();
exit(-1);
}
}
void addCommandLineOption(const std::string& optionName,
......
......@@ -27,6 +27,7 @@ namespace xacc {
// Boolean indicating that framework has been initialized
extern bool xaccFrameworkInitialized;
extern bool isPyApi;
// Reference to the command line parser
extern std::shared_ptr<CLIParser> xaccCLParser;
......@@ -76,6 +77,8 @@ void Initialize();
*/
bool isInitialized();
void setIsPyApi();
/**
* Add a valid command line option
*
......
Supports Markdown
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