Commit 2a7f735e authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding u1 rotation gate, defaults to rz in AllGateVisitor


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 14d5bd87
Pipeline #105218 passed with stage
in 9 minutes and 54 seconds
......@@ -52,6 +52,8 @@ public:
auto isw = std::make_shared<xacc::quantum::iSwap>();
auto fsim = std::make_shared<xacc::quantum::fSim>();
auto u = std::make_shared<xacc::quantum::U>();
auto u1 = std::make_shared<xacc::quantum::U1>();
auto anneal = std::make_shared<xacc::quantum::AnnealingInstruction>();
auto s = std::make_shared<xacc::quantum::S>();
......@@ -84,6 +86,8 @@ public:
context.RegisterService<xacc::Instruction>(isw);
context.RegisterService<xacc::Instruction>(fsim);
context.RegisterService<xacc::Instruction>(u);
context.RegisterService<xacc::Instruction>(u1);
context.RegisterService<xacc::Instruction>(ifstmt);
context.RegisterService<xacc::Instruction>(anneal);
......
......@@ -193,6 +193,23 @@ public:
DEFINE_VISITABLE()
};
class U1 : public Gate {
public:
U1()
: Gate("U1",
std::vector<InstructionParameter>{InstructionParameter(0.0)}) {}
U1(std::size_t qbit, InstructionParameter &&theta)
: Gate("U1", std::vector<std::size_t>{qbit},
std::vector<InstructionParameter>{theta}) {}
U1(std::vector<std::size_t> qbits)
: Gate("U1", qbits,
std::vector<InstructionParameter>{InstructionParameter(0.0)}) {}
const int nRequiredBits() const override { return 1; }
DEFINE_CLONE(U1)
DEFINE_VISITABLE()
};
class Rx : public Gate {
public:
Rx()
......
......@@ -16,6 +16,7 @@
#include "InstructionIterator.hpp"
#include "CommonGates.hpp"
#include <Instruction.hpp>
namespace xacc {
namespace quantum {
......@@ -44,6 +45,7 @@ class AllGateVisitor : public BaseInstructionVisitor,
public InstructionVisitor<T>,
public InstructionVisitor<Tdg>,
public InstructionVisitor<U>,
public InstructionVisitor<U1>,
public InstructionVisitor<IfStmt> {
public:
void visit(Hadamard &h) override {}
......@@ -51,6 +53,12 @@ public:
void visit(Rz &h) override {}
void visit(Ry &h) override {}
void visit(Rx &h) override {}
void visit(U1 &u1) override {
InstructionParameter p = u1.getParameter(0);
Rz rz(u1.bits());
rz.setParameter(0, p);
visit(rz);
}
void visit(X &h) override {}
void visit(Y &h) override {}
void visit(Z &h) override {}
......@@ -80,8 +88,8 @@ public:
visit(c3);
}
void visit(fSim& fsim) override {}
void visit(iSwap& isw) override {}
void visit(fSim &fsim) override {}
void visit(iSwap &isw) override {}
void visit(CRZ &crz) override {}
void visit(CH &ch) override {}
void visit(S &s) override {}
......
......@@ -22,24 +22,36 @@
#include "Circuit.hpp"
TEST(XASMCompilerTester, checkU1) {
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(R"(__qpu__ void u1_test(qbit q, double x) {
U1(q[0], x);
})");
auto kernel = IR->getComposites()[0];
std::cout << "HELLO: " << kernel->toString() << "\n";
std::cout << kernel->operator()({2.2})->toString() << "\n";
}
TEST(XASMCompilerTester, checkISwapAndFSim) {
auto compiler = xacc::getCompiler("xasm");
auto IR = compiler->compile(R"(__qpu__ void iswap_test(qbit q, double x, double y) {
auto IR =
compiler->compile(R"(__qpu__ void iswap_test(qbit q, double x, double y) {
H(q[0]);
iSwap(q[0], q[1]);
fSim(q[0], q[1], x, y);
CX(q[0], q[1]);
})");
auto kernel = IR->getComposites()[0];
auto kernel = IR->getComposites()[0];
std::cout << "HELLO: " << kernel->toString() << "\n";
std::cout << kernel->operator()({2.2,3.3})->toString() << "\n";
std::cout << kernel->operator()({2.2, 3.3})->toString() << "\n";
}
TEST(XASMCompilerTester, checkTranslate) {
......
......@@ -10,7 +10,7 @@ template <typename T> struct empty_delete {
qreg::qreg(const int n) { buffer = xacc::qalloc(n).get(); }
qreg::qreg(const qreg &other) : buffer(other.buffer) {}
qubit qreg::operator[](const std::size_t &i) {
qubit qreg::operator[](const std::size_t i) {
return std::make_pair(buffer->name(), i);
}
AcceleratorBuffer *qreg::results() { return buffer; }
......
......@@ -29,7 +29,7 @@ public:
qreg() = default;
qreg(const int n);
qreg (const qreg& other);
qubit operator[](const std::size_t &i);
qubit operator[](const std::size_t i);
AcceleratorBuffer *results();
std::map<std::string, int> counts();
double exp_val_z();
......
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