13 #ifndef QUANTUM_GATE_ACCELERATORS_IONQPROGRAMVISITOR_HPP_ 14 #define QUANTUM_GATE_ACCELERATORS_IONQPROGRAMVISITOR_HPP_ 17 #include "AllGateVisitor.hpp" 18 #include "ionq_program.hpp" 27 constexpr
static double pi = xacc::constants::pi;
29 std::vector<xacc::ionq::CircuitInstruction> instructions;
39 const std::string
name()
const override {
return "ionq-visitor"; }
42 return "Map XACC IR to IonQ Program.";
47 const std::vector<xacc::ionq::CircuitInstruction> getCircuitInstructions() {
54 inst.set_target(h.bits()[0]);
56 instructions.push_back(inst);
66 void visit(
CRZ &crz)
override {
67 auto lambda = crz.getParameter(0).as<
double>();
68 U u1_1(crz.bits()[1], 0.0, 0.0, lambda / 2.0);
70 U u1_2(crz.bits()[1], 0.0, 0.0, lambda / -2.0);
78 void visit(
CH &ch)
override {
80 Sdg sdg(ch.bits()[1]);
103 void visit(
S &s)
override {
104 U u(s.bits()[0], 0.0, 0.0, 3.1415926 / 2.0);
107 void visit(
Sdg &sdg)
override {
108 U u(sdg.bits()[0], 0.0, 0.0, 3.1415926 / -2.0);
111 void visit(
T &t)
override {
112 U u(t.bits()[0], 0.0, 0.0, 3.1415926 / 4.0);
115 void visit(
Tdg &tdg)
override {
116 U u(tdg.bits()[0], 0.0, 0.0, 3.1415926 / -4.0);
120 void visit(
CNOT &cn)
override {
122 inst.set_gate(
"cnot");
123 inst.set_target(cn.bits()[1]);
124 inst.set_control(cn.bits()[0]);
126 instructions.push_back(inst);
129 void visit(
X &x)
override {
132 inst.set_target(x.bits()[0]);
134 instructions.push_back(inst);
137 void visit(
Y &y)
override {
140 inst.set_target(y.bits()[0]);
142 instructions.push_back(inst);
145 void visit(
Z &z)
override {
148 inst.set_target(z.bits()[0]);
150 instructions.push_back(inst);
153 void visit(
U &u)
override {
154 auto t = u.getParameter(0).toString();
155 auto p = u.getParameter(1).toString();
156 auto l = u.getParameter(2).toString();
158 Rz rz(u.bits()[0], t);
159 Ry ry(u.bits()[0], p);
160 Rz rz2(u.bits()[0], l);
166 void visit(
Rx &rx)
override {
169 inst.set_target(rx.bits()[0]);
170 inst.set_rotation(rx.getParameter(0).as<
double>());
171 instructions.push_back(inst);
174 void visit(
Ry &ry)
override {
177 inst.set_target(ry.bits()[0]);
178 inst.set_rotation(ry.getParameter(0).as<
double>());
179 instructions.push_back(inst);
182 void visit(
Rz &rz)
override {
185 inst.set_target(rz.bits()[0]);
186 inst.set_rotation(rz.getParameter(0).as<
double>());
187 instructions.push_back(inst);
190 void visit(
CPhase &cp)
override {
191 auto lambda = cp.getParameter(0).as<
double>();
192 U u1_1(cp.bits()[0], 0.0, 0.0, lambda / 2.0);
194 U u1_2(cp.bits()[1], 0.0, 0.0, -1.0 * lambda / 2.0);
196 U u1_3(cp.bits()[1], 0.0, 0.0, lambda / 2.0);
205 void visit(
Measure &m)
override {}
Definition: CommonGates.hpp:306
Definition: CommonGates.hpp:199
Definition: CommonGates.hpp:328
Definition: Accelerator.hpp:25
Definition: CommonGates.hpp:425
virtual ~IonQProgramVisitor()
Definition: ionq_program_visitor.hpp:209
Definition: CommonGates.hpp:412
Definition: CommonGates.hpp:438
Definition: CommonGates.hpp:124
Definition: CommonGates.hpp:112
Definition: CommonGates.hpp:465
Definition: ionq_program.hpp:10
const std::string description() const override
Definition: ionq_program_visitor.hpp:41
Definition: CommonGates.hpp:295
Definition: AllGateVisitor.hpp:24
Definition: CommonGates.hpp:399
Definition: CommonGates.hpp:216
Definition: ionq_program.hpp:26
Definition: CommonGates.hpp:235
Definition: CommonGates.hpp:317
Definition: CommonGates.hpp:381
const std::string name() const override
Definition: ionq_program_visitor.hpp:39
Definition: CommonGates.hpp:479
Definition: CommonGates.hpp:270
Definition: CommonGates.hpp:100
Definition: ionq_program_visitor.hpp:25