Commit 76a05915 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Starting on integrating CppMicroServices as our plugin infrastructure

parent 30bc0b10
......@@ -48,6 +48,8 @@ if (EXISTS ${CMAKE_SOURCE_DIR}/tpls/fire)
include(tests)
endif()
find_package(CppMicroServices NO_MODULE REQUIRED)
# We require MPI
find_package(MPI REQUIRED)
......@@ -79,6 +81,7 @@ include_directories(${CMAKE_BINARY_DIR})
include_directories(${MPI_INCLUDE_PATH})
include_directories(${Boost_INCLUDE_DIRS})
include_directories(tpls/boost-dll)
include_directories("/usr/local/include/cppmicroservices3")
include_directories("${CMAKE_SOURCE_DIR}/xacc")
include_directories("${CMAKE_SOURCE_DIR}/xacc/ir")
include_directories("${CMAKE_SOURCE_DIR}/xacc/compiler")
......
......@@ -49,15 +49,39 @@ if (OPENSSL_FOUND)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp)
add_library(${LIBRARY_NAME} SHARED ${SRC})
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} xacc-quantum-aqc)
add_library(${LIBRARY_NAME} ${SRC})
target_link_libraries(${LIBRARY_NAME} CppMicroServices ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} xacc-quantum-aqc)
set(_bundle_name xacc_dwave)
set_target_properties(${LIBRARY_NAME} PROPERTIES
COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
US_BUNDLE_NAME ${_bundle_name}
)
if(BUILD_SHARED_LIBS)
set_target_properties(${LIBRARY_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
)
endif()
usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
FILES
manifest.json
)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "xacc-dwave;dl;pthread")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "xacc-dwave;dl;pthread;CppMicroServices")
add_subdirectory(examples)
endif()
......
......@@ -29,6 +29,6 @@
#
#**********************************************************************************/
add_executable(dwave-simple-example dwave-simple-example.cpp)
target_link_libraries(dwave-simple-example ${Boost_LIBRARIES} dl)
target_link_libraries(dwave-simple-example ${Boost_LIBRARIES} dl CppMicroServices xacc-quantum-aqc)
install(TARGETS dwave-simple-example DESTINATION examples)
......@@ -29,6 +29,15 @@
*
**********************************************************************************/
#include "XACC.hpp"
#include "EmbeddingAlgorithm.hpp"
#include <cppmicroservices/FrameworkFactory.h>
#include <cppmicroservices/Framework.h>
#include <cppmicroservices/BundleContext.h>
#include <cppmicroservices/Bundle.h>
#include <cppmicroservices/BundleImport.h>
using namespace cppmicroservices;
const std::string src =
"__qpu__ factoring15() {\n"
......@@ -50,6 +59,54 @@ const std::string src =
int main (int argc, char** argv) {
// Create a new framework with a default configuration.
Framework fw = FrameworkFactory().NewFramework();
try {
// Initialize the framework, such that we can call
// GetBundleContext() later.
fw.Init();
} catch (const std::exception& e) {
std::cout << e.what() << std::endl;
return 1;
}
// The framework inherits from the Bundle class; it is
// itself a bundle.
auto ctx = fw.GetBundleContext();
if (!ctx) {
std::cerr << "Invalid framework context" << std::endl;
return 1;
}
ctx.InstallBundles("/usr/local/xacc/lib/plugins/embedding/libxacc-trivial-embedding.so");
ctx.InstallBundles("/usr/local/xacc/lib/plugins/compilers/libxacc-scaffold.so");
try {
// Start the framwork itself.
fw.Start();
// Our bundles depend on each other in the sense that the consumer
// bundle expects a ServiceTime service in its activator Start()
// function. This is done here for simplicity, but is actually
// bad practice.
auto bundles = ctx.GetBundles();
for (auto b : bundles) {
std::cout << "BUNDLE: " << b.GetSymbolicName() << "\n";
b.Start();
}
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
auto ref = ctx.GetServiceReference<xacc::quantum::EmbeddingAlgorithm>();
auto emb = ctx.GetService(ref);
std::cout << "EMBALGO NAME: " << emb->name() << "\n";
// Initialize the XACC Framework
xacc::Initialize(argc, argv);
......
{
"bundle.symbolic_name" : "xacc_dwave",
"bundle.activator" : true
}
\ No newline at end of file
......@@ -59,14 +59,44 @@ if (CLANG_FOUND AND LLVM_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/ir/instructions)
# Set up dependencies to resources to track changes
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
# Generate bundle initialization code
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)
add_library(${LIBRARY_NAME} SHARED ${SRC})
#install(FILES ${HEADERS} DESTINATION include)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
set(_bundle_name xacc_scaffold)
set_target_properties(${LIBRARY_NAME} PROPERTIES
# This is required for every bundle
COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
# This is for convenience, used by other CMake functions
US_BUNDLE_NAME ${_bundle_name}
)
if(BUILD_SHARED_LIBS)
set_target_properties(${LIBRARY_NAME} PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
)
endif()
# Embed meta-data from a manifest.json file
usFunctionEmbedResources(TARGET ${LIBRARY_NAME}
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
FILES
manifest.json
)
link_directories(${CLANG_LIBRARY_DIRS} ${LLVM_LIBRARY_DIRS})
target_link_libraries(${LIBRARY_NAME} xacc-quantum-gate ${CLANG_LIBS} ${LLVM_LIBS} ${Boost_LIBRARIES})
target_link_libraries(${LIBRARY_NAME} xacc-quantum-gate CppMicroServices ${CLANG_LIBS} ${LLVM_LIBS} ${Boost_LIBRARIES})
install(TARGETS ${LIBRARY_NAME} DESTINATION lib/plugins/compilers/)
# Gather tests
file (GLOB test_files tests/*.cpp)
......
/*=============================================================================
Library: CppMicroServices
Copyright (c) The CppMicroServices developers. See the COPYRIGHT
file at the top-level directory of this distribution and at
https://github.com/CppMicroServices/CppMicroServices/COPYRIGHT .
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
//! [Activator]
#include "ScaffoldCompiler.hpp"
#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
#include "cppmicroservices/ServiceProperties.h"
#include <memory>
#include <set>
using namespace cppmicroservices;
namespace {
/**
* This class implements a bundle activator that uses the bundle
* context to register an English language dictionary service
* with the C++ Micro Services registry during static initialization
* of the bundle. The dictionary service interface is
* defined in a separate file and is implemented by a nested class.
*/
class US_ABI_LOCAL ScaffoldActivator : public BundleActivator
{
public:
ScaffoldActivator() {}
/**
* Implements BundleActivator::Start(). Registers an
* instance of a dictionary service using the bundle context;
* attaches properties to the service that can be queried
* when performing a service look-up.
* @param context the context for the bundle.
*/
void Start(BundleContext context) {
auto compiler = std::make_shared<
xacc::quantum::ScaffoldCompiler>();
context.RegisterService<xacc::Compiler>(
compiler);
}
/**
* Implements BundleActivator::Stop(). Does nothing since
* the C++ Micro Services library will automatically unregister any registered services.
* @param context the context for the bundle.
*/
void Stop(BundleContext /*context*/) {
// NOTE: The service is automatically unregistered
}
};
}
CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(ScaffoldActivator)
//![Activator]
{
"bundle.symbolic_name" : "xacc_scaffold",
"bundle.activator" : true,
"bundle.name" : "XACC Scaffold Compiler Integration",
"bundle.description" : "This bundle uses scaffold to compile code"
}
\ No newline at end of file
......@@ -38,14 +38,76 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler/default)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC compiler/default/*.cpp)
file (GLOB SRC compiler/*.cpp compiler/default/DefaultParameterSetter.cpp)
#----
add_library(${LIBRARY_NAME} SHARED ${SRC})
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES})
target_include_directories(xacc-quantum-aqc PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/compiler>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
if(BUILD_SHARED_LIBS)
set_target_properties(xacc-quantum-aqc PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
)
endif()
# [publisher-begin]
#=========================================================
# A bundle implementing the ServiceTime interface
#---------------------------------------------------------
set(_srcs
compiler/default/EmbeddingAlgorithmActivator.cpp
compiler/default/TrivialEmbeddingAlgorithm.cpp
)
# Set up dependencies to resources to track changes
usFunctionGetResourceSource(TARGET xacc-trivial-embedding OUT _srcs)
# Generate bundle initialization code
usFunctionGenerateBundleInit(TARGET xacc-trivial-embedding OUT _srcs)
add_library(xacc-trivial-embedding SHARED ${_srcs})
target_link_libraries(xacc-trivial-embedding CppMicroServices xacc-quantum-aqc)
set(_bundle_name trivial_embedding_algorithm)
set_target_properties(xacc-trivial-embedding PROPERTIES
# This is required for every bundle
COMPILE_DEFINITIONS US_BUNDLE_NAME=${_bundle_name}
# This is for convenience, used by other CMake functions
US_BUNDLE_NAME ${_bundle_name}
)
if(BUILD_SHARED_LIBS)
set_target_properties(xacc-trivial-embedding PROPERTIES
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN 1
)
endif()
# Embed meta-data from a manifest.json file
usFunctionEmbedResources(TARGET xacc-trivial-embedding
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/compiler/default
FILES
manifest.json
)
# [publisher-end]
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} CppMicroServices)
add_subdirectory(ir)
add_subdirectory(compiler)
install(FILES ${HEADERS} DESTINATION include/quantum/aqc)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
install(TARGETS xacc-trivial-embedding DESTINATION lib/plugins/embedding)
......@@ -30,5 +30,5 @@
#**********************************************************************************/
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread;xacc-quantum-aqc;xacc-trivial-embedding")
......@@ -41,6 +41,10 @@
#include "DWGraph.hpp"
#include "Embedding.hpp"
//#include "cppmicroservices/ServiceInterface.h"
#include <string>
namespace xacc {
namespace quantum {
......@@ -49,7 +53,7 @@ namespace quantum {
* for minor graph embedding algorithms.
*
*/
class EmbeddingAlgorithm {
class __attribute__((visibility("default"))) EmbeddingAlgorithm {
public:
......
/*=============================================================================
Library: CppMicroServices
Copyright (c) The CppMicroServices developers. See the COPYRIGHT
file at the top-level directory of this distribution and at
https://github.com/CppMicroServices/CppMicroServices/COPYRIGHT .
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/
//! [Activator]
#include "TrivialEmbeddingAlgorithm.hpp"
#include "cppmicroservices/BundleActivator.h"
#include "cppmicroservices/BundleContext.h"
#include "cppmicroservices/ServiceProperties.h"
#include <memory>
#include <set>
using namespace cppmicroservices;
namespace {
/**
* This class implements a bundle activator that uses the bundle
* context to register an English language dictionary service
* with the C++ Micro Services registry during static initialization
* of the bundle. The dictionary service interface is
* defined in a separate file and is implemented by a nested class.
*/
class US_ABI_LOCAL EmbeddingAlgorithmActivator : public BundleActivator
{
public:
EmbeddingAlgorithmActivator() {}
/**
* Implements BundleActivator::Start(). Registers an
* instance of a dictionary service using the bundle context;
* attaches properties to the service that can be queried
* when performing a service look-up.
* @param context the context for the bundle.
*/
void Start(BundleContext context) {
auto trivialEmbService = std::make_shared<
xacc::quantum::TrivialEmbeddingAlgorithm>();
context.RegisterService<xacc::quantum::EmbeddingAlgorithm>(
trivialEmbService);
}
/**
* Implements BundleActivator::Stop(). Does nothing since
* the C++ Micro Services library will automatically unregister any registered services.
* @param context the context for the bundle.
*/
void Stop(BundleContext /*context*/) {
// NOTE: The service is automatically unregistered
}
};
}
CPPMICROSERVICES_EXPORT_BUNDLE_ACTIVATOR(EmbeddingAlgorithmActivator)
//![Activator]
......@@ -32,6 +32,7 @@
namespace xacc {
namespace quantum {
Embedding TrivialEmbeddingAlgorithm::embed(
std::shared_ptr<DWGraph> problem,
std::shared_ptr<xacc::AcceleratorGraph> hdware,
......@@ -65,7 +66,5 @@ Embedding TrivialEmbeddingAlgorithm::embed(
return xaccEmbedding;
}
xacc::quantum::RegisterEmbeddingAlgorithm<TrivialEmbeddingAlgorithm> TRIVEMB(
"trivial");
}
}
{
"bundle.symbolic_name" : "trivial_embedding_algorithm",
"bundle.activator" : true,
"bundle.name" : "Trivial Embedding Algorithm",
"bundle.description" : "This bundle uses trivial embedding algo"
}
\ No newline at end of file
{
"bundle.symbolic_name" : "xacc_quantum_aqc",
"bundle.activator" : true
}
\ No newline at end of file
......@@ -48,7 +48,7 @@ namespace xacc {
* compiler-specific compilation mechanism, and returns a valid
* XACC IR instance modeling the result of the compilation.
*/
class Compiler : public OptionsProvider {
class __attribute__((visibility("default"))) Compiler : public OptionsProvider {
public:
......
......@@ -101,7 +101,7 @@ public:
// Load all default Compilers and Accelerators,
// ie those in XACC INSTALL DIR/lib
boost::filesystem::path xaccPath(
/*boost::filesystem::path xaccPath(
std::string(XACC_INSTALL_DIR) + std::string("/lib"));
if (boost::filesystem::exists(xaccPath)) {
boost::filesystem::directory_iterator end_itr;
......@@ -133,7 +133,7 @@ public:
}
}
}
}
}*/
auto registeredAccOptions = AcceleratorRegistry::instance()->getRegisteredOptions();
auto registeredCompilerOptions = CompilerRegistry::instance()->getRegisteredOptions();
......
......@@ -34,6 +34,8 @@
#include <memory>
#include <boost/program_options.hpp>
//#include "cppmicroservices/ServiceInterface.h"
using namespace boost::program_options;
namespace xacc {
......@@ -44,7 +46,7 @@ namespace xacc {
* that they can take to drive and control their execution and
* behavior.
*/
class OptionsProvider {
class __attribute__((visibility("default"))) OptionsProvider {
public:
......
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