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

Adding AQCAcceleratorBuffer, minor clean up

parent 92244eb1
......@@ -34,6 +34,7 @@ find_package(OpenSSL)
if (OPENSSL_FOUND)
include_directories(${CMAKE_SOURCE_DIR}/quantum/aqc/ir)
include_directories(${CMAKE_SOURCE_DIR}/quantum/aqc/compiler)
include_directories(${CMAKE_SOURCE_DIR}/quantum/aqc/accelerator)
include_directories(${CMAKE_SOURCE_DIR}/tpls/rapidjson/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
......
......@@ -33,6 +33,7 @@
#include "DWQMICompiler.hpp"
#include "DWKernel.hpp"
#include "RuntimeOptions.hpp"
#include "AQCAcceleratorBuffer.hpp"
namespace xacc {
......@@ -53,6 +54,14 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string& src,
// Set the Kernel Source code
kernelSource = src;
// Here we assume, there is just one allocation
// of qubits for the D-Wave -- all of them.
// auto bufName = acc->getAllocatedBufferNames()[0];
// auto buffer = acc->getBuffer(bufName);
// auto aqcBuffer = std::dynamic_pointer_cast<AQCAcceleratorBuffer>(buffer);
// if (!aqcBuffer) {
// XACCError("Invalid AcceleratorBuffer passed to DW QMI Compiler. Must be an AQCAcceleratorBuffer.");
// }
// Here we expect we have a kernel, only one kernel,
// and that it is just machine level instructions
......@@ -119,6 +128,9 @@ std::shared_ptr<IR> DWQMICompiler::compile(const std::string& src,
// Compute the minor graph embedding
auto embedding = embeddingAlgorithm->embed(problemGraph, hardwareGraph);
// Add the embedding to the AcceleratorBuffer
// aqcBuffer->setEmbedding(embedding);
auto countEdgesBetweenSubTrees = [&](std::list<int> Ti, std::list<int> Tj) -> int {
int nEdges = 0;
for (auto i : Ti) {
......
......@@ -35,6 +35,7 @@
#include <boost/test/included/unit_test.hpp>
#include "DWQMICompiler.hpp"
#include "XACC.hpp"
#include "AQCAcceleratorBuffer.hpp"
using namespace xacc::quantum;
......@@ -59,6 +60,8 @@ public:
virtual std::shared_ptr<xacc::AcceleratorBuffer> createBuffer(
const std::string& varId) {
auto b = std::make_shared<AQCAcceleratorBuffer>(varId, 1);
storeBuffer(varId, b);
}
virtual void initialize() {
......@@ -86,6 +89,7 @@ public:
*/
virtual std::shared_ptr<xacc::AcceleratorBuffer> createBuffer(
const std::string& varId, const int size) {
auto b = std::make_shared<AQCAcceleratorBuffer>(varId, size);
}
};
......@@ -114,7 +118,7 @@ public:
};
class Shor15FakeEmbedding : public EmbeddingAlgorithm {
class Factoring15FakeEmbedding : public EmbeddingAlgorithm {
public:
virtual std::map<int, std::list<int>> embed(
......@@ -184,13 +188,13 @@ BOOST_AUTO_TEST_CASE(checkSimpleCompile) {
BOOST_AUTO_TEST_CASE(checkShor15OneToOneMapping) {
EmbeddingAlgorithmRegistry::instance()->add(Shor15FakeEmbedding().name(),
std::make_shared<EmbeddingAlgorithmRegistry::CreatorFunction>([]() {return std::make_shared<Shor15FakeEmbedding>();}));
EmbeddingAlgorithmRegistry::instance()->add(Factoring15FakeEmbedding().name(),
std::make_shared<EmbeddingAlgorithmRegistry::CreatorFunction>([]() {return std::make_shared<Factoring15FakeEmbedding>();}));
auto compiler = std::make_shared<DWQMICompiler>();
const std::string shor15QMI =
"__qpu__ shor15() {\n"
"__qpu__ factor15() {\n"
" 0 0 20\n"
" 1 1 50\n"
" 2 2 60\n"
......@@ -215,10 +219,11 @@ BOOST_AUTO_TEST_CASE(checkShor15OneToOneMapping) {
}
auto acc = std::make_shared<FakeDWAcc>();
acc->createBuffer("hello");
auto ir = compiler->compile(shor15QMI, acc);
auto qmi = ir->getKernel("shor15")->toString("");
auto qmi = ir->getKernel("factor15")->toString("");
std::cout << qmi << "\n";
......
......@@ -35,9 +35,10 @@ set (LIBRARY_NAME xacc-quantum-aqc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ir)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compiler/trivial)
file (GLOB_RECURSE HEADERS *.hpp)
file (GLOB SRC compiler/TrivialEmbeddingAlgorithm.cpp)
file (GLOB SRC compiler/trivial/TrivialEmbeddingAlgorithm.cpp) # compiler/cmr/*.cpp)
add_library(${LIBRARY_NAME} SHARED ${SRC})
......
#ifndef QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_
#define QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_
#include "AcceleratorBuffer.hpp"
namespace xacc {
namespace quantum {
class AQCAcceleratorBuffer : public AcceleratorBuffer {
protected:
std::map<int, std::list<int>> embedding;
std::vector<double> energies;
public:
AQCAcceleratorBuffer(const std::string& str, const int N) :
AcceleratorBuffer(str, N) {
}
template<typename ... Indices>
AQCAcceleratorBuffer(const std::string& str, int firstIndex,
Indices ... indices) :
AcceleratorBuffer(str, firstIndex, indices...) {
}
void setEmbedding(std::map<int, std::list<int>> emb) {
embedding = emb;
}
std::map<int, std::list<int>> getEmbedding() {
return embedding;
}
};
}
}
#endif /* QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_ */
......@@ -5,12 +5,14 @@
namespace xacc {
namespace quantum {
template<typename ResultType>
class HUBO {
public:
virtual std::shared_ptr<xacc::quantum::DWGraph> reduceToQubo(std::vector<InstructionParameter> parameters) = 0;
virtual void mapResults(std::shared_ptr<AcceleratorBuffer> resultBuffer) = 0;
virtual ResultType mapResults(std::shared_ptr<AcceleratorBuffer> resultBuffer) = 0;
virtual ~HUBO() {}
};
......
......@@ -249,6 +249,12 @@ public:
vertex(tgtIndex, *_graph.get()), *_graph.get());
}
void removeEdge(const int srcIndex, const int tgtIndex) {
auto v = vertex(srcIndex, *_graph.get());
auto u = vertex(tgtIndex, *_graph.get());
remove_edge(v, u, *_graph.get());
}
/**
* Add a vertex to this Graph.
*/
......
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