Commit 06957faa authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Major rehaul of plugin system

parent 76a05915
......@@ -54,7 +54,6 @@ find_package(CppMicroServices NO_MODULE REQUIRED)
find_package(MPI REQUIRED)
# We require Boost
find_package(PythonLibs REQUIRED)
find_package(Boost COMPONENTS system program_options filesystem python REQUIRED)
# Look for OpenMP, add it we find it
......
......@@ -38,53 +38,22 @@ if (OPENSSL_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/quantum/aqc/accelerator)
include_directories(${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/accelerator)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler)
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/util)
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tpls/simpleweb)
set (PACKAGE_NAME "XACC D-Wave Compiler and Accelerator Support")
set (PACKAGE_NAME "XACC D-Wave Support")
set (PACKAGE_DESCIPTION "Extensions to XACC to work with the D-Wave QPU")
set (LIBRARY_NAME xacc-dwave)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp)
usFunctionGetResourceSource(TARGET ${LIBRARY_NAME} OUT SRC)
usFunctionGenerateBundleInit(TARGET ${LIBRARY_NAME} OUT SRC)
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)
add_subdirectory(accelerator)
add_subdirectory(compiler)
add_subdirectory(examples)
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "xacc-dwave;dl;pthread;CppMicroServices")
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "xacc-dwave-accelerator;xacc-dwave-qmicompiler;dl;pthread;CppMicroServices")
add_subdirectory(examples)
endif()
#add_subdirectory(examples)
#***********************************************************************************
# Copyright (c) 2016, UT-Battelle
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the xacc nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Contributors:
# Initial API and implementation - Alex McCaskey
#
#**********************************************************************************/
set (PACKAGE_NAME "D-Wave XACC Accelerator")
set (PACKAGE_DESCIPTION "D-Wave XACC Accelerator Bundle")
set (LIBRARY_NAME xacc-dwave-accelerator)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp)
# 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})
set(_bundle_name xacc_dwave_accelerator)
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
)
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} CppMicroServices xacc-quantum-aqc)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib/plugins/accelerators)
......@@ -157,6 +157,103 @@ public:
return desc;
}
virtual bool handleOptions(variables_map& map){
if(map.count("dwave-list-solvers")) {
std::string tempApiKey, tempUrl;
auto findApiKeyInFile = [](std::string& apiKey, std::string& url,
boost::filesystem::path &p) {
std::ifstream stream(p.string());
std::string contents(
(std::istreambuf_iterator<char>(stream)),
std::istreambuf_iterator<char>());
std::vector<std::string> lines;
boost::split(lines, contents, boost::is_any_of("\n"));
for (auto l : lines) {
if (boost::contains(l, "key")) {
std::vector<std::string> split;
boost::split(split, l, boost::is_any_of(":"));
auto key = split[1];
boost::trim(key);
apiKey = key;
} else if (boost::contains(l, "url")) {
std::vector<std::string> split;
boost::split(split, l, boost::is_any_of(":"));
auto key = split[1] + ":" + split[2];
boost::trim(key);
url = key;
}
}
};
auto searchAPIKey = [&](std::string& key, std::string& url) {
// Search for the API Key in $HOME/.dwave_config,
// $DWAVE_CONFIG, or in the command line argument --dwave-api-key
auto options = RuntimeOptions::instance();
boost::filesystem::path dwaveConfig(
std::string(getenv("HOME")) + "/.dwave_config");
if (boost::filesystem::exists(dwaveConfig)) {
findApiKeyInFile(key, url, dwaveConfig);
} else if (const char * nonStandardPath = getenv("DWAVE_CONFIG")) {
boost::filesystem::path nonStandardDwaveConfig(
nonStandardPath);
findApiKeyInFile(key, url, nonStandardDwaveConfig);
} else {
// Ensure that the user has provided an api-key
if (!options->exists("dwave-api-key")) {
XACCError("Cannot list D-Wave solvers without API Key.");
}
// Set the API Key
key = (*options)["dwave-api-key"];
if (options->exists("dwave-api-url")) {
url = (*options)["dwave-api-url"];
}
}
// If its still empty, then we have a problem
if (key.empty()) {
XACCError("Error. The API Key is empty. Please place it "
"in your $HOME/.dwave_config file, $DWAVE_CONFIG env var, "
"or provide --dwave-api-key argument.");
}
};
searchAPIKey(tempApiKey, tempUrl);
boost::replace_all(tempUrl, "https://", "");
boost::replace_all(tempUrl, "/sapi", "");
std::map<std::string, std::string> headers;
// Set up the extra HTTP headers we are going to need
headers.insert(std::make_pair("X-Auth-Token", tempApiKey));
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();
Document document;
document.Parse(message.c_str());
if (document.IsArray()) {
for (auto i = 0; i < document.Size(); i++) {
XACCInfo("Available D-Wave Solver: " + std::string(document[i]["id"].GetString()));
}
}
return true;
}
return false; }
/**
* Register this Accelerator with the framework.
*/
......@@ -292,6 +389,15 @@ public:
return buffer;
}
virtual const std::string name() const {
return "dwave";
}
virtual const std::string description() const {
return "The D-Wave Accelerator executes Ising Hamiltonian parameters "
"on a remote D-Wave QPU.";
}
/**
* The destructor
*/
......
#include "DWAccelerator.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 DWAcceleratorActivator : public BundleActivator
{
public:
DWAcceleratorActivator() {}
/**
* 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 acc = std::make_shared<
xacc::quantum::DWAccelerator>();
context.RegisterService<xacc::Accelerator>(
acc);
}
/**
* 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(DWAcceleratorActivator)
//![Activator]
{
"bundle.symbolic_name" : "xacc_dwave_accelerator",
"bundle.activator" : true,
"bundle.name" : "XACC D-Wave Accelerator",
"bundle.description" : "This bundle provides a D-Wave Accelerator for Adiabatic Model QC."
}
\ No newline at end of file
#***********************************************************************************
# Copyright (c) 2016, UT-Battelle
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the xacc nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Contributors:
# Initial API and implementation - Alex McCaskey
#
#**********************************************************************************/
set (PACKAGE_NAME "D-Wave XACC QMI Compiler")
set (PACKAGE_DESCIPTION "D-Wave XACC QMI Compiler Bundle")
set (LIBRARY_NAME xacc-dwave-qmicompiler)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp)
# 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})
set(_bundle_name xacc_dwave_qmicompiler)
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
)
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} CppMicroServices xacc-quantum-aqc)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib/plugins/compilers)
......@@ -37,6 +37,8 @@
#include "DWGraph.hpp"
#include "EmbeddingAlgorithm.hpp"
#include "ServiceRegistry.hpp"
namespace xacc {
namespace quantum {
......@@ -125,6 +127,17 @@ public:
});
}
virtual bool handleOptions(variables_map& map) {
if (map.count("dwave-list-embedding-algorithms")) {
auto ids = ServiceRegistry::instance()->getRegisteredIds<EmbeddingAlgorithm>();
// EmbeddingAlgorithmRegistry::instance()->getRegisteredIds();
for (auto i : ids) {
XACCInfo("Registered Embedding Algorithm: " + i);
}
return true;
}
return false;
}
/**
* We don't allow translations for the DW Compiler.
* @param bufferVariable
......@@ -136,6 +149,15 @@ public:
XACCError("DWQMICompiler::translate - Method not implemented");
};
virtual const std::string name() const {
return "dwave-qmi";
}
virtual const std::string description() const {
return "The D-Wave QMI Compiler takes quantum machine instructions "
"and performs minor graph embedding and parameter setting.";
}
/**
* The destructor
*/
......
#include "DWQMICompiler.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 DWQMICompilerActivator : public BundleActivator
{
public:
DWQMICompilerActivator() {}
/**
* 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 c = std::make_shared<
xacc::quantum::DWQMICompiler>();
context.RegisterService<xacc::Compiler>(
c);
}
/**
* 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(DWQMICompilerActivator)
{
"bundle.symbolic_name" : "xacc_dwave_qmicompiler",
"bundle.activator" : true,
"bundle.name" : "XACC D-Wave QMI Compiler",
"bundle.description" : "This bundle provides a D-Wave QMI Compiler for Adiabatic Model QC."
}
\ No newline at end of file
......@@ -103,6 +103,15 @@ public:
auto b = std::make_shared<AQCAcceleratorBuffer>(varId, size);
storeBuffer(varId, b);
}
virtual const std::string name() const {
return "";
}
virtual const std::string description() const {
return "";
}
};
class FakeEmbedding : public EmbeddingAlgorithm {
......@@ -119,14 +128,14 @@ public:
return embedding;
}
/**
* Return the name of this Embedding Algorithm
* @return
*/
virtual std::string name() {
virtual const std::string name() const {
return "fake-embedding";
}
virtual const std::string description() const {
return "";
}
};
class Factoring15FakeEmbedding : public EmbeddingAlgorithm {
......@@ -146,14 +155,15 @@ public:
return embedding;
}
/**
* Return the name of this Embedding Algorithm
* @return
*/
virtual std::string name() {
return "fake-shor15-embedding";
virtual const std::string name() const {
return "fake-factor15-embedding";
}
virtual const std::string description() const {
return "";
}
};
......@@ -228,9 +238,9 @@ BOOST_AUTO_TEST_CASE(checkFactoring15OneToOneMapping) {
auto options = xacc::RuntimeOptions::instance();
if (options->exists("dwave-embedding")) {
(*options)["dwave-embedding"] = "fake-shor15-embedding";
(*options)["dwave-embedding"] = "fake-factor15-embedding";
} else {
options->insert(std::make_pair("dwave-embedding", "fake-shor15-embedding"));
options->insert(std::make_pair("dwave-embedding", "fake-factor15-embedding"));
}
auto acc = std::make_shared<FakeDWAcc>();
......
......@@ -35,8 +35,6 @@ if (OPENSSL_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)
include_directories(${PYTHON_INCLUDE_DIR})
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tensors)
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tensors/impl)
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tpls/eigen)
......@@ -47,25 +45,20 @@ if (OPENSSL_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/ir/functions)
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/util)
include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tpls/simpleweb)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/accelerator)
set (PACKAGE_NAME "Rigetti XACC Accelerator")
set (PACKAGE_DESCIPTION "Rigetti XACC Accelerator Framework")
set (PACKAGE_NAME "Rigetti XACC")
set (PACKAGE_DESCIPTION "Rigetti XACC Plugins")
set (LIBRARY_NAME xacc-rigetti)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC *.cpp)
add_library(${LIBRARY_NAME} SHARED ${SRC})
target_link_libraries(${LIBRARY_NAME} ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} xacc-quantum-gate ${PYTHON_LIBRARY})
#install(FILES ${HEADERS} DESTINATION include)