Commit 17b15957 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing commit error



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent ec9de217
......@@ -52,13 +52,8 @@ endif(APPLE)
add_library(pyxacc SHARED xacc-py.cpp)
set_target_properties(pyxacc PROPERTIES PREFIX "")
set(CppUsLib CppMicroServicesd)
find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
target_link_libraries(pyxacc ${CppUsLib} xacc xacc-quantum-gate ${Boost_LIBRARIES} cpr curl) #xacc xacc-quantum-gate xacc-quantum-aqc CppMicroServices ${Boost_LIBRARIES} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(pyxacc CppMicroServices xacc xacc-quantum-gate ${Boost_LIBRARIES} cpr curl)
if(APPLE)
set_target_properties(pyxacc PROPERTIES INSTALL_RPATH "@loader_path/lib")
......
......@@ -73,12 +73,17 @@ PYBIND11_MODULE(pyxacc, m) {
.def("getParameter", &xacc::Function::getParameter, "")
.def("getParameters", &xacc::Function::getParameters, "")
.def("setParameter", &xacc::Function::setParameter, "")
.def("getTag", &xacc::Function::getTag, "");
.def("getTag", &xacc::Function::getTag, "")
.def("mapBits", &xacc::Function::mapBits, "");
// Expose the IR interface
py::class_<xacc::IR, std::shared_ptr<xacc::IR>> (m, "IR", "The XACC Intermediate Representation, "
"serves as a container for XACC Functions.")
.def("getKernels", &xacc::IR::getKernels, "Return the kernels in this IR");
.def("getKernels", &xacc::IR::getKernels, "Return the kernels in this IR")
.def("addKernel", &xacc::IR::addKernel, "");
py::class_<xacc::IRPreprocessor, std::shared_ptr<xacc::IRPreprocessor>> (m, "IRPreprocesor", "").def("process", &xacc::IRPreprocessor::process, "");
py::class_<xacc::AcceleratorBufferPostprocessor, std::shared_ptr<xacc::AcceleratorBufferPostprocessor>> (m, "AcceleratorBufferPostprocessor", "").def("process", &xacc::AcceleratorBufferPostprocessor::process, "");
// Expose the Kernel
py::class_<xacc::Kernel<>, std::shared_ptr<xacc::Kernel<>>>(m, "Kernel", "The XACC Kernel is the "
......@@ -178,6 +183,9 @@ PYBIND11_MODULE(pyxacc, m) {
m.def("getCompiler", (std::shared_ptr<xacc::Compiler> (*)(const std::string&))
&xacc::getCompiler, py::return_value_policy::reference,
"Return the Compiler of given name.");
m.def("getIRPreprocessor", (std::shared_ptr<xacc::IRPreprocessor> (*)(const std::string&))
&xacc::getService<IRPreprocessor>, py::return_value_policy::reference,
"Return the Compiler of given name.");
m.def("setOption", &xacc::setOption, "Set an XACC framework option.");
m.def("getOption", &xacc::getOption, "Get an XACC framework option.");
m.def("optionExists", &xacc::optionExists, "Set an XACC framework option.");
......@@ -190,6 +198,8 @@ PYBIND11_MODULE(pyxacc, m) {
return p.getRuntimeKernels()[0].getIRFunction();
}, py::arg("acc"), py::arg("src"), py::arg("compilerName") = std::string(""), py::return_value_policy::move, "");
m.def("functionToInstruction", [](std::shared_ptr<Function> f) {return std::dynamic_pointer_cast<Instruction>(f);}, py::return_value_policy::copy);
py::module gatesub = m.def_submodule("gate", "Gate model quantum computing data structures.");
gatesub.def("create",
[](const std::string& name, std::vector<int> qbits, std::vector<InstructionParameter> params = std::vector<InstructionParameter> {}) -> std::shared_ptr<Instruction> {
......
......@@ -51,15 +51,11 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
manifest.json
)
set(CppUsLib CppMicroServicesd)
link_directories(${CPPUS_LIBRARY_DIR})
find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
set(BOOST_ROOT ${CMAKE_INSTALL_PREFIX})
find_package(Boost COMPONENTS system program_options filesystem chrono regex graph REQUIRED)
target_link_libraries(${LIBRARY_NAME} CppMicroServices xacc ${Boost_LIBRARIES}) #${CppUsLib}) #${Boost_LIBRARIES} xacc ${CppUsLib} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} ${CppUsLib})
#target_link_libraries(${LIBRARY_NAME} ${CppUsLib}) #${Boost_LIBRARIES} ${CppUsLib} xacc restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
if(APPLE)
set_target_properties(xacc-quantum-aqc PROPERTIES INSTALL_RPATH "@loader_path")
......
......@@ -53,15 +53,11 @@ usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
manifest.json
)
set(CppUsLib CppMicroServicesd)
link_directories(${CPPUS_LIBRARY_DIR})
find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
target_link_libraries(${LIBRARY_NAME} ${CppUsLib})
#target_link_libraries(${LIBRARY_NAME} ${CppUsLib}) #${Boost_LIBRARIES} xacc ${CppUsLib} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
set(BOOST_ROOT ${CMAKE_INSTALL_PREFIX})
find_package(Boost COMPONENTS system program_options filesystem chrono regex graph REQUIRED)
target_link_libraries(${LIBRARY_NAME} CppMicroServices xacc ${Boost_LIBRARIES}) #${CppUsLib}) #${Boost_LIBRARIES} xacc ${CppUsLib} restclient-cpp) #cpprest ${OPENSSL_LIBRARIES})
if(APPLE)
set_target_properties(xacc-quantum-gate PROPERTIES INSTALL_RPATH "@loader_path")
......
......@@ -13,7 +13,7 @@
#include "KernelReplacementPreprocessor.hpp"
#include <boost/algorithm/string.hpp>
#include "IRGenerator.hpp"
#include "ServiceRegistry.hpp"
#include "XACC.hpp"
#include <numeric>
namespace xacc {
......@@ -61,7 +61,7 @@ const std::string KernelReplacementPreprocessor::process(const std::string& sour
}
auto buffer = accelerator->getBuffer(bufName);
auto algoGen = ServiceRegistry::instance()->getService<IRGenerator>(funcName);
auto algoGen = xacc::getService<IRGenerator>(funcName);
auto algoKernel = algoGen->generate(buffer);
......
#include "GateIRProvider.hpp"
#include "GateIR.hpp"
#include "XACC.hpp"
namespace xacc {
namespace quantum {
......@@ -8,7 +8,7 @@ std::shared_ptr<Instruction> GateIRProvider::createInstruction(const std::string
std::vector<int> bits, std::vector<InstructionParameter> parameters) {
std::shared_ptr<GateInstruction> inst =
ServiceRegistry::instance()->getService<GateInstruction>(name);
xacc::getService<GateInstruction>(name);
inst->setBits(bits);
int idx = 0;
for (auto& a : parameters) {
......@@ -31,7 +31,7 @@ std::shared_ptr<IR> GateIRProvider::createIR() {
std::vector<std::string> GateIRProvider::getInstructions() {
std::vector<std::string> ret;
for (auto i : ServiceRegistry::instance()->getRegisteredIds<GateInstruction>()) {
for (auto i : xacc::getRegisteredIds<GateInstruction>()) {
ret.push_back(i);
}
return ret;
......
......@@ -63,12 +63,7 @@ endif()
# Get the test files
file(GLOB test_files utils/tests/*Tester.cpp accelerator/tests/*Tester.cpp)
set(CppUsLib CppMicroServicesd)
find_library(cppus_has_d_suffix CppMicroServicesd)
if (NOT cppus_has_d_suffix)
set(CppUsLib CppMicroServices)
endif()
target_link_libraries(xacc ${CppUsLib})
target_link_libraries(xacc CppMicroServices cpr)
# Add the tests
if(XACC_BUILD_TESTS)
......
......@@ -19,6 +19,7 @@ namespace xacc {
bool xaccFrameworkInitialized = false;
std::shared_ptr<CLIParser> xaccCLParser = std::make_shared<CLIParser>();
std::shared_ptr<ServiceRegistry> serviceRegistry = std::make_shared<ServiceRegistry>();
int argc = 0;
char** argv = NULL;
......@@ -70,8 +71,6 @@ void Initialize(int arc, char** arv) {
notify(vm);
XACCLogger::instance()->enqueueLog("Creating XACC ServiceRegistry");
// Get reference to the service registry
auto serviceRegistry = xacc::ServiceRegistry::instance();
try {
XACCLogger::instance()->enqueueLog("Initializing the ServiceRegistry");
if (vm.count("internal-plugin-path")) {
......@@ -87,7 +86,7 @@ void Initialize(int arc, char** arv) {
}
// Parse any user-supplied command line options
xaccCLParser->parse(argc, argv);
xaccCLParser->parse(argc, argv, *serviceRegistry);
XACCLogger::instance()->enqueueLog("[xacc] Initializing XACC Framework.");
......@@ -175,13 +174,11 @@ void setOption(const std::string& optionKey, const std::string& value) {
}
void unsetOption(const std::string& optionKey) {
if (optionExists(optionKey)) {
(*RuntimeOptions::instance()).erase(optionKey);
} else {
error("Invalid option, cannot unset");
(*RuntimeOptions::instance()).erase(optionKey);
}
return;
}
void setCompiler(const std::string& compilerName) {
setOption("compiler", compilerName);
}
......@@ -201,7 +198,7 @@ std::shared_ptr<Accelerator> getAccelerator() {
"requires that you set --accelerator at the command line.");
}
auto acc = ServiceRegistry::instance()->getService<Accelerator>(getOption("accelerator"));
auto acc = serviceRegistry->getService<Accelerator>(getOption("accelerator"));
if (acc) {
acc->initialize();
} else {
......@@ -218,7 +215,7 @@ std::shared_ptr<Accelerator> getAccelerator(const std::string& name) {
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto acc = ServiceRegistry::instance()->getService<Accelerator>(name);
auto acc = serviceRegistry->getService<Accelerator>(name);
if (acc) {
acc->initialize();
} else {
......@@ -235,7 +232,7 @@ bool hasAccelerator(const std::string& name) {
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
return ServiceRegistry::instance()->hasService<Accelerator>(name);
return serviceRegistry->hasService<Accelerator>(name);
}
......@@ -245,7 +242,7 @@ std::shared_ptr<Compiler> getCompiler(const std::string& name) {
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto c = ServiceRegistry::instance()->getService<Compiler>(name);
auto c = serviceRegistry->getService<Compiler>(name);
if (!c) {
error(
"Invalid Compiler. Could not find " + name
......@@ -265,7 +262,7 @@ std::shared_ptr<Compiler> getCompiler() {
error("Invalid use of XACC API. getCompiler() with no string argument "
"requires that you set --compiler at the command line.");
}
auto compiler = ServiceRegistry::instance()->getService<Compiler>(getOption("compiler"));
auto compiler = serviceRegistry->getService<Compiler>(getOption("compiler"));
if (!compiler) {
error(
"Invalid Compiler. Could not find " + (*options)["compiler"]
......@@ -275,7 +272,7 @@ std::shared_ptr<Compiler> getCompiler() {
}
bool hasCompiler(const std::string& name) {
return ServiceRegistry::instance()->hasService<Compiler>(name);
return serviceRegistry->hasService<Compiler>(name);
}
std::shared_ptr<IRTransformation> getIRTransformations(
......@@ -285,7 +282,7 @@ std::shared_ptr<IRTransformation> getIRTransformations(
"XACC not initialized before use. Please execute "
"xacc::Initialize() before using API.");
}
auto t = ServiceRegistry::instance()->getService<IRTransformation>(name);
auto t = serviceRegistry->getService<IRTransformation>(name);
if (!t) {
error(
"Invalid IRTransformation. Could not find " + name
......@@ -314,7 +311,7 @@ const std::string translateWithVisitor(const std::string& originalSource, const
auto acc = getAccelerator(accelerator);
auto originalCompiler = getCompiler(originalLanguage);
auto ir = originalCompiler->compile(originalSource, acc);
auto visitor = ServiceRegistry::instance()->getService<
auto visitor = serviceRegistry->getService<
BaseInstructionVisitor>(visitorMappingName);
std::vector<std::string> previouslySeenKernels;
......@@ -344,7 +341,7 @@ void Finalize() {
XACCLogger::instance()->dumpQueue();
info("");
info("[xacc::plugins] Cleaning up Plugin Registry.");
xacc::ServiceRegistry::instance()->destroy();
// xacc::serviceRegistry->destroy();
xacc::xaccFrameworkInitialized = false;
info("[xacc] Finalizing XACC Framework.");
}
......
......@@ -30,6 +30,7 @@ extern bool xaccFrameworkInitialized;
// Reference to the command line parser
extern std::shared_ptr<CLIParser> xaccCLParser;
extern std::shared_ptr<ServiceRegistry> serviceRegistry;
extern int argc;
extern char** argv;
......@@ -232,7 +233,7 @@ bool hasCompiler(const std::string& name);
template<typename Service>
std::shared_ptr<Service> getService(const std::string& serviceName) {
auto service = ServiceRegistry::instance()->getService<Service>(
auto service = serviceRegistry->getService<Service>(
serviceName);
if (!service) {
error(
......@@ -242,6 +243,20 @@ std::shared_ptr<Service> getService(const std::string& serviceName) {
return service;
}
template<typename Service>
bool hasService(const std::string& serviceName) {
return serviceRegistry->hasService<Service>(
serviceName);
}
template<typename ServiceInterface>
std::vector<std::string> getRegisteredIds() {
return serviceRegistry->getRegisteredIds<ServiceInterface>();
}
template<typename ServiceInterface>
std::vector<std::shared_ptr<ServiceInterface>> getServices() {
return serviceRegistry->getServices<ServiceInterface>();
}
std::shared_ptr<IRTransformation> getIRTransformation(const std::string& name);
const std::string translate(const std::string& original, const std::string& originalLanguageName,
......
......@@ -24,7 +24,7 @@ std::vector<IRTransformation> getAcceleratorIndependentTransformations(
std::vector<std::shared_ptr<Preprocessor>> getDefaultPreprocessors(
AcceleratorType accType) {
std::vector<std::shared_ptr<Preprocessor>> preprocessors;
auto preprocessor = ServiceRegistry::instance()->getService<Preprocessor>(
auto preprocessor = xacc::getService<Preprocessor>(
"kernel-replacement");
if (accType == AcceleratorType::qpu_gate) {
preprocessors.push_back(preprocessor);
......@@ -33,6 +33,22 @@ std::vector<std::shared_ptr<Preprocessor>> getDefaultPreprocessors(
return preprocessors;
}
void Program::addPreprocessor(const std::string& preProcessorName) {
if(xacc::hasService<Preprocessor>(preProcessorName)) {
auto preprocessor = xacc::getService<Preprocessor>(preProcessorName);
preprocessors.push_back(preprocessor);
}
}
void Program::addIRPreprocessor(const std::string& name) {
if (xacc::hasService<IRPreprocessor>(
name)) {
auto p = xacc::getService<
IRPreprocessor>(name);
irpreprocessors.push_back(p);
}
}
void Program::build() {
// Get reference to the runtime options
......@@ -42,8 +58,7 @@ void Program::build() {
auto compilerToRun = (*runtimeOptions)["compiler"];
// Create the appropriate compiler
compiler = xacc::ServiceRegistry::instance()->getService<Compiler>(
compilerToRun);
compiler = xacc::getService<Compiler>(compilerToRun);
// Make sure we got a valid
if (!compiler) {
......
......@@ -122,21 +122,9 @@ public:
preprocessors.push_back(preprocessor);
}
void addPreprocessor(const std::string& preProcessorName) {
if(ServiceRegistry::instance()->hasService<Preprocessor>(preProcessorName)) {
auto preprocessor = ServiceRegistry::instance()->getService<Preprocessor>(preProcessorName);
preprocessors.push_back(preprocessor);
}
}
void addPreprocessor(const std::string& preProcessorName);
void addIRPreprocessor(const std::string& name) {
if (ServiceRegistry::instance()->hasService<IRPreprocessor>(
name)) {
auto p = ServiceRegistry::instance()->getService<
IRPreprocessor>(name);
irpreprocessors.push_back(p);
}
}
void addIRPreprocessor(const std::string& name);
std::vector<std::shared_ptr<AcceleratorBufferPostprocessor>> getBufferPostprocessors() {
return bufferPostprocessors;
......
......@@ -69,12 +69,12 @@ public:
/**
*/
void parse(int argc, char** argv) {
void parse(int argc, char** argv, ServiceRegistry& serviceRegistry) {
// Get a reference to the RuntimeOptions
auto runtimeOptions = RuntimeOptions::instance();
auto registeredOptions = ServiceRegistry::instance()->getRegisteredOptions();
auto registeredOptions = serviceRegistry.getRegisteredOptions();
for (auto s : registeredOptions) {
xaccOptions->add(*s.get());
......@@ -97,12 +97,12 @@ public:
// then load it
if (clArgs.count("load")) {
auto loadPath = clArgs["load-compiler"].as<std::string>();
ServiceRegistry::instance()->loadPlugin(loadPath);
serviceRegistry.loadPlugin(loadPath);
}
bool listTypes = false;
if (clArgs.count("list-compilers")) {
auto ids = ServiceRegistry::instance()->getRegisteredIds<Compiler>();
auto ids = serviceRegistry.getRegisteredIds<Compiler>();
XACCLogger::instance()->info("Available XACC Compilers:");
for (auto i : ids) {
XACCLogger::instance()->info("\t" + i);
......@@ -111,7 +111,7 @@ public:
}
if (clArgs.count("list-accelerators")) {
auto ids = ServiceRegistry::instance()->getRegisteredIds<Accelerator>();
auto ids = serviceRegistry.getRegisteredIds<Accelerator>();
XACCLogger::instance()->info("Available XACC Accelerators:");
for (auto i : ids) {
XACCLogger::instance()->info("\t" + i);
......@@ -127,7 +127,7 @@ public:
exit(0);
}
auto exitRequested = ServiceRegistry::instance()->handleOptions(clArgs);
auto exitRequested = serviceRegistry.handleOptions(clArgs);
if (exitRequested) {
XACCLogger::instance()->dumpQueue();
XACCLogger::instance()->info(
......
......@@ -44,7 +44,7 @@ namespace xacc {
* It delegates to the CppMicroServices Framework and BundleContexts,
* and provides methods for creating instances of XACC plugins or services.
*/
class ServiceRegistry : public Singleton<ServiceRegistry> {
class ServiceRegistry {
protected:
......@@ -61,24 +61,21 @@ protected:
std::map<std::string, std::string> installed;
/**
* The constructor
*/
ServiceRegistry() : framework(FrameworkFactory().NewFramework()) {}
bool initialized = false;
public:
ServiceRegistry() : framework(FrameworkFactory().NewFramework()) {}
void initialize(const std::string internalPath = "");
// Overriding here so we can have a custom constructor
static ServiceRegistry* instance() {
if (!instance_) {
instance_ = new ServiceRegistry();
}
return instance_;
}
// // Overriding here so we can have a custom constructor
// static ServiceRegistry* instance() {
// if (!instance_) {
// instance_ = new ServiceRegistry();
// }
// return instance_;
// }
template<typename ServiceInterface>
bool hasService(const std::string name) {
......
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