Commit 088b2304 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

fixing bug where bit expressions for cnot was not being checked

parent a4fdf4fa
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -64,14 +64,8 @@ protected:

  void addOneQubitGate(const std::string name, xacc::Instruction &inst) {
    auto expr = inst.getBitExpression(0);
    if (expr.empty()) {
    ss << "quantum::" + name + "(" << inst.getBufferNames()[0] << "["
         << inst.bits()[0] << "]";

    } else {
      ss << "quantum::" + name + "(" << inst.getBufferNames()[0] << "["
         << inst.getBitExpression(0) << "]";
    }
         << (expr.empty() ? std::to_string(inst.bits()[0]) : expr) << "]";
    if (inst.isParameterized() && inst.name() != "Measure") {
      ss << ", " << inst.getParameter(0).toString();
      for (int i = 1; i < inst.nParameters(); i++) {
@@ -86,8 +80,13 @@ public:

  void visit(Hadamard &h) override { addOneQubitGate("h", h); }
  void visit(CNOT &cnot) override {
    ss << "quantum::cnot(" << cnot.getBufferNames()[0] << "[" << cnot.bits()[0]
       << "], " << cnot.getBufferNames()[1] << "[" << cnot.bits()[1] << "]);\n";
    auto expr_src = cnot.getBitExpression(0);
    auto expr_tgt = cnot.getBitExpression(1);
    ss << "quantum::cnot(" << cnot.getBufferNames()[0] << "["
       << (expr_src.empty() ? std::to_string(cnot.bits()[0]) : expr_src)
       << "], " << cnot.getBufferNames()[1] << "["
       << (expr_tgt.empty() ? std::to_string(cnot.bits()[1]) : expr_tgt)
       << "]);\n";
  }

  void visit(Rz &rz) override { addOneQubitGate("rz", rz); }
@@ -111,7 +110,6 @@ public:
  void visit(U &u) override { addOneQubitGate("u", u); }
  void visit(Circuit &circ) override {
    if (circ.name() == "exp_i_theta") {
      std::cout << "VISITING THE EXP I THETA\n";
      ss << "quantum::exp(" << circ.getBufferNames()[0] << ", "
         << circ.getArguments()[0]->name << ", " << circ.getArguments()[1]->name
         << ");\n";
@@ -438,8 +436,7 @@ void run_token_collector_llvm_rt(clang::Preprocessor &PP,
        auto creg_name = current_token_str;
        auto size = creg_name_to_size[creg_name];
        for (int k = 0; k < size; k++) {
          qrt_code << "quantum::mz(" << qreg_name << "[" << k
                   << "]);\n";
          qrt_code << "quantum::mz(" << qreg_name << "[" << k << "]);\n";
        }
        continue;
      }