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

general cleanup and adding documentation

parent 5eaaef35
......@@ -48,7 +48,7 @@ std::shared_ptr<AcceleratorBuffer> DWAccelerator::createBuffer(
XACCError("Invalid buffer size.");
}
auto buffer = std::make_shared<AcceleratorBuffer>(varId, size);
auto buffer = std::make_shared<AQCAcceleratorBuffer>(varId, size);
storeBuffer(varId, buffer);
return buffer;
}
......
......@@ -38,6 +38,7 @@
#include <boost/filesystem.hpp>
#include "DWKernel.hpp"
#include "DWQMI.hpp"
#include "AQCAcceleratorBuffer.hpp"
#define RAPIDJSON_HAS_STDSTRING 1
......@@ -51,6 +52,10 @@ using namespace xacc;
namespace xacc {
namespace quantum {
/**
* Wrapper for information related to the remote
* D-Wave solver.
*/
struct DWSolver {
std::string name;
std::string description;
......@@ -63,11 +68,18 @@ struct DWSolver {
};
/**
*
* The DWAccelerator is an XACC Accelerator that
* takes D-Wave IR and executes the quantum machine
* instructions via remote HTTP invocations.
*/
class DWAccelerator : virtual public Accelerator {
class DWAccelerator : public Accelerator {
public:
/**
* The constructor
*/
DWAccelerator() {}
/**
* Create, store, and return an AcceleratorBuffer with the given
* variable id string and of the given number of bits.
......@@ -150,11 +162,19 @@ public:
"dwave", acc.getOptions());
}
DWAccelerator() {
}
/**
* Initialize this DWAccelerator with information
* about the remote Qubist solvers
*/
virtual void initialize();
/**
* Create and return an AQCAcceleratorBuffer of size
* dictated by the current solver being used.
*
* @param varId The name of this buffer
* @return buffer The AcceleratorBuffer
*/
virtual std::shared_ptr<AcceleratorBuffer> createBuffer(
const std::string& varId) {
auto options = RuntimeOptions::instance();
......@@ -166,7 +186,7 @@ public:
XACCError(solverName + " is not available for creating a buffer.");
}
auto solver = availableSolvers[solverName];
auto buffer = std::make_shared<AcceleratorBuffer>(varId, solver.nQubits);
auto buffer = std::make_shared<AQCAcceleratorBuffer>(varId, solver.nQubits);
storeBuffer(varId, buffer);
return buffer;
}
......@@ -178,9 +198,25 @@ public:
protected:
/**
* Reference to the D-Wave API Token
*/
std::string apiKey;
/**
* Reference to the remote D-Wave Qubist URL
*/
std::string url;
/**
* Reference to the HTTP Post/Get headers
*/
std::map<std::string, std::string> headers;
/**
* Reference to the mapping of solver names
* to Solver Type.
*/
std::map<std::string, DWSolver> availableSolvers;
private:
......
......@@ -39,9 +39,6 @@ namespace xacc {
namespace quantum {
DWQMICompiler::DWQMICompiler() {
}
std::shared_ptr<IR> DWQMICompiler::compile(const std::string& src,
std::shared_ptr<Accelerator> acc) {
......
......@@ -42,19 +42,38 @@ namespace xacc {
namespace quantum {
/**
* The DWQMICompiler is an XACC Compiler that compiles
* D-Wave quantum machine instructions to produce an
* appropriate Ising form for execution on the D-Wave QPU.
*
* This compilation leverages XACC EmbeddingAlgorithms to
* compute the minor graph embedding represented by the
* input source kernel code to output the embedded Ising
* graph for D-Wave execution.
*/
class DWQMICompiler: public xacc::Compiler {
public:
DWQMICompiler();
/**
* The Compiler.
*/
DWQMICompiler() {}
/**
* Compile the given kernel code for the
* given D-Wave Accelerator.
*
* @param src The QMI source code
* @param acc Reference to the D-Wave Accelerator
* @return
*/
virtual std::shared_ptr<xacc::IR> compile(const std::string& src,
std::shared_ptr<Accelerator> acc);
/**
* This method is not implemented - we must always have
* D-Wave Accelerator connectivity information for compilation.
*
* @return
*/
......@@ -68,6 +87,11 @@ public:
return "dwave-qmi";
}
/**
* Return the command line options for this compiler
*
* @return options Description of command line options.
*/
virtual std::shared_ptr<options_description> getOptions() {
auto desc = std::make_shared<options_description>(
"D-Wave QMI Compiler Options");
......@@ -85,6 +109,12 @@ public:
"dwave-qmi", c.getOptions());
}
/**
* We don't allow translations for the DW Compiler.
* @param bufferVariable
* @param function
* @return
*/
virtual const std::string translate(const std::string& bufferVariable,
std::shared_ptr<Function> function) {
XACCError("DWQMICompiler::translate - Method not implemented");
......
/***********************************************************************************
* 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_ACCELERATOR_AQCACCELERATORBUFFER_HPP_
#define QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_
#include "AcceleratorBuffer.hpp"
namespace xacc {
namespace quantum {
/**
* The AQCAcceleratorBuffer is an AcceleratorBuffer that keeps
* track of the problem-specific embedding into the
* hardware graph. It also tracks AQC QPU computed
* energies.
*/
class AQCAcceleratorBuffer : public AcceleratorBuffer {
protected:
/**
* The minor graph embedding for the problem these
* results represent.
*/
std::map<int, std::list<int>> embedding;
/**
* The energies computed as part of this execution.
*/
std::vector<double> energies;
public:
/**
* The constructor
* @param str The name of this buffer
* @param N The number of bits represented by this buffer
*/
AQCAcceleratorBuffer(const std::string& str, const int N) :
AcceleratorBuffer(str, N) {
}
/**
* The constructor
* @param str
* @param firstIndex
* @param indices
*/
template<typename ... Indices>
AQCAcceleratorBuffer(const std::string& str, int firstIndex,
Indices ... indices) :
AcceleratorBuffer(str, firstIndex, indices...) {
}
/**
* Set the minor graph embedding for the problem
* solved during this execution .
*
* @param emb The minor graph embedding
*/
void setEmbedding(std::map<int, std::list<int>> emb) {
embedding = emb;
}
/**
* Return the minor graph embedding.
*
* @return emb The minor graph embedding
*/
std::map<int, std::list<int>> getEmbedding() {
return embedding;
}
......@@ -39,4 +103,4 @@ public:
}
}
#endif /* QUANTUM_AQC_ACCELERATOR_AQCACCELERATORBUFFER_HPP_ */
#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_COMPILER_HUBO_HPP_
#define QUANTUM_AQC_COMPILER_HUBO_HPP_
......@@ -6,14 +36,49 @@
namespace xacc {
namespace quantum {
/**
* HUBO is an interface for higher-order unconstrained
* binary optimization problems. It provides a method
* for subclasses to implement that takes a set of input
* parameters and maps the problem down to a
* quadratic unconstrained binary optimization problem,
* in the form of a Graph.
*
* It takes a template parameter describing the
* return type of the mapResults method - which
* takes AQC QPU execution results and maps them to the
* higher-order problem result.
*/
template<typename ResultType>
class HUBO {
public:
virtual std::shared_ptr<xacc::quantum::DWGraph> reduceToQubo(std::vector<InstructionParameter> parameters) = 0;
virtual ResultType mapResults(std::shared_ptr<AcceleratorBuffer> resultBuffer) = 0;
virtual ~HUBO() {}
/**
* Map this HUBO problem to a quadratic unconstrained
* binary optimization problem.
*
* @param parameters Any input parameters needed to set the problem up
* @return quboGraph The QUBO represented as a graph
*/
virtual std::shared_ptr<xacc::quantum::DWGraph> reduceToQubo(
std::vector<InstructionParameter> parameters) = 0;
/**
* Take the low-level AQC QPU result output and construct result of
* HUBO problem .
*
* @param resultBuffer The AcceleratorBuffer containing the AQC QPU results.
* @return results Custom Type representing the result.
*/
virtual ResultType mapResults(
std::shared_ptr<AcceleratorBuffer> resultBuffer) = 0;
/**
* The destructor
*/
virtual ~HUBO() {
}
};
}
......
/*
* DWGraph.hpp
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Created on: Jul 11, 2017
* Author: aqw
*/
* 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_IR_DWGRAPH_HPP_
#define QUANTUM_AQC_IR_DWGRAPH_HPP_
......
/***********************************************************************************
* 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_IR_DWIR_HPP_
#define QUANTUM_AQC_IR_DWIR_HPP_
......
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