Commit 76229d9e authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

Removing Compiler template parameter. Removing common submodule, adding fire...

Removing Compiler template parameter. Removing common submodule, adding fire as submodule. general clean up
parent 0b4c5d53
[submodule "tpls/common"] [submodule "tpls/fire"]
path = tpls/common path = tpls/fire
url = https://github.com/ORNL-QCI/common url = https://github.com/jayjaybillings/fire
...@@ -38,9 +38,9 @@ message(STATUS "C++ version ${CXX_STANDARD} configured.") ...@@ -38,9 +38,9 @@ message(STATUS "C++ version ${CXX_STANDARD} configured.")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")
if (EXISTS ${CMAKE_SOURCE_DIR}/tpls/common) if (EXISTS ${CMAKE_SOURCE_DIR}/tpls/fire)
message(STATUS "Common found in tpls") message(STATUS "Fire found in tpls")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/cmake/Modules") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tpls/fire/cmake/Modules")
include(tests) include(tests)
endif() endif()
...@@ -67,9 +67,6 @@ include_directories("${CMAKE_SOURCE_DIR}/xacc/compiler") ...@@ -67,9 +67,6 @@ include_directories("${CMAKE_SOURCE_DIR}/xacc/compiler")
include_directories("${CMAKE_SOURCE_DIR}/xacc/program") include_directories("${CMAKE_SOURCE_DIR}/xacc/program")
include_directories("${CMAKE_SOURCE_DIR}/xacc/accelerator") include_directories("${CMAKE_SOURCE_DIR}/xacc/accelerator")
include_directories("${CMAKE_SOURCE_DIR}/xacc/utils") include_directories("${CMAKE_SOURCE_DIR}/xacc/utils")
include_directories("${CMAKE_SOURCE_DIR}/tpls/common/factory")
include_directories("${CMAKE_SOURCE_DIR}/tpls/common/graph")
include_directories("${CMAKE_SOURCE_DIR}/tpls/common/exception")
add_subdirectory(tpls) add_subdirectory(tpls)
add_subdirectory(xacc) add_subdirectory(xacc)
......
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
#**********************************************************************************/ #**********************************************************************************/
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/accelerators) include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/accelerators)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/accelerators/firetensoraccelerator) include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/accelerators/firetensoraccelerator)
include_directories(${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tpls/eigen) include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tpls/eigen)
include_directories(${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tensors) include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tensors)
include_directories(${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tensors/impl) include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tensors/impl)
include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/utils) include_directories(${CMAKE_SOURCE_DIR}/quantum/gate/utils)
add_executable(teleport_scaffold teleport_scaffold.cpp) add_executable(teleport_scaffold teleport_scaffold.cpp)
......
...@@ -29,10 +29,10 @@ ...@@ -29,10 +29,10 @@
# #
#**********************************************************************************/ #**********************************************************************************/
include_directories(${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tensor) include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tensor)
include_directories(${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tpls/eigen) include_directories(${CMAKE_SOURCE_DIR}/tpls/fire/tpls/eigen)
# Gather tests # Gather tests
file (GLOB test_files tests/*.cpp) file (GLOB test_files tests/*.cpp)
add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/firetensoraccelerator;${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tensors;${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tensors/impl;${CMAKE_SOURCE_DIR}/tpls/common/tpls/fire/tpls/eigen" "${Boost_LIBRARIES}") add_tests("${test_files}" "${CMAKE_CURRENT_SOURCE_DIR};${CMAKE_CURRENT_SOURCE_DIR}/firetensoraccelerator;${CMAKE_SOURCE_DIR}/tpls/fire/tensors;${CMAKE_SOURCE_DIR}/tpls/fire/tensors/impl;${CMAKE_SOURCE_DIR}/tpls/fire/tpls/eigen" "${Boost_LIBRARIES}")
...@@ -86,7 +86,7 @@ public: ...@@ -86,7 +86,7 @@ public:
// Get the requested qubit buffer // Get the requested qubit buffer
auto qubits = this->allocatedBuffers[bufferId]; auto qubits = this->allocatedBuffers[bufferId];
if (!qubits) { if (!qubits) {
QCIError("Invalid buffer id. Could not get qubit buffer."); XACCError("Invalid buffer id. Could not get qubit buffer.");
} }
// Set the size // Set the size
...@@ -95,7 +95,7 @@ public: ...@@ -95,7 +95,7 @@ public:
// Cast to a GraphIR, if we can... // Cast to a GraphIR, if we can...
auto graphir = std::dynamic_pointer_cast<QuantumGraphIR>(ir); auto graphir = std::dynamic_pointer_cast<QuantumGraphIR>(ir);
if (!graphir) { if (!graphir) {
QCIError("Invalid IR - this Accelerator only accepts GraphIR<Graph<CircuitNode>>."); XACCError("Invalid IR - this Accelerator only accepts GraphIR<Graph<CircuitNode>>.");
} }
// Get the Graph and related info // Get the Graph and related info
...@@ -144,7 +144,7 @@ public: ...@@ -144,7 +144,7 @@ public:
auto qubitWeNeed = std::get<3>(gate.properties)[0]; auto qubitWeNeed = std::get<3>(gate.properties)[0];
auto qubitFound = qubitIdToMeasuredResult.find(qubitWeNeed); auto qubitFound = qubitIdToMeasuredResult.find(qubitWeNeed);
if (qubitFound == qubitIdToMeasuredResult.end()) { if (qubitFound == qubitIdToMeasuredResult.end()) {
QCIError("Invalid conditional node - this qubit has not been measured."); XACCError("Invalid conditional node - this qubit has not been measured.");
} }
auto result = qubitIdToMeasuredResult[qubitWeNeed]; auto result = qubitIdToMeasuredResult[qubitWeNeed];
...@@ -247,7 +247,7 @@ public: ...@@ -247,7 +247,7 @@ public:
// Sum them up // Sum them up
localU = localU + temp; localU = localU + temp;
} else { } else {
QCIError("Can only simulate one and two qubit gates."); XACCError("Can only simulate one and two qubit gates.");
} }
// Make sure that localU is the correct size // Make sure that localU is the correct size
...@@ -288,7 +288,7 @@ protected: ...@@ -288,7 +288,7 @@ protected:
auto rotation = std::exp(i * param); auto rotation = std::exp(i * param);
g.setValues( { { 1, 0 }, { 0, rotation } }); g.setValues( { { 1, 0 }, { 0, rotation } });
} else { } else {
QCIError("We don't know what this gate is... yet."); XACCError("We don't know what this gate is... yet.");
} }
return g; return g;
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#include <boost/test/included/unit_test.hpp> #include <boost/test/included/unit_test.hpp>
#include "SimulatedQubits.hpp" #include "SimulatedQubits.hpp"
using namespace qci::common;
using namespace xacc::quantum; using namespace xacc::quantum;
BOOST_AUTO_TEST_CASE(checkConstruction) { BOOST_AUTO_TEST_CASE(checkConstruction) {
......
...@@ -32,12 +32,10 @@ ...@@ -32,12 +32,10 @@
#define QUANTUM_GATE_SCAFFOLD_SCAFFCCAPI_HPP_ #define QUANTUM_GATE_SCAFFOLD_SCAFFCCAPI_HPP_
#include <cstdlib> #include <cstdlib>
#include "QCIError.hpp" #include "XACCError.hpp"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
using namespace qci::common;
namespace scaffold { namespace scaffold {
/** /**
...@@ -88,7 +86,7 @@ public: ...@@ -88,7 +86,7 @@ public:
// Return the QASM // Return the QASM
return qasm; return qasm;
} else { } else {
QCIError( 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.")
} }
} }
......
...@@ -29,11 +29,8 @@ ...@@ -29,11 +29,8 @@
* *
**********************************************************************************/ **********************************************************************************/
#include "ScaffoldCompiler.hpp" #include "ScaffoldCompiler.hpp"
#include "GraphIR.hpp"
#include <regex> #include <regex>
#include "ScaffCCAPI.hpp"
#include "QasmToGraph.hpp"
#include "QuantumCircuit.hpp"
namespace xacc { namespace xacc {
...@@ -206,7 +203,51 @@ void ScaffoldCompiler::modifySource() { ...@@ -206,7 +203,51 @@ void ScaffoldCompiler::modifySource() {
// std::cout << "\n" << kernelSource << "\n"; // std::cout << "\n" << kernelSource << "\n";
} }
std::shared_ptr<IR> ScaffoldCompiler::compile() {
std::shared_ptr<IR> ScaffoldCompiler::compile(const std::string& src,
std::shared_ptr<IAccelerator> acc) {
kernelSource = src;
kernelArgsToMap();
// Set the accelerator
accelerator = acc;
// Get the bit variable type string
auto bitTypeStr = getBitType();
// Get the qubit variable name, if it exists
std::string varName;
for (auto it = typeToVarKernelArgs.begin(); it != typeToVarKernelArgs.end();
it++) {
if (boost::contains(it->first, bitTypeStr)) {
varName = it->second;
auto nBits = accelerator->getBufferSize(varName);
boost::replace_first(kernelSource,
std::string(bitTypeStr + " " + varName),
std::string(
bitTypeStr + " " + varName + "["
+ std::to_string(nBits) + "]"));
// Replace the varname in the map with varName[#]
typeToVarKernelArgs[bitTypeStr] = varName + "["
+ std::to_string(nBits) + "]";
}
}
return compile(kernelSource);
}
std::shared_ptr<IR> ScaffoldCompiler::compile(const std::string& src) {
kernelSource = src;
if (!accelerator) {
kernelArgsToMap();
}
modifySource();
// Create an instance of our ScaffCC API // Create an instance of our ScaffCC API
// so that we can interact with a locally installed // so that we can interact with a locally installed
...@@ -273,6 +314,6 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() { ...@@ -273,6 +314,6 @@ std::shared_ptr<IR> ScaffoldCompiler::compile() {
} // end namespace xacc } // end namespace xacc
// Required in CPP file to be discovered by factory pattern // Required in CPP file to be discovered by factory pattern
REGISTER_QCIOBJECT_WITH_QCITYPE(xacc::quantum::ScaffoldCompiler, "compiler", REGISTER_XACCOBJECT_WITH_XACCTYPE(xacc::quantum::ScaffoldCompiler, "compiler",
"scaffold"); "scaffold");
...@@ -31,13 +31,14 @@ ...@@ -31,13 +31,14 @@
#ifndef QUANTUM_SCAFFOLDCOMPILER_HPP_ #ifndef QUANTUM_SCAFFOLDCOMPILER_HPP_
#define QUANTUM_SCAFFOLDCOMPILER_HPP_ #define QUANTUM_SCAFFOLDCOMPILER_HPP_
#include <iostream>
#include <memory>
#include "AbstractFactory.hpp"
#include "Compiler.hpp" #include "Compiler.hpp"
#include "QCIError.hpp" #include "XACCError.hpp"
#include <boost/algorithm/string.hpp>
using namespace qci::common; #include "Accelerator.hpp"
#include "GraphIR.hpp"
#include "ScaffCCAPI.hpp"
#include "QasmToGraph.hpp"
#include "QuantumCircuit.hpp"
namespace xacc { namespace xacc {
...@@ -49,7 +50,7 @@ namespace quantum { ...@@ -49,7 +50,7 @@ namespace quantum {
* to handle generation of quantum assembly language (or QASM) * to handle generation of quantum assembly language (or QASM)
* using an installed Scaffold compiler. * using an installed Scaffold compiler.
*/ */
class ScaffoldCompiler : public Compiler<ScaffoldCompiler> { class ScaffoldCompiler : public xacc::Compiler {
public: public:
...@@ -58,7 +59,10 @@ public: ...@@ -58,7 +59,10 @@ public:
* XACC intermediate representation instance. * XACC intermediate representation instance.
* @return ir XACC intermediate representation * @return ir XACC intermediate representation
*/ */
virtual std::shared_ptr<IR> compile(); virtual std::shared_ptr<xacc::IR> compile(const std::string& src,
std::shared_ptr<IAccelerator> acc);
virtual std::shared_ptr<xacc::IR> compile(const std::string& src);
/** /**
* *
...@@ -94,6 +98,49 @@ protected: ...@@ -94,6 +98,49 @@ protected:
std::map<int, std::vector<std::string>> gateIdToParameterMap; std::map<int, std::vector<std::string>> gateIdToParameterMap;
/**
*
*/
std::map<std::string, std::string> typeToVarKernelArgs;
std::vector<std::string> orderOfArgs;
std::vector<std::string> orderedVarNames;
virtual std::vector<std::string> getKernelArgumentVariableNames() {
return orderedVarNames;
}
void kernelArgsToMap() {
auto firstParen = kernelSource.find_first_of('(');
auto secondParen = kernelSource.find_first_of(')', firstParen);
auto functionArguments = kernelSource.substr(firstParen+1, (secondParen-firstParen)-1);
int counter = 0;
if (!functionArguments.empty()) {
// First search the prototype to see if it has
// and argument that declares the accelerator bit buffer
// to use in the kernel
std::vector<std::string> splitArgs, splitTypeVar;
boost::split(splitArgs, functionArguments, boost::is_any_of(","));
std::string varName;
for (int i = 0; i < splitArgs.size(); i++) {
// split type from var name
auto s = splitArgs[i];
boost::trim(s);
boost::split(splitTypeVar, s, boost::is_any_of(" "));
auto type = splitTypeVar[0];
auto var = splitTypeVar[1];
boost::trim(type);
boost::trim(var);
typeToVarKernelArgs.insert(std::make_pair(type, var));
orderOfArgs.push_back(type);
orderedVarNames.push_back(var);
}
}
}
}; };
} }
......
...@@ -32,20 +32,32 @@ ...@@ -32,20 +32,32 @@
#define BOOST_TEST_MODULE ScaffoldCompilerTester #define BOOST_TEST_MODULE ScaffoldCompilerTester
#include <boost/test/included/unit_test.hpp> #include <boost/test/included/unit_test.hpp>
#include "AbstractFactory.hpp"
#include "Compiler.hpp"
#include "QasmToGraph.hpp"
#include "GraphIR.hpp"
#include "ScaffoldCompiler.hpp" #include "ScaffoldCompiler.hpp"
#include "XACCFactory.hpp"
using namespace qci::common;
using namespace xacc::quantum; using namespace xacc::quantum;
using GraphType = QuantumCircuit;
struct F {
F() :
compiler(
xacc::XACCFactory::createAndCast<xacc::Compiler>("compiler",
"scaffold")) {
BOOST_TEST_MESSAGE("setup fixture");
BOOST_VERIFY(compiler);
}
~F() {
BOOST_TEST_MESSAGE("teardown fixture");
}
BOOST_AUTO_TEST_CASE(checkSimpleCompile) { std::shared_ptr<xacc::Compiler> compiler;
using GraphType = QuantumCircuit; };
auto compiler = qci::common::AbstractFactory::createAndCast<xacc::ICompiler>("compiler", "scaffold"); //____________________________________________________________________________//
BOOST_VERIFY(compiler);
BOOST_FIXTURE_TEST_SUITE( s, F )
BOOST_AUTO_TEST_CASE(checkSimpleCompile) {
const std::string src("__qpu__ eprCreation () {\n" const std::string src("__qpu__ eprCreation () {\n"
" qbit qreg[2];\n" " qbit qreg[2];\n"
...@@ -55,7 +67,8 @@ BOOST_AUTO_TEST_CASE(checkSimpleCompile) { ...@@ -55,7 +67,8 @@ BOOST_AUTO_TEST_CASE(checkSimpleCompile) {
auto ir = compiler->compile(src); auto ir = compiler->compile(src);
BOOST_VERIFY(ir); BOOST_VERIFY(ir);
auto graphir = std::dynamic_pointer_cast<xacc::GraphIR<GraphType>>(ir);
auto graphir = std::dynamic_pointer_cast<xacc::GraphIR<QuantumCircuit>>(ir);
BOOST_VERIFY(graphir); BOOST_VERIFY(graphir);
// The above code should produce a graph // The above code should produce a graph
...@@ -70,13 +83,6 @@ BOOST_AUTO_TEST_CASE(checkSimpleCompile) { ...@@ -70,13 +83,6 @@ BOOST_AUTO_TEST_CASE(checkSimpleCompile) {
} }
BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) { BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) {
using GraphType = QuantumCircuit;
auto compiler =
qci::common::AbstractFactory::createAndCast<xacc::ICompiler>(
"compiler", "scaffold");
BOOST_VERIFY(compiler);
const std::string src("__qpu__ teleport () {\n" const std::string src("__qpu__ teleport () {\n"
" qbit qreg[3];\n" " qbit qreg[3];\n"
" cbit creg[2];\n" " cbit creg[2];\n"
...@@ -92,7 +98,7 @@ BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) { ...@@ -92,7 +98,7 @@ BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) {
auto ir = compiler->compile(src); auto ir = compiler->compile(src);
BOOST_VERIFY(ir); BOOST_VERIFY(ir);
auto graphir = std::dynamic_pointer_cast<xacc::GraphIR<GraphType>>(ir); auto graphir = std::dynamic_pointer_cast<xacc::GraphIR<QuantumCircuit>>(ir);
BOOST_VERIFY(graphir); BOOST_VERIFY(graphir);
graphir->persist(std::cout); graphir->persist(std::cout);
...@@ -102,12 +108,6 @@ BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) { ...@@ -102,12 +108,6 @@ BOOST_AUTO_TEST_CASE(checkCodeWithMeasurementIf) {
} }
BOOST_AUTO_TEST_CASE(checkCodeWithArgument) { BOOST_AUTO_TEST_CASE(checkCodeWithArgument) {
using GraphType = QuantumCircuit;
auto compiler =
qci::common::AbstractFactory::createAndCast<xacc::ICompiler>(
"compiler", "scaffold");
BOOST_VERIFY(compiler);
const std::string src("__qpu__ kernel (qbit qreg[1], double phi) {\n" const std::string src("__qpu__ kernel (qbit qreg[1], double phi) {\n"
" Rz(qreg[0], phi);\n" " Rz(qreg[0], phi);\n"
...@@ -115,8 +115,10 @@ BOOST_AUTO_TEST_CASE(checkCodeWithArgument) { ...@@ -115,8 +115,10 @@ BOOST_AUTO_TEST_CASE(checkCodeWithArgument) {
auto ir = compiler->compile(src); auto ir = compiler->compile(src);
BOOST_VERIFY(ir); BOOST_VERIFY(ir);
auto graphir = std::dynamic_pointer_cast<xacc::GraphIR<GraphType>>(ir); auto graphir = std::dynamic_pointer_cast<xacc::GraphIR<QuantumCircuit>>(ir);
BOOST_VERIFY(graphir); BOOST_VERIFY(graphir);
graphir->persist(std::cout); graphir->persist(std::cout);
} }
BOOST_AUTO_TEST_SUITE_END()
...@@ -57,7 +57,6 @@ public: ...@@ -57,7 +57,6 @@ public:
const std::string& flatQasmStr) { const std::string& flatQasmStr) {
// Local Declarations // Local Declarations
using namespace qci::common;
QuantumCircuit graph; QuantumCircuit graph;
std::map<std::string, int> qubitVarNameToId; std::map<std::string, int> qubitVarNameToId;
std::vector<std::string> qasmLines; std::vector<std::string> qasmLines;
......
...@@ -43,11 +43,11 @@ namespace quantum { ...@@ -43,11 +43,11 @@ namespace quantum {
* Parameters: Gate, Layer (ie time sequence), Gate Vertex Id, * Parameters: Gate, Layer (ie time sequence), Gate Vertex Id,
* Qubit Ids that the gate acts on, enabled state, vector of parameters names * Qubit Ids that the gate acts on, enabled state, vector of parameters names
*/ */
class CircuitNode: public qci::common::QCIVertex<std::string, int, int, class CircuitNode: public XACCVertex<std::string, int, int,
std::vector<int>, bool, std::vector<std::string>> { std::vector<int>, bool, std::vector<std::string>> {
public: public:
CircuitNode() : CircuitNode() :
QCIVertex() { XACCVertex() {
propertyNames[0] = "Gate"; propertyNames[0] = "Gate";
propertyNames[1] = "Circuit Layer"; propertyNames[1] = "Circuit Layer";
propertyNames[2] = "Gate Vertex Id"; propertyNames[2] = "Gate Vertex Id";
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
* its Vertex template parameter as a CircuitNode. It adds the * its Vertex template parameter as a CircuitNode. It adds the
* ability to read QuantumCircuits from a graphviz dot file. * ability to read QuantumCircuits from a graphviz dot file.
*/ */
class QuantumCircuit : virtual public qci::common::Graph<CircuitNode> { class QuantumCircuit : virtual public Graph<CircuitNode> {
public: public:
virtual void read(std::istream& stream) { virtual void read(std::istream& stream) {
......
...@@ -59,7 +59,7 @@ int main(int argc, char** argv) { ...@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
std::ofstream outputStream(outputFileName); std::ofstream outputStream(outputFileName);
std::stringstream ss; std::stringstream ss;
if (!inputStream) { if (!inputStream) {
QCIError("Invalid input qasm file"); XACCError("Invalid input qasm file");
} }
ss << inputStream.rdbuf(); ss << inputStream.rdbuf();
......
add_subdirectory(common) #add_subdirectory(fire)
Subproject commit f406c0dd32474e0267a381085957e962ca5baa6b
Subproject commit e1e149dcf6e37f609fe9f806bfdcbc8e68439772
...@@ -41,7 +41,7 @@ file (GLOB SRC program/*.cpp compiler/*.cpp accelerator/*.cpp) ...@@ -41,7 +41,7 @@ file (GLOB SRC program/*.cpp compiler/*.cpp accelerator/*.cpp)
file(GLOB test_files tests/*Tester.cpp) file(GLOB test_files tests/*Tester.cpp)
# Add the tests