Loading mlir/parsers/qasm3/tests/CMakeLists.txt +19 −0 Original line number Diff line number Diff line Loading @@ -17,3 +17,22 @@ add_test(NAME qcor_qasm3_test_utils_tester COMMAND qasm3CompilerTester_TestUtils target_include_directories(qasm3CompilerTester_TestUtils PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_TestUtils qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_Declaration test_declaration.cpp) add_test(NAME qcor_qasm3_test_declaration COMMAND qasm3CompilerTester_Declaration) target_include_directories(qasm3CompilerTester_Declaration PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_Declaration qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_Casting test_casting.cpp) add_test(NAME qcor_qasm3_test_casting COMMAND qasm3CompilerTester_Casting) target_include_directories(qasm3CompilerTester_Casting PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_Casting qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_LoopStmts test_loop_stmts.cpp) add_test(NAME qcor_qasm3_test_loops COMMAND qasm3CompilerTester_LoopStmts) target_include_directories(qasm3CompilerTester_LoopStmts PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_LoopStmts qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_QuantumInstructions test_quantum_instructions.cpp) add_test(NAME qcor_qasm3_test_qinsts COMMAND qasm3CompilerTester_QuantumInstructions) target_include_directories(qasm3CompilerTester_QuantumInstructions PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_QuantumInstructions qcor-mlir-api gtest gtest_main) mlir/parsers/qasm3/tests/test_assignment.cpp +7 −21 Original line number Diff line number Diff line Loading @@ -58,35 +58,21 @@ bool bb = 1; bool bbb = 0; QCOR_EXPECT_TRUE(ii == 10); // FIXME Need to fix float[] comparison // QCOR_EXPECT_TRUE(f == 0.0); // QCOR_EXPECT_TRUE(ff == 3.14); QCOR_EXPECT_TRUE(result == 0); QCOR_EXPECT_TRUE(results[0] == 0); QCOR_EXPECT_TRUE(results[1] == 0); QCOR_EXPECT_TRUE(b == 0); QCOR_EXPECT_TRUE(z == 0); QCOR_EXPECT_TRUE(bb == 1); QCOR_EXPECT_TRUE(bbb == 0); QCOR_EXPECT_TRUE(f == 0.0); QCOR_EXPECT_TRUE(ff == 3.14); // print(dd); // print(ffff); // print(layers); // print(layers2); // print(t); // print(tt); // print(mypi); // print(added); // print(added_diff_types); // print(tmp); // print(b, z); // print(bb); // print(bbb); // print(f); // print(ff); )#"; auto mlir = qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::MLIR, true); std::cout << "MLIR:\n" << mlir << "\n"; qcor::execute("qasm3", src, "test"); EXPECT_FALSE(qcor::execute("qasm3", src, "test")); } int main(int argc, char **argv) { Loading mlir/parsers/qasm3/tests/test_casting.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line #include "gtest/gtest.h" #include "qcor_mlir_api.hpp" TEST(qasm3VisitorTester, checkUintIndexing) { const std::string uint_index = R"#(OPENQASM 3; include "qelib1.inc"; uint[4] b_in = 15; bool b1 = bool(b_in[0]); bool b2 = bool(b_in[1]); bool b3 = bool(b_in[2]); bool b4 = bool(b_in[3]); print(b1,b2,b3,b4); QCOR_EXPECT_TRUE(b1 == 1); QCOR_EXPECT_TRUE(b2 == 1); QCOR_EXPECT_TRUE(b3 == 1); QCOR_EXPECT_TRUE(b4 == 1); )#"; auto mlir = qcor::mlir_compile("qasm3", uint_index, "uint_index", qcor::OutputType::MLIR, false); std::cout << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", uint_index, "uint_index")); } TEST(qasm3VisitorTester, checkCastBitToInt) { const std::string cast_int = R"#(OPENQASM 3; include "qelib1.inc"; bit c[4] = "1111"; int[4] t = int[4](c); // should print 15 print(t); QCOR_EXPECT_TRUE(t == 15); )#"; auto mlir = qcor::mlir_compile("qasm3", cast_int, "cast_int", qcor::OutputType::MLIR, false); std::cout << "cast_int MLIR:\n" << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", cast_int, "cast_int")); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); return ret; } No newline at end of file mlir/parsers/qasm3/tests/test_declaration.cpp 0 → 100644 +70 −0 Original line number Diff line number Diff line #include "gtest/gtest.h" #include "qcor_mlir_api.hpp" TEST(qasm3VisitorTester, checkDeclaration) { const std::string src = R"#(OPENQASM 3; include "qelib1.inc"; int[10] x, y; QCOR_EXPECT_TRUE(x == 0); QCOR_EXPECT_TRUE(y == 0); int[5] xx=2, yy=1; QCOR_EXPECT_TRUE(xx == 2); QCOR_EXPECT_TRUE(yy == 1); qubit q1[6], q2; bit b1[4]="0100", b2 = "1"; QCOR_EXPECT_TRUE(b1[0] == 0); QCOR_EXPECT_TRUE(b1[1] == 1); QCOR_EXPECT_TRUE(b1[2] == 0); QCOR_EXPECT_TRUE(b1[3] == 0); bit k, kk[22]; QCOR_EXPECT_TRUE(k == 0); QCOR_EXPECT_TRUE(kk[13] == 0); bool bb = False; bool m=True, n=bool(xx); QCOR_EXPECT_TRUE(m == 1); QCOR_EXPECT_TRUE(bb == 0); QCOR_EXPECT_TRUE(n == 0); const c = 5.5e3, d=5; const e = 2.2; QCOR_EXPECT_TRUE(c == 5500.0); QCOR_EXPECT_TRUE(d == 5); QCOR_EXPECT_TRUE(e == 2.2); x q2; k = measure q2; QCOR_EXPECT_TRUE(k == 1); for i in [0:22] { QCOR_EXPECT_TRUE(kk[i] == 0); } )#"; auto mlir = qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::MLIR, true); std::cout << "MLIR:\n" << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", src, "test")); const std::string src2 = R"#(OPENQASM 3; include "qelib1.inc"; bit kk[22]; for i in [0:22] { print("should only see 0 bc next statement will fail: ", i); QCOR_EXPECT_TRUE(kk[i] == 1); } )#"; auto mlir2 = qcor::mlir_compile("qasm3", src2, "test", qcor::OutputType::MLIR, true); std::cout << "MLIR:\n" << mlir2 << "\n"; EXPECT_TRUE(qcor::execute("qasm3", src2, "test")); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); return ret; } No newline at end of file mlir/parsers/qasm3/tests/test_loop_stmts.cpp 0 → 100644 +72 −0 Original line number Diff line number Diff line #include "gtest/gtest.h" #include "qcor_mlir_api.hpp" TEST(qasm3VisitorTester, checkLoops) { const std::string for_stmt = R"#(OPENQASM 3; include "qelib1.inc"; int[32] loop_count = 0; for i in {11,22,33} { print(i); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 3); loop_count = 0; for i in [0:10] { print(i); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 10); loop_count = 0; for j in [0:2:4] { print("steps:", j); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 2); loop_count = 0; for j in [0:4] { print("j in 0:4", j); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 4); loop_count = 0; for i in [0:4] { for j in {1,2,3} { print(i,j); loop_count += 1; } } QCOR_EXPECT_TRUE(loop_count == 12); )#"; auto mlir = qcor::mlir_compile("qasm3", for_stmt, "for_stmt", qcor::OutputType::MLIR, false); std::cout << "for_stmt MLIR:\n" << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", for_stmt, "for_stmt")); const std::string while_stmt = R"#(OPENQASM 3; include "qelib1.inc"; int[32] i = 0; while (i < 10) { print(i); i += 1; } QCOR_EXPECT_TRUE(i == 10); )#"; auto mlir2 = qcor::mlir_compile("qasm3", while_stmt, "while_stmt", qcor::OutputType::MLIR, false); std::cout << mlir2 << "\n"; EXPECT_FALSE(qcor::execute("qasm3", while_stmt, "while_stmt")); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); return ret; } No newline at end of file Loading
mlir/parsers/qasm3/tests/CMakeLists.txt +19 −0 Original line number Diff line number Diff line Loading @@ -17,3 +17,22 @@ add_test(NAME qcor_qasm3_test_utils_tester COMMAND qasm3CompilerTester_TestUtils target_include_directories(qasm3CompilerTester_TestUtils PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_TestUtils qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_Declaration test_declaration.cpp) add_test(NAME qcor_qasm3_test_declaration COMMAND qasm3CompilerTester_Declaration) target_include_directories(qasm3CompilerTester_Declaration PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_Declaration qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_Casting test_casting.cpp) add_test(NAME qcor_qasm3_test_casting COMMAND qasm3CompilerTester_Casting) target_include_directories(qasm3CompilerTester_Casting PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_Casting qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_LoopStmts test_loop_stmts.cpp) add_test(NAME qcor_qasm3_test_loops COMMAND qasm3CompilerTester_LoopStmts) target_include_directories(qasm3CompilerTester_LoopStmts PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_LoopStmts qcor-mlir-api gtest gtest_main) add_executable(qasm3CompilerTester_QuantumInstructions test_quantum_instructions.cpp) add_test(NAME qcor_qasm3_test_qinsts COMMAND qasm3CompilerTester_QuantumInstructions) target_include_directories(qasm3CompilerTester_QuantumInstructions PRIVATE . ../../ ${XACC_ROOT}/include/gtest) target_link_libraries(qasm3CompilerTester_QuantumInstructions qcor-mlir-api gtest gtest_main)
mlir/parsers/qasm3/tests/test_assignment.cpp +7 −21 Original line number Diff line number Diff line Loading @@ -58,35 +58,21 @@ bool bb = 1; bool bbb = 0; QCOR_EXPECT_TRUE(ii == 10); // FIXME Need to fix float[] comparison // QCOR_EXPECT_TRUE(f == 0.0); // QCOR_EXPECT_TRUE(ff == 3.14); QCOR_EXPECT_TRUE(result == 0); QCOR_EXPECT_TRUE(results[0] == 0); QCOR_EXPECT_TRUE(results[1] == 0); QCOR_EXPECT_TRUE(b == 0); QCOR_EXPECT_TRUE(z == 0); QCOR_EXPECT_TRUE(bb == 1); QCOR_EXPECT_TRUE(bbb == 0); QCOR_EXPECT_TRUE(f == 0.0); QCOR_EXPECT_TRUE(ff == 3.14); // print(dd); // print(ffff); // print(layers); // print(layers2); // print(t); // print(tt); // print(mypi); // print(added); // print(added_diff_types); // print(tmp); // print(b, z); // print(bb); // print(bbb); // print(f); // print(ff); )#"; auto mlir = qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::MLIR, true); std::cout << "MLIR:\n" << mlir << "\n"; qcor::execute("qasm3", src, "test"); EXPECT_FALSE(qcor::execute("qasm3", src, "test")); } int main(int argc, char **argv) { Loading
mlir/parsers/qasm3/tests/test_casting.cpp 0 → 100644 +49 −0 Original line number Diff line number Diff line #include "gtest/gtest.h" #include "qcor_mlir_api.hpp" TEST(qasm3VisitorTester, checkUintIndexing) { const std::string uint_index = R"#(OPENQASM 3; include "qelib1.inc"; uint[4] b_in = 15; bool b1 = bool(b_in[0]); bool b2 = bool(b_in[1]); bool b3 = bool(b_in[2]); bool b4 = bool(b_in[3]); print(b1,b2,b3,b4); QCOR_EXPECT_TRUE(b1 == 1); QCOR_EXPECT_TRUE(b2 == 1); QCOR_EXPECT_TRUE(b3 == 1); QCOR_EXPECT_TRUE(b4 == 1); )#"; auto mlir = qcor::mlir_compile("qasm3", uint_index, "uint_index", qcor::OutputType::MLIR, false); std::cout << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", uint_index, "uint_index")); } TEST(qasm3VisitorTester, checkCastBitToInt) { const std::string cast_int = R"#(OPENQASM 3; include "qelib1.inc"; bit c[4] = "1111"; int[4] t = int[4](c); // should print 15 print(t); QCOR_EXPECT_TRUE(t == 15); )#"; auto mlir = qcor::mlir_compile("qasm3", cast_int, "cast_int", qcor::OutputType::MLIR, false); std::cout << "cast_int MLIR:\n" << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", cast_int, "cast_int")); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); return ret; } No newline at end of file
mlir/parsers/qasm3/tests/test_declaration.cpp 0 → 100644 +70 −0 Original line number Diff line number Diff line #include "gtest/gtest.h" #include "qcor_mlir_api.hpp" TEST(qasm3VisitorTester, checkDeclaration) { const std::string src = R"#(OPENQASM 3; include "qelib1.inc"; int[10] x, y; QCOR_EXPECT_TRUE(x == 0); QCOR_EXPECT_TRUE(y == 0); int[5] xx=2, yy=1; QCOR_EXPECT_TRUE(xx == 2); QCOR_EXPECT_TRUE(yy == 1); qubit q1[6], q2; bit b1[4]="0100", b2 = "1"; QCOR_EXPECT_TRUE(b1[0] == 0); QCOR_EXPECT_TRUE(b1[1] == 1); QCOR_EXPECT_TRUE(b1[2] == 0); QCOR_EXPECT_TRUE(b1[3] == 0); bit k, kk[22]; QCOR_EXPECT_TRUE(k == 0); QCOR_EXPECT_TRUE(kk[13] == 0); bool bb = False; bool m=True, n=bool(xx); QCOR_EXPECT_TRUE(m == 1); QCOR_EXPECT_TRUE(bb == 0); QCOR_EXPECT_TRUE(n == 0); const c = 5.5e3, d=5; const e = 2.2; QCOR_EXPECT_TRUE(c == 5500.0); QCOR_EXPECT_TRUE(d == 5); QCOR_EXPECT_TRUE(e == 2.2); x q2; k = measure q2; QCOR_EXPECT_TRUE(k == 1); for i in [0:22] { QCOR_EXPECT_TRUE(kk[i] == 0); } )#"; auto mlir = qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::MLIR, true); std::cout << "MLIR:\n" << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", src, "test")); const std::string src2 = R"#(OPENQASM 3; include "qelib1.inc"; bit kk[22]; for i in [0:22] { print("should only see 0 bc next statement will fail: ", i); QCOR_EXPECT_TRUE(kk[i] == 1); } )#"; auto mlir2 = qcor::mlir_compile("qasm3", src2, "test", qcor::OutputType::MLIR, true); std::cout << "MLIR:\n" << mlir2 << "\n"; EXPECT_TRUE(qcor::execute("qasm3", src2, "test")); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); return ret; } No newline at end of file
mlir/parsers/qasm3/tests/test_loop_stmts.cpp 0 → 100644 +72 −0 Original line number Diff line number Diff line #include "gtest/gtest.h" #include "qcor_mlir_api.hpp" TEST(qasm3VisitorTester, checkLoops) { const std::string for_stmt = R"#(OPENQASM 3; include "qelib1.inc"; int[32] loop_count = 0; for i in {11,22,33} { print(i); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 3); loop_count = 0; for i in [0:10] { print(i); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 10); loop_count = 0; for j in [0:2:4] { print("steps:", j); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 2); loop_count = 0; for j in [0:4] { print("j in 0:4", j); loop_count += 1; } QCOR_EXPECT_TRUE(loop_count == 4); loop_count = 0; for i in [0:4] { for j in {1,2,3} { print(i,j); loop_count += 1; } } QCOR_EXPECT_TRUE(loop_count == 12); )#"; auto mlir = qcor::mlir_compile("qasm3", for_stmt, "for_stmt", qcor::OutputType::MLIR, false); std::cout << "for_stmt MLIR:\n" << mlir << "\n"; EXPECT_FALSE(qcor::execute("qasm3", for_stmt, "for_stmt")); const std::string while_stmt = R"#(OPENQASM 3; include "qelib1.inc"; int[32] i = 0; while (i < 10) { print(i); i += 1; } QCOR_EXPECT_TRUE(i == 10); )#"; auto mlir2 = qcor::mlir_compile("qasm3", while_stmt, "while_stmt", qcor::OutputType::MLIR, false); std::cout << mlir2 << "\n"; EXPECT_FALSE(qcor::execute("qasm3", while_stmt, "while_stmt")); } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); return ret; } No newline at end of file