13 #ifndef QUANTUM_GATE_COMPILER_STAQ_VISITORS_HPP_ 14 #define QUANTUM_GATE_COMPILER_STAQ_VISITORS_HPP_ 16 #include "ast/decl.hpp" 17 #include "parser/parser.hpp" 18 #include "ast/traversal.hpp" 21 #include "AllGateVisitor.hpp" 26 namespace internal_staq {
27 static const std::map<std::string, std::string> staq_to_xacc{
29 {
"cx",
"CX"}, {
"id",
"I"}, {
"x",
"X"}, {
"y",
"Y"},
30 {
"z",
"Z"}, {
"h",
"H"}, {
"s",
"S"}, {
"sdg",
"Sdg"},
31 {
"t",
"T"}, {
"tdg",
"Tdg"}, {
"rx",
"Rx"}, {
"ry",
"Ry"},
32 {
"rz",
"Rz"}, {
"cz",
"CZ"}, {
"cy",
"CY"}, {
"swap",
"Swap"},
33 {
"ch",
"CH"}, {
"crz",
"CRZ"}, {
"cu1",
"CPhase"}};
37 std::vector<std::string> qregs;
38 void visit(staq::ast::RegisterDecl &d)
override {
40 qregs.push_back(d.id());
47 std::map<std::string, int> ancillas;
48 void visit(staq::ast::AncillaDecl &d)
override {
49 ancillas.insert({d.id(), d.size()});
56 void visit(VarAccess &)
override {}
58 void visit(BExpr &)
override {}
59 void visit(UExpr &)
override {}
60 void visit(PiExpr &)
override {}
61 void visit(IntExpr &)
override {}
62 void visit(RealExpr &r)
override {}
63 void visit(VarExpr &v)
override {}
64 void visit(ResetStmt &)
override {}
65 void visit(
IfStmt &)
override {}
66 void visit(BarrierGate &)
override {}
67 void visit(GateDecl &)
override {}
68 void visit(OracleDecl &)
override {}
69 void visit(RegisterDecl &)
override {}
70 void visit(AncillaDecl &)
override {}
71 void visit(Program &prog)
override {
73 prog.foreach_stmt([
this](
auto &stmt) { stmt.accept(*
this); });
75 void visit(MeasureStmt &m)
override {
76 ss <<
"Measure(" << m.q_arg().var() <<
"[" << m.q_arg().offset().value()
79 void visit(UGate &u)
override {
80 ss <<
"U(" << u.arg().var() <<
"[" << u.arg().offset().value() <<
"], " 81 << u.theta().constant_eval().value() <<
", " 82 << u.phi().constant_eval().value() <<
", " 83 << u.lambda().constant_eval().value() <<
");\n";
85 void visit(CNOTGate &cx)
override {
86 ss <<
"CX(" << cx.ctrl().var() <<
"[" << cx.ctrl().offset().value() <<
"]," 87 << cx.tgt().var() <<
"[" << cx.tgt().offset().value() <<
"]);\n";
90 void visit(DeclaredGate &g)
override {
92 auto xacc_name = staq_to_xacc.at(g.name());
93 ss << xacc_name <<
"(" << g.qarg(0).var() <<
"[" 94 << g.qarg(0).offset().value() <<
"]";
95 for (
int i = 1; i < g.num_qargs(); i++) {
96 ss <<
", " << g.qarg(i).var() <<
"[" << g.qarg(i).offset().value() <<
"]";
99 if (g.num_cargs() > 0) {
100 ss <<
", " << g.carg(0).constant_eval().value();
101 for (
int i = 1; i < g.num_cargs(); i++) {
102 ss <<
", " << g.carg(i).constant_eval().value() <<
"\n";
115 std::stringstream ss;
116 std::map<std::string, std::string> cregNames;
120 void visit(
CNOT &cnot)
override;
121 void visit(
Rz &rz)
override;
122 void visit(
Ry &ry)
override;
123 void visit(
Rx &rx)
override;
124 void visit(
X &x)
override;
125 void visit(
Y &y)
override;
126 void visit(
Z &z)
override;
127 void visit(
CY &cy)
override;
128 void visit(
CZ &cz)
override;
129 void visit(
Swap &s)
override;
130 void visit(
CRZ &crz)
override;
131 void visit(
CH &ch)
override;
132 void visit(
S &s)
override;
133 void visit(
Sdg &sdg)
override;
134 void visit(
T &t)
override;
135 void visit(
Tdg &tdg)
override;
136 void visit(
CPhase &cphase)
override;
137 void visit(
Measure &measure)
override;
139 void visit(
U &u)
override;
140 void visit(
IfStmt &ifStmt)
override;
Definition: CommonGates.hpp:306
Definition: staq_visitors.hpp:45
Definition: staq_visitors.hpp:35
Definition: staq_visitors.hpp:53
Definition: CommonGates.hpp:199
Definition: CommonGates.hpp:328
Definition: CommonGates.hpp:451
Definition: Accelerator.hpp:25
Definition: CommonGates.hpp:425
Definition: CommonGates.hpp:412
Definition: CommonGates.hpp:438
Definition: CommonGates.hpp:124
Definition: CommonGates.hpp:112
Definition: CommonGates.hpp:465
Definition: CommonGates.hpp:295
Definition: AllGateVisitor.hpp:24
Definition: CommonGates.hpp:368
Definition: CommonGates.hpp:399
Definition: staq_visitors.hpp:112
Definition: CommonGates.hpp:216
Definition: CommonGates.hpp:254
Definition: CommonGates.hpp:235
Definition: CommonGates.hpp:317
Definition: CommonGates.hpp:381
Definition: CommonGates.hpp:479
Definition: CommonGates.hpp:270
Definition: CommonGates.hpp:56
Definition: CommonGates.hpp:100
Definition: DefaultParameterSetter.cpp:17