Commit 6574086c authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Syncing up work on new QIR and GateQIR

parent 078b04b0
......@@ -28,4 +28,8 @@
# Initial API and implementation - Alex McCaskey
#
#**********************************************************************************/
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/qir)
add_subdirectory(qir)
add_subdirectory(gate)
/*
* QIR.hpp
*
* Created on: Apr 12, 2017
* Author: aqw
*/
#ifndef QUANTUM_QIR_HPP_
#define QUANTUM_QIR_HPP_
#include "IR.hpp"
template<typename VertexType>
class QIR : public virtual xacc::Graph<VertexType> {
public:
virtual void generateGraph() = 0;
virtual ~QIR() {}
};
#endif /* QUANTUM_QIR_HPP_ */
......@@ -29,7 +29,10 @@
#
#**********************************************************************************/
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gateir)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gateir/instructions)
add_subdirectory(gateir)
add_subdirectory(compilers)
add_subdirectory(accelerators)
add_subdirectory(utils)
......
/*
* GateQIR.hpp
*
* Created on: Apr 12, 2017
* Author: aqw
*/
#ifndef QUANTUM_GATE_GATEQIR_HPP_
#define QUANTUM_GATE_GATEQIR_HPP_
#include "QIR.hpp"
#include "QuantumCircuit.hpp"
class GateQIR : public virtual QIR<xacc::quantum::CircuitNode> {
protected:
std::vector<QInstruction> instructions;
virtual ~GateQIR() {}
};
#endif
......@@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(checkConstruction) {
std::istringstream iss(irstr);
auto graphir = std::make_shared<xacc::GraphIR<QuantumCircuit>>();
graphir->read(iss);
graphir->load(iss);
acc.execute(qreg1, graphir);
auto qreg = std::static_pointer_cast<SimulatedQubits<10>>(qreg1);
......
......@@ -87,7 +87,7 @@ public:
return qasm;
} else {
XACCError(
"Cannot find scaffold compiler. Make sure scaffcc is in PATH and executable.")
"Cannot find scaffold compiler. Make sure scaffcc is in PATH and executable.");
}
}
};
......
#***********************************************************************************
# 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 "XACC Quantum Gate IR Runtime")
set (PACKAGE_DESCIPTION "XACC Quantum Gate Model Intermediate Representation")
set (LIBRARY_NAME xacc-gateqir)
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};${CMAKE_CURRENT_SOURCE_DIR}/instructions" "${LIBRARY_NAME};${Boost_LIBRARIES};xacc-qir")
/***********************************************************************************
* 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_GATE_GATEIR_GATEINSTRUCTION_HPP_
#define QUANTUM_GATE_GATEIR_GATEINSTRUCTION_HPP_
#include "QInstruction.hpp"
namespace xacc {
namespace quantum {
class GateInstruction: public virtual QInstruction {
protected:
int gateId;
std::string gateName;
int circuitLayer;
std::vector<int> qbits;
public:
GateInstruction() :
gateId(0), gateName("UNKNOWN"), circuitLayer(0), qbits(
std::vector<int> { }) {
}
GateInstruction(int id, int layer, std::string name, std::vector<int> qubts) :
gateId(id), circuitLayer(layer), gateName(name), qbits(qubts) {
}
virtual const int getId() {
return gateId;
}
virtual const std::string getName() {
return gateName;
}
virtual const int layer() {
return circuitLayer;
}
virtual const std::vector<int> qubits() {
return qbits;
}
virtual const std::string toString(const std::string bufferVarName) {
auto str = gateName + " ";
for (auto q : qubits()) {
str += bufferVarName + std::to_string(q) + ",";
}
// Remove trailing comma
str = str.substr(0, str.length() - 1);
return str;
}
virtual ~GateInstruction() {
}
};
}
}
#endif /* QUANTUM_GATE_GATEIR_GATEINSTRUCTION_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
*
**********************************************************************************/
#include "GateQIR.hpp"
namespace xacc {
namespace quantum {
void GateQIR::generateGraph() {
}
std::string GateQIR::toString() {
}
void GateQIR::persist(std::ostream& outStream) {
}
// FOR IR
void GateQIR::load(std::istream& inStream) {
}
// FOR GRAPH
void GateQIR::read(std::istream& stream) {
}
}
}
/***********************************************************************************
* 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_GATE_GATEQIR_HPP_
#define QUANTUM_GATE_GATEQIR_HPP_
#include "../../qir/QIR.hpp"
namespace xacc {
namespace quantum {
/**
* CircuitNode subclasses QCIVertex to provide the following
* parameters in the given order:
*
* Parameters: Gate, Layer (ie time sequence), Gate Vertex Id,
* Qubit Ids that the gate acts on, enabled state, vector of parameters names
*/
class CircuitNode: public XACCVertex<std::string, int, int,
std::vector<int>, bool, std::vector<std::string>> {
public:
CircuitNode() :
XACCVertex() {
propertyNames[0] = "Gate";
propertyNames[1] = "Circuit Layer";
propertyNames[2] = "Gate Vertex Id";
propertyNames[3] = "Gate Acting Qubits";
propertyNames[4] = "Enabled";
propertyNames[5] = "RuntimeParameters";
// by default all circuit nodes
// are enabled and
std::get<4>(properties) = true;
}
};
/**
*
*/
class GateQIR: public virtual xacc::quantum::QIR<xacc::quantum::CircuitNode> {
public:
GateQIR() : QFunction() {}
GateQIR(int id, const std::string name) : QFunction(id, name) {}
/**
*
*/
virtual void generateGraph();
/**
* Return a string representation of this
* intermediate representation
* @return
*/
virtual std::string toString();
/**
* Persist this IR instance to the given
* output stream.
*
* @param outStream
*/
virtual void persist(std::ostream& outStream);
/**
* Create this IR instance from the given input
* stream.
*
* @param inStream
*/
virtual void load(std::istream& inStream);
/**
* This is the implementation of the Graph.read method...
*
* Read in a graphviz dot graph from the given input
* stream. This is left for subclasses.
*
* @param stream
*/
virtual void read(std::istream& stream);
/**
* The destructor
*/
virtual ~GateQIR() {
}
};
}
}
#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_GATE_GATEIR_PARAMETERIZEDGATEINSTRUCTION_HPP_
#define QUANTUM_GATE_GATEIR_PARAMETERIZEDGATEINSTRUCTION_HPP_
#include "GateInstruction.hpp"
#include "XACCError.hpp"
namespace xacc {
namespace quantum {
template<typename ... InstructionParameter>
class ParameterizedGateInstruction: public virtual GateInstruction {
protected:
std::tuple<InstructionParameter...> params;
public:
ParameterizedGateInstruction(int id, int layer, std::string name,
std::vector<int> qubts, InstructionParameter ... pars) :
GateInstruction(id, layer, name, qubts), params(
std::make_tuple(pars...)) {
}
auto getParameter(const std::size_t idx) {
if(idx + 1 > sizeof...(InstructionParameter)) {
XACCError("Invalid Parameter requested from Parameterized Gate Instruction.");
}
return xacc::runtime_get(params, idx);
}
virtual const std::string toString(const std::string bufferVarName) {
auto str = gateName;
str += "(";
xacc::for_each(params, [&](auto element) {
str += std::to_string(element) + ",";
});
str += str.substr(0, str.length() - 1) + ") ";
for (auto q : qubits()) {
str += bufferVarName + std::to_string(q) + ",";
}
// Remove trailing comma
str = str.substr(0, str.length() - 1);
return str;
}
};
}
}
#endif /* QUANTUM_GATE_GATEIR_PARAMETERIZEDGATEINSTRUCTION_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_GATE_GATEIR_INSTRUCTIONS_CNOT_HPP_
#define QUANTUM_GATE_GATEIR_INSTRUCTIONS_CNOT_HPP_
#include "GateInstruction.hpp"
class QInstructionVisitor;
namespace xacc {
namespace quantum {
/**
*
*/
class CNOT: public virtual GateInstruction {
public:
CNOT(int id, int layer, int srcqbit, int tgtqbit) :
GateInstruction(id, layer, "CNOT", std::vector<int> { srcqbit,
tgtqbit }) {
}
virtual void accept(QInstructionVisitor& visitor) {
}
};
}
}
#endif /* QUANTUM_GATE_GATEIR_INSTRUCTIONS_CNOT_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_GATE_IR_HADAMARD_HPP_
#define QUANTUM_GATE_IR_HADAMARD_HPP_
#include "GateInstruction.hpp"
class QInstructionVisitor;
namespace xacc {
namespace quantum {
/**
*
*/
class Hadamard : public virtual GateInstruction {
public:
Hadamard(int id, int layer, int qbit) :
GateInstruction(id, layer, "H", std::vector<int> { qbit }) {
}
virtual void accept(QInstructionVisitor& visitor) {
}
};
}
}
#endif /* QUANTUM_GATE_IR_HADAMARD_HPP_ */
/***********************************************************************************
* Copyright (c) 2017, UT-Battelle
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without