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

fixing bug in staq where U angles were hard coded to 0


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent b392cdf7
Pipeline #106664 passed with stage
in 9 minutes and 41 seconds
...@@ -217,6 +217,7 @@ std::shared_ptr<IR> StaqCompiler::compile(const std::string &src, ...@@ -217,6 +217,7 @@ std::shared_ptr<IR> StaqCompiler::compile(const std::string &src,
transformations::inline_ast( transformations::inline_ast(
*prog, {false, transformations::default_overrides, "anc"}); *prog, {false, transformations::default_overrides, "anc"});
// std::cout <<"PROG: " << *prog << "\n";
// Visit Program to find out how many qreg there are and // Visit Program to find out how many qreg there are and
// use that to build up openqasm xacc function prototype // use that to build up openqasm xacc function prototype
...@@ -262,7 +263,7 @@ std::shared_ptr<IR> StaqCompiler::compile(const std::string &src, ...@@ -262,7 +263,7 @@ std::shared_ptr<IR> StaqCompiler::compile(const std::string &src,
xx << ") {\n" << translate.ss.str() << "}"; xx << ") {\n" << translate.ss.str() << "}";
kernel = xx.str(); kernel = xx.str();
} }
// std::cout << "\n\nFinal:\n" << kernel << "\n"; // std::cout << "\n\nFinal:\n" << kernel << "\n";
return xasm->compile(kernel, acc); return xasm->compile(kernel, acc);
} }
......
...@@ -15,6 +15,28 @@ ...@@ -15,6 +15,28 @@
#include "xacc.hpp" #include "xacc.hpp"
#include "xacc_service.hpp" #include "xacc_service.hpp"
TEST(StaqCompilerTester, checkCphase) {
auto src = R"#(
qreg q[4];
x q[3];
h q[0];
h q[1];
h q[2];
cu1(0.785398) q[0], q[3];
creg c[3];
measure q[0] -> c[0];
measure q[1] -> c[1];
measure q[2] -> c[2];)#";
auto compiler = xacc::getCompiler("staq");
auto IR = compiler->compile(src);
auto hello = IR->getComposites()[0];
std::cout << "HELLO:\n" << hello->toString() << "\n";
}
TEST(StaqCompilerTester, checkSimple) { TEST(StaqCompilerTester, checkSimple) {
auto compiler = xacc::getCompiler("staq"); auto compiler = xacc::getCompiler("staq");
auto IR = compiler->compile(R"( auto IR = compiler->compile(R"(
......
...@@ -26,11 +26,11 @@ namespace xacc { ...@@ -26,11 +26,11 @@ namespace xacc {
namespace internal_staq { namespace internal_staq {
static const std::map<std::string, std::string> staq_to_xacc{ static const std::map<std::string, std::string> staq_to_xacc{
// "u3", "u2", "u1", "ccx", cu1, cu3 // "u3", "u2", "u1", "ccx", cu1, cu3
{"cx", "CX"}, {"id", "I"}, {"x", "X"}, {"y", "Y"}, {"cx", "CX"}, {"id", "I"}, {"x", "X"}, {"y", "Y"},
{"z", "Z"}, {"h", "H"}, {"s", "S"}, {"sdg", "Sdg"}, {"z", "Z"}, {"h", "H"}, {"s", "S"}, {"sdg", "Sdg"},
{"t", "T"}, {"tdg", "Tdg"}, {"rx", "Rx"}, {"ry", "Ry"}, {"t", "T"}, {"tdg", "Tdg"}, {"rx", "Rx"}, {"ry", "Ry"},
{"rz", "Rz"}, {"cz", "CZ"}, {"cy", "CY"}, {"swap", "Swap"}, {"rz", "Rz"}, {"cz", "CZ"}, {"cy", "CY"}, {"swap", "Swap"},
{"ch", "CH"}, {"crz", "CRZ"}}; {"ch", "CH"}, {"crz", "CRZ"}, {"cu1", "CPhase"}};
class CountQregs : public staq::ast::Traverse { class CountQregs : public staq::ast::Traverse {
public: public:
...@@ -77,8 +77,10 @@ public: ...@@ -77,8 +77,10 @@ public:
<< "]);\n"; << "]);\n";
} }
void visit(UGate &u) override { void visit(UGate &u) override {
ss << "U(" << u.arg().var() << "[" << u.arg().offset().value() << "], " << 0 ss << "U(" << u.arg().var() << "[" << u.arg().offset().value() << "], "
<< ", " << 0 << ", " << 0 << ");\n"; << u.theta().constant_eval().value() << ", "
<< u.phi().constant_eval().value() << ", "
<< u.lambda().constant_eval().value() << ");\n";
} }
void visit(CNOTGate &cx) override { void visit(CNOTGate &cx) override {
ss << "CX(" << cx.ctrl().var() << "[" << cx.ctrl().offset().value() << "]," ss << "CX(" << cx.ctrl().var() << "[" << cx.ctrl().offset().value() << "],"
...@@ -111,7 +113,7 @@ class XACCToStaqOpenQasm : public AllGateVisitor { ...@@ -111,7 +113,7 @@ class XACCToStaqOpenQasm : public AllGateVisitor {
public: public:
std::stringstream ss; std::stringstream ss;
std::map<std::string,std::string> cregNames; std::map<std::string, std::string> cregNames;
XACCToStaqOpenQasm(std::map<std::string, int> bufNamesToSize); XACCToStaqOpenQasm(std::map<std::string, int> bufNamesToSize);
void visit(Hadamard &h) override; void visit(Hadamard &h) override;
......
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