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

Updating DWKernel tests, adding xacc::translate api call



Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 1cdad83f
......@@ -389,7 +389,8 @@ PYBIND11_MODULE(_pyxacc, m) {
xacc::getService<IRGenerator>,
py::return_value_policy::reference,
"Return the IRGenerator of given name.");
m.def("translate", &xacc::translate, "Translate the provided IR Function to the given language.");
m.def("translate", &xacc::translate,
"Translate the provided IR Function to the given language.");
m.def("setOption", [](const std::string s, InstructionParameter p) {
xacc::setOption(s, boost::lexical_cast<std::string>(p));
});
......
......@@ -88,7 +88,7 @@ public:
const std::string getTag() override { return ""; }
void mapBits(std::vector<int> bitMap) override {
xacc::error("DWKernel.mapBits not implemented");
xacc::error("DWKernel.mapBits not implemented");
}
/**
......@@ -101,7 +101,9 @@ public:
instructions.push_back(instruction);
}
const int depth() override { xacc::error("DWKernel graph is undirected, cannot compute depth."); }
const int depth() override {
xacc::error("DWKernel graph is undirected, cannot compute depth.");
}
const std::string persistGraph() override {
std::stringstream s;
......@@ -110,31 +112,33 @@ public:
}
Graph<DWVertex> toGraph() override {
int maxBit = 0;
for (int i = 0; i < nInstructions(); ++i) {
auto inst = getInstruction(i);
auto bits = inst->bits();
if (bits[0] > maxBit) {
maxBit = bits[0];
}
if (bits[1] > maxBit) {
maxBit = bits[1];
}
int maxBit = 0;
for (int i = 0; i < nInstructions(); ++i) {
auto inst = getInstruction(i);
auto bits = inst->bits();
if (bits[0] > maxBit) {
maxBit = bits[0];
}
if (bits[1] > maxBit) {
maxBit = bits[1];
}
}
DWGraph graph(maxBit+1);
for (int i = 0; i < nInstructions(); ++i) {
auto inst = getInstruction(i);
auto bits = inst->bits();
if (bits[0] == bits[1]) {
std::get<0>(graph.getVertex(bits[0]).properties) = boost::get<double>(inst->getParameter(0));
} else {
graph.addEdge(bits[0], bits[1], boost::get<double>(inst->getParameter(0)));
}
DWGraph graph(maxBit + 1);
for (int i = 0; i < nInstructions(); ++i) {
auto inst = getInstruction(i);
auto bits = inst->bits();
if (bits[0] == bits[1]) {
std::get<0>(graph.getVertex(bits[0]).properties) =
boost::get<double>(inst->getParameter(0));
} else {
graph.addEdge(bits[0], bits[1],
boost::get<double>(inst->getParameter(0)));
}
}
return graph;
return graph;
}
void replaceInstruction(const int idx, InstPtr replacingInst) override {
......@@ -153,9 +157,8 @@ public:
*/
const std::string name() const override { return _name; }
const std::string description() const override { return ""; }
const std::vector<int> bits() override { return std::vector<int>{}; }
const std::vector<int> bits() override { return std::vector<int>{}; }
const std::string toString(const std::string &bufferVarName) override {
std::stringstream ss;
......
......@@ -32,7 +32,7 @@ TEST(DWKernelTester, checkDWKernelConstruction) {
EXPECT_TRUE(kernel.getInstruction(1) == qmi2);
EXPECT_TRUE(kernel.getInstruction(2) == qmi3);
const std::string expected = "0 1 2.2\n0 0 0\n22 22 3.3\n";
const std::string expected = "0 1 2.2;\n0 0 0;\n22 22 3.3;\n";
EXPECT_TRUE(kernel.toString("") == expected);
}
......@@ -40,7 +40,7 @@ TEST(DWKernelTester, checkDWKernelConstruction) {
TEST(DWKernelTester, checkGraph) {
auto qmi = std::make_shared<DWQMI>(0, 1, 2.2);
auto qmi2 = std::make_shared<DWQMI>(0,1.2);
auto qmi2 = std::make_shared<DWQMI>(0, 1.2);
auto qmi3 = std::make_shared<DWQMI>(1, 3.3);
DWKernel kernel("foo");
......@@ -51,7 +51,6 @@ TEST(DWKernelTester, checkGraph) {
auto graph = kernel.toGraph();
graph.write(std::cout);
}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
......
......@@ -37,7 +37,8 @@ namespace quantum {
// for (auto i = boost::sregex_iterator(flatQasmStr.begin(),
// flatQasmStr.end(), qubitDeclarations); i !=
// boost::sregex_iterator(); ++i) { std::string qubitLine =
// (*i).str(); qubitLine.erase(std::remove(qubitLine.begin(), qubitLine.end(),
// (*i).str(); qubitLine.erase(std::remove(qubitLine.begin(),
// qubitLine.end(),
// '\n'), qubitLine.end()); boost::sregex_token_iterator
// first{qubitLine.begin(), qubitLine.end(), spaceDelim, -1}, last;
// std::vector<std::string> splitQubitLine = {first, last};
......@@ -107,13 +108,13 @@ namespace quantum {
// int counter = 0;
// std::vector<std::string> splitComma, props;
// boost::split(splitComma, gateCommand[1],
// boost::is_any_of(",")); for (auto segment : splitComma)
// { if (boost::contains(segment, qubitVarName)) {
// boost::is_any_of(",")); for (auto segment :
// splitComma) { if (boost::contains(segment, qubitVarName)) {
// actingQubits.push_back(qubitVarNameToId[segment]);
// } else {
// // This is not a qubit, it must be
// a parameter
// for gate props.push_back("PARAM_"
// // This is not a qubit, it must
// be a parameter for gate
// props.push_back("PARAM_"
// +
// std::to_string(counter));
// std::get<5>(node.properties) = props; counter++;
......@@ -323,11 +324,10 @@ void GateIR::load(std::istream &inStream) {
// if (eqsplit[0] == "Gate Acting Qubits") { auto qubitsStr = eqsplit[1];
// boost::replace_all(qubitsStr, "[", "");
// boost::replace_all(qubitsStr, "[",
// ""); std::vector<std::string> elementsStr;
// std::vector<int> qubits; boost::split(elementsStr, qubitsStr,
// boost::is_any_of(" ")); for (auto element
// : elementsStr) {
// qubits.push_back(std::stoi(element));
// ""); std::vector<std::string>
// elementsStr; std::vector<int> qubits;
// boost::split(elementsStr, qubitsStr, boost::is_any_of(" "));
// for (auto element : elementsStr) { qubits.push_back(std::stoi(element));
// }
// std::get<3>(v.properties) = qubits;
// } else if (eqsplit[0] == "Enabled") {
......
......@@ -96,7 +96,7 @@ TEST(QubitMapIRPreprocessorTester, checkSimple) {
// (-2.143303525+0j)*X0*X1 + (-3.91311896+0j)*X1*X2 +
// (-2.143303525+0j)*Y0*Y1 + (-3.91311896+0j)*Y1*Y2 +
//(0.218290555+0j)*Z0 + (-6.125+0j)*Z1 + (-9.625+0j)*Z2 needs x0, x1,
//x2, y0, y1, y2
// x2, y0, y1, y2
xacc::Initialize();
std::unordered_map<std::string, Term> test{{"X0X1", {{0, "X"}, {1, "X"}}},
......
......@@ -97,7 +97,7 @@ TEST(ReadoutErrorIRPreprocessorTester, checkSimple) {
// (-2.143303525+0j)*X0*X1 + (-3.91311896+0j)*X1*X2 +
// (-2.143303525+0j)*Y0*Y1 + (-3.91311896+0j)*Y1*Y2 +
//(0.218290555+0j)*Z0 + (-6.125+0j)*Z1 + (-9.625+0j)*Z2 needs x0, x1,
//x2, y0, y1, y2
// x2, y0, y1, y2
std::unordered_map<std::string, Term> test{{"X0X1", {{0, "X"}, {1, "X"}}},
{"X1X2", {{1, "X"}, {2, "X"}}},
......
......@@ -290,9 +290,10 @@ getIRTransformations(const std::string &name) {
return t;
}
const std::string translate(std::shared_ptr<Function> function, const std::string toLanguage);{
const std::string translate(std::shared_ptr<Function> function,
const std::string toLanguage) {
auto toLanguageCompiler = getCompiler(toLanguage);
return toLanguageCompiler->translate(nullptr, function);
return toLanguageCompiler->translate("", function);
}
const std::string translateWithVisitor(const std::string &originalSource,
......
......@@ -282,7 +282,8 @@ std::shared_ptr<Function> optimizeFunction(const std::string optimizer,
std::shared_ptr<IRTransformation> getIRTransformation(const std::string &name);
const std::string translate(std::shared_ptr<Function> function, const std::string toLanguage);
const std::string translate(std::shared_ptr<Function> function,
const std::string toLanguage);
const std::string translateWithVisitor(const std::string &originalSource,
const std::string &originalLanguage,
......
......@@ -60,10 +60,11 @@ public:
return generate(nullptr, temp);
}
virtual std::vector<InstructionParameter> analyzeResults(std::shared_ptr<AcceleratorBuffer> buffer) {
return std::vector<InstructionParameter>{};
virtual std::vector<InstructionParameter>
analyzeResults(std::shared_ptr<AcceleratorBuffer> buffer) {
return std::vector<InstructionParameter>{};
}
/**
* The destructor
*/
......
......@@ -346,14 +346,12 @@ int main(int argc, char **argv) {
// [label=\"Gate=x,Circuit Layer=1,Gate Vertex Id=1,Gate Acting
// Qubits=[0]\"];\n" "2 [label=\"Gate=h,Circuit Layer=1,Gate Vertex Id=2,Gate
// Acting
// Qubits=[1]\"];\n" "3 [label=\"Gate=cnot,Circuit Layer=2,Gate
// Vertex Id=3,Gate
// Acting Qubits=[1 2]\"];\n" "4 [label=\"Gate=cnot,Circuit
// Layer=3,Gate Vertex
// Id=4,Gate Acting Qubits=[0 1]\"];\n" "5
// [label=\"Gate=h,Circuit Layer=4,Gate Vertex Id=5,Gate Acting
// Qubits=[0]\"];\n" "6 [label=\"Gate=measure,Circuit Layer=5,Gate Vertex
// Id=6,Gate Acting Qubits=[0]\"];\n" "7
// Qubits=[1]\"];\n" "3 [label=\"Gate=cnot,Circuit
// Layer=2,Gate Vertex Id=3,Gate Acting Qubits=[1 2]\"];\n" "4
// [label=\"Gate=cnot,Circuit Layer=3,Gate Vertex Id=4,Gate Acting Qubits=[0
// 1]\"];\n" "5 [label=\"Gate=h,Circuit Layer=4,Gate Vertex
// Id=5,Gate Acting Qubits=[0]\"];\n" "6 [label=\"Gate=measure,Circuit
// Layer=5,Gate Vertex Id=6,Gate Acting Qubits=[0]\"];\n" "7
// [label=\"Gate=measure,Circuit
// Layer=5,Gate Vertex Id=7,Gate Acting
// Qubits=[1]\"];\n" "8 [label=\"Gate=h,Circuit Layer=6,Gate
......
Supports Markdown
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