Commit 0508946b authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

update grammar to allow compute action in gate def, started on test

parent f6ec5a87
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+859 −843

File changed.

Preview size limit exceeded, changes collapsed.

+2 −0
Original line number Diff line number Diff line
@@ -928,6 +928,8 @@ public:
    virtual size_t getRuleIndex() const override;
    antlr4::tree::TerminalNode *LBRACE();
    antlr4::tree::TerminalNode *RBRACE();
    std::vector<Compute_action_stmtContext *> compute_action_stmt();
    Compute_action_stmtContext* compute_action_stmt(size_t i);
    std::vector<QuantumStatementContext *> quantumStatement();
    QuantumStatementContext* quantumStatement(size_t i);
    std::vector<QuantumLoopContext *> quantumLoop();
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ quantumGateSignature
    ;

quantumBlock
    : LBRACE ( quantumStatement | quantumLoop )* RBRACE
    : LBRACE ( compute_action_stmt | quantumStatement | quantumLoop )* RBRACE
    ;

// loops containing only quantum statements allowed in gates
+30 −0
Original line number Diff line number Diff line
@@ -37,6 +37,36 @@ compute {
  EXPECT_EQ(countSubstring(llvm, "__quantum__qis"), 19);
}

TEST(qasm3ComputeActionTester, checkCtrlOpt) {
  const std::string src = R"#(OPENQASM 3;

qubit qq, rr, ss, vv, ww;

gate test22 q, r, s, v {
    compute {
        rx(1.57) q;
        h r;
        h s;
        h v;
        cnot q, r;
        cnot r, s;
        cnot s, v;
    } action {
        rz(2.2) v;
    }
}

ctrl @ test22 ww, qq, rr, ss, vv;

)#";
  std::cout << qcor::mlir_compile(src, "test", qcor::OutputType::MLIR, true)
            << "\n";
  auto llvm = qcor::mlir_compile(src, "test", qcor::OutputType::LLVMIR, true);
  std::cout << "LLVM:\n" << llvm << "\n";
  // 2 rxs, 6 hs, 6 cnots, 1 rz + decls == 19
  //   EXPECT_EQ(countSubstring(llvm, "__quantum__qis"), 19);
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  auto ret = RUN_ALL_TESTS();