Commit 21a8641f authored by Mccaskey, Alex's avatar Mccaskey, Alex

Adding EmbeddingAlgorithm and empty DWaveCompiler

parent ea5530f7
......@@ -33,4 +33,4 @@ include_directories(${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)
add_subdirectory(qir)
add_subdirectory(gate)
add_subdirectory(aqc)
#***********************************************************************************
# 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
#
#**********************************************************************************/
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ir)
add_subdirectory(compilers)
#***********************************************************************************
# Copyright (c) 2017, 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 "DWave Compiler XACC Runtime")
set (PACKAGE_DESCIPTION "DWave Compiler XACC Programming Framework")
set (LIBRARY_NAME xacc-dwavecompiler)
file (GLOB HEADERS *.hpp)
file (GLOB SRC *.cpp)
add_library(${LIBRARY_NAME} SHARED ${SRC})
install(FILES ${HEADERS} DESTINATION include)
install(TARGETS ${LIBRARY_NAME} DESTINATION lib)
# Gather tests
file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR}" "${LIBRARY_NAME};${Boost_LIBRARIES};dl;pthread")
/***********************************************************************************
* 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
*
**********************************************************************************/
#include <regex>
#include "DWaveCompiler.hpp"
#include <boost/algorithm/string.hpp>
namespace xacc {
namespace quantum {
DWaveCompiler::DWaveCompiler() {
}
std::shared_ptr<IR> DWaveCompiler::compile(const std::string& src,
std::shared_ptr<Accelerator> acc) {
// Set the Kernel Source code
kernelSource = src;
// Replace the __qpu__ attribute with module
if (boost::contains(kernelSource, "__qpu__")) {
kernelSource.erase(kernelSource.find("__qpu__"), 7);
kernelSource = std::string("module") + kernelSource;
}
}
std::shared_ptr<IR> DWaveCompiler::compile(const std::string& src) {
kernelSource = src;
if (boost::contains(kernelSource, "__qpu__")) {
kernelSource.erase(kernelSource.find("__qpu__"), 7);
kernelSource = std::string("module") + kernelSource;
std::cout << "\n" << kernelSource << "\n";
}
auto embeddingAlgoReg = xacc::quantum::EmbeddingAlgorithmRegistry::instance();
std::cout << "WE HAVE " << embeddingAlgoReg->size() << " algorithm impls\n";
return std::make_shared<DWaveIR>();
}
}
}
/*
* DWaveCompiler.hpp
*
* Created on: May 30, 2017
* Author: aqw
*/
#ifndef QUANTUM_AQC_COMPILERS_DWAVECOMPILER_HPP_
#define QUANTUM_AQC_COMPILERS_DWAVECOMPILER_HPP_
#include "Compiler.hpp"
#include "Utils.hpp"
#include "EmbeddingAlgorithm.hpp"
#include "DWaveIR.hpp"
namespace xacc {
namespace quantum {
/**
*/
class DWaveCompiler: public xacc::Compiler {
public:
DWaveCompiler();
/**
*/
virtual std::shared_ptr<xacc::IR> compile(const std::string& src,
std::shared_ptr<Accelerator> acc);
/**
*
* @return
*/
virtual std::shared_ptr<xacc::IR> compile(const std::string& src);
/**
* Return the name of this Compiler
* @return name Compiler name
*/
virtual const std::string getName() {
return "DWave";
}
/**
* Register this Compiler with the framework.
*/
static void registerCompiler() {
xacc::RegisterCompiler<xacc::quantum::DWaveCompiler> Scaffold(
"DWave");
}
/**
* The destructor
*/
virtual ~DWaveCompiler() {}
};
RegisterCompiler(xacc::quantum::DWaveCompiler)
}
}
#endif
/***********************************************************************************
* Copyright (c) 2017, 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
*
**********************************************************************************/
#ifndef QUANTUM_AQC_COMPILERS_EMBEDDINGALGORITHM_HPP_
#define QUANTUM_AQC_COMPILERS_EMBEDDINGALGORITHM_HPP_
#include <boost/dll.hpp>
#include <map>
#include <list>
#include <memory>
#include <string>
#include "Utils.hpp"
#include "Registry.hpp"
#include "Graph.hpp"
namespace xacc {
namespace quantum {
/**
* The DWaveVertex is a subclass of the XACCVertex that
* keeps track of one vertex parameter - the qubit
* bias parameter. XACCVertex already keeps track
* of edge weights.
*/
class DWaveVertex: public XACCVertex<double> {
public:
DWaveVertex() :
XACCVertex() {
propertyNames[0] = "bias";
}
};
// Alias for Graphs of DWave Vertices
using DWaveGraph = Graph<DWaveVertex>;
/**
* The EmbeddingAlgorithm class provides an interface
* for minor graph embedding algorithms.
*
*/
class EmbeddingAlgorithm {
public:
/**
* The Constructor
*/
EmbeddingAlgorithm() {}
/**
* The Destructor
*/
virtual ~EmbeddingAlgorithm() {}
/**
* Implementations of EmbeddingAlgorithm implement this method to
* provide a valid minor graph embedding of the given problem
* graph into the given hardware graph.
*
* @param problem The problem graph to be embedded into the hardware graph
* @param hardware The hardware graph.
* @param params Any key-value string parameters to influence the algorithm.
* @return embedding A mapping of problem vertex indices to the list of hardware vertices they map to
*/
virtual std::map<int, std::list<int>> embed(std::shared_ptr<DWaveGraph> problem,
std::shared_ptr<DWaveGraph> hardware,
std::map<std::string, std::string> params = std::map<std::string,
std::string>()) = 0;
/**
* Return the name of this Embedding Algorithm
* @return
*/
virtual std::string name() = 0;
};
/**
* EmbeddingAlgorithm Registry is just an alias for a
* Registry of EmbeddingAlgorithms.
*/
using EmbeddingAlgorithmRegistry = Registry<EmbeddingAlgorithm>;
/**
* RegisterEmbeddingAlgorithm is a convenience class for
* registering custom derived EmbeddingAlgorithm classes.
*
* Creators of EmbeddingAlgorithm subclasses create an instance
* of this class with their EmbeddingAlgorithm subclass as the template
* parameter to register their EmbeddingAlgorithm with XACC. This instance
* must be created in the CPP implementation file for the EmbeddingAlgorithm
* and at global scope.
*/
template<typename T>
class RegisterEmbeddingAlgorithm {
public:
RegisterEmbeddingAlgorithm(const std::string& name) {
EmbeddingAlgorithmRegistry::instance()->add(name,
(std::function<std::shared_ptr<xacc::quantum::EmbeddingAlgorithm>()>) ([]() {
return std::make_shared<T>();
}));
}
};
}
}
#endif
/***********************************************************************************
* 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
*
**********************************************************************************/
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE DWaveCompilerTester
#include <boost/test/included/unit_test.hpp>
#include "DWaveCompiler.hpp"
#include "XACC.hpp"
using namespace xacc::quantum;
struct F {
F() :
compiler(std::make_shared<DWaveCompiler>()) {
BOOST_TEST_MESSAGE("setup fixture");
BOOST_VERIFY(compiler);
}
~F() {
BOOST_TEST_MESSAGE("teardown fixture");
}
std::shared_ptr<xacc::Compiler> compiler;
};
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_SUITE( s, F )
BOOST_AUTO_TEST_CASE(checkSimpleCompile) {
auto argc = boost::unit_test::framework::master_test_suite().argc;
auto argv = boost::unit_test::framework::master_test_suite().argv;
xacc::Initialize(argc, argv);
compiler->compile("");
xacc::Finalize();
}
BOOST_AUTO_TEST_SUITE_END()
#ifndef QUANTUM_AQC_IR_DWAVEIR_HPP_
#define QUANTUM_AQC_IR_DWAVEIR_HPP_
#include "IR.hpp"
namespace xacc {
namespace quantum {
class DWaveIR : public virtual IR {
public:
/**
* Return a assembly-like string representation of this
* intermediate representation
* @return
*/
virtual std::string toAssemblyString(const std::string& kernelName, const std::string& accBufferVarName) {
return "";
}
/**
* Persist this IR instance to the given
* output stream.
*
* @param outStream
*/
virtual void persist(std::ostream& outStream) {
return;
}
/**
* Create this IR instance from the given input
* stream.
*
* @param inStream
*/
virtual void load(std::istream& inStream) {
}
virtual void addKernel(std::shared_ptr<Function> kernel) {
}
virtual std::shared_ptr<Function> getKernel(const std::string& name) {
}
};
}
}
#endif /* QUANTUM_AQC_IR_DWAVEIR_HPP_ */
......@@ -113,10 +113,7 @@ public:
};
// Create an alias to search for.
BOOST_DLL_ALIAS(
xacc::quantum::FireTensorAccelerator::registerAccelerator,
registerAccelerator
)
RegisterAccelerator(xacc::quantum::FireTensorAccelerator)
}
}
......
......@@ -34,11 +34,8 @@
#include "Compiler.hpp"
#include "Utils.hpp"
#include <boost/algorithm/string.hpp>
#include <boost/dll/alias.hpp>
#include "ScaffoldASTConsumer.hpp"
#include "Accelerator.hpp"
namespace xacc {
......@@ -107,13 +104,8 @@ protected:
};
// Create an alias to search for.
BOOST_DLL_ALIAS(
xacc::quantum::ScaffoldCompiler::registerCompiler,
registerCompiler
)
RegisterCompiler(xacc::quantum::ScaffoldCompiler)
}
......
#add_subdirectory(fire)
add_subdirectory(boost-dll)
file(GLOB BOOST_DLL_FILES boost/dll/*.hpp)
file(GLOB BOOST_DLL_DETAIL_FILES boost/dll/detail/*.hpp)
file(GLOB BOOST_DLL_DETAIL_POSIX_FILES boost/dll/detail/posix/*.hpp)
file(GLOB BOOST_DLL_DETAIL_DEMANGLING_FILES boost/dll/detail/demangling/*.hpp)
file(GLOB BOOST_DLL_DETAIL_WINDOWS_FILES boost/dll/detail/windows/*.hpp)
install(FILES "boost/dll.hpp" DESTINATION include/boost)
install(FILES ${BOOST_DLL_FILES} DESTINATION include/boost/dll)
install(FILES ${BOOST_DLL_DETAIL_FILES} DESTINATION include/boost/dll/detail)
install(FILES ${BOOST_DLL_DETAIL_POSIX_FILES} DESTINATION include/boost/dll/detail/posix)
install(FILES ${BOOST_DLL_DETAIL_DEMANGLING_FILES} DESTINATION include/boost/dll/detail/demangling)
install(FILES ${BOOST_DLL_DETAIL_WINDOWS_FILES} DESTINATION include/boost/dll/detail/windows)
\ No newline at end of file
......@@ -32,7 +32,7 @@ set (PACKAGE_NAME "XACC Specification")
set (PACKAGE_DESCIPTION "The XACC Programming Framework")
set (LIBRARY_NAME xacc)
file (GLOB HEADERS ir/*.hpp program/*.hpp compiler/*.hpp accelerator/*.hpp utils/*.hpp)
file (GLOB HEADERS program/*.hpp XACC.hpp ir/*.hpp program/*.hpp compiler/*.hpp accelerator/*.hpp utils/*.hpp)
# Get the test files
file(GLOB test_files tests/*Tester.cpp)
......
......@@ -40,6 +40,7 @@
#include "IRTransformation.hpp"
#include "Registry.hpp"
#include "Function.hpp"
#include <boost/dll/alias.hpp>
namespace xacc {
......@@ -210,5 +211,8 @@ public:
}));
}
};
#define RegisterAccelerator(TYPE) BOOST_DLL_ALIAS(TYPE::registerAccelerator, registerAccelerator)
}
#endif
......@@ -35,6 +35,7 @@
#include <iostream>
#include "Registry.hpp"
#include "IR.hpp"
#include <boost/dll/alias.hpp>
#include "Accelerator.hpp"
namespace xacc {
......@@ -125,5 +126,8 @@ public:
}));
}
};
#define RegisterCompiler(TYPE) BOOST_DLL_ALIAS(TYPE::registerCompiler, registerCompiler)
}
#endif
......@@ -107,6 +107,14 @@ public:
dll::load_mode::append_decorations);
regFunc();
}
if (lib.has("registerEmbeddingAlgorithm")) {
typedef void (RegisterEmbeddingAlgorithm)();
auto regFunc = boost::dll::import_alias<
RegisterEmbeddingAlgorithm>(p,
"registerEmbeddingAlgorithm",
dll::load_mode::append_decorations);
regFunc();
}
}
}
}
......
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