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,
transformations::inline_ast(
*prog, {false, transformations::default_overrides, "anc"});
// std::cout <<"PROG: " << *prog << "\n";
// Visit Program to find out how many qreg there are and
// use that to build up openqasm xacc function prototype
......
......@@ -15,6 +15,28 @@
#include "xacc.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) {
auto compiler = xacc::getCompiler("staq");
auto IR = compiler->compile(R"(
......
......@@ -30,7 +30,7 @@ static const std::map<std::string, std::string> staq_to_xacc{
{"z", "Z"}, {"h", "H"}, {"s", "S"}, {"sdg", "Sdg"},
{"t", "T"}, {"tdg", "Tdg"}, {"rx", "Rx"}, {"ry", "Ry"},
{"rz", "Rz"}, {"cz", "CZ"}, {"cy", "CY"}, {"swap", "Swap"},
{"ch", "CH"}, {"crz", "CRZ"}};
{"ch", "CH"}, {"crz", "CRZ"}, {"cu1", "CPhase"}};
class CountQregs : public staq::ast::Traverse {
public:
......@@ -77,8 +77,10 @@ public:
<< "]);\n";
}
void visit(UGate &u) override {
ss << "U(" << u.arg().var() << "[" << u.arg().offset().value() << "], " << 0
<< ", " << 0 << ", " << 0 << ");\n";
ss << "U(" << u.arg().var() << "[" << u.arg().offset().value() << "], "
<< u.theta().constant_eval().value() << ", "
<< u.phi().constant_eval().value() << ", "
<< u.lambda().constant_eval().value() << ");\n";
}
void visit(CNOTGate &cx) override {
ss << "CX(" << cx.ctrl().var() << "[" << cx.ctrl().offset().value() << "],"
......@@ -111,7 +113,7 @@ class XACCToStaqOpenQasm : public AllGateVisitor {
public:
std::stringstream ss;
std::map<std::string,std::string> cregNames;
std::map<std::string, std::string> cregNames;
XACCToStaqOpenQasm(std::map<std::string, int> bufNamesToSize);
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