Loading mlir/parsers/qasm3/tests/test_subroutine.cpp +64 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,70 @@ print("Avg <X0X1> = ", exp_val); EXPECT_FALSE(qcor::execute(sub1, "check_deuteron")); } TEST(qasm3VisitorTester, checkSubroutineAdder) { const std::string sub1 = R"#(OPENQASM 3; gate ccx a,b,c { h c; cx b,c; tdg c; cx a,c; t c; cx b,c; tdg c; cx a,c; t b; t c; h c; cx a,b; t a; tdg b; cx a,b; } gate majority a, b, c { cx c, b; cx c, a; ccx a, b, c; } gate unmaj a, b, c { ccx a, b, c; cx c, a; cx a, b; } qubit cin; qubit a[8]; qubit b[8]; qubit cout; bit ans[9]; // Input values: uint[8] a_in = 5; uint[8] b_in = 4; for i in [0:8] { if (bool(a_in[i])) { x a[i]; } if (bool(b_in[i])) { x b[i]; } } // add a to b, storing result in b majority cin, b[0], a[0]; for i in [0: 7] { majority a[i], b[i + 1], a[i + 1]; } cx a[7], cout; for i in [6: -1: -1] { unmaj a[i], b[i+1], a[i+1]; } unmaj cin, b[0], a[0]; measure b[0:7] -> ans[0:7]; measure cout[0] -> ans[8];)#"; auto llvm_ir = qcor::mlir_compile(sub1, "check_deuteron", qcor::OutputType::LLVMIR, false); std::cout << llvm_ir << "\n"; } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); Loading Loading
mlir/parsers/qasm3/tests/test_subroutine.cpp +64 −0 Original line number Diff line number Diff line Loading @@ -84,6 +84,70 @@ print("Avg <X0X1> = ", exp_val); EXPECT_FALSE(qcor::execute(sub1, "check_deuteron")); } TEST(qasm3VisitorTester, checkSubroutineAdder) { const std::string sub1 = R"#(OPENQASM 3; gate ccx a,b,c { h c; cx b,c; tdg c; cx a,c; t c; cx b,c; tdg c; cx a,c; t b; t c; h c; cx a,b; t a; tdg b; cx a,b; } gate majority a, b, c { cx c, b; cx c, a; ccx a, b, c; } gate unmaj a, b, c { ccx a, b, c; cx c, a; cx a, b; } qubit cin; qubit a[8]; qubit b[8]; qubit cout; bit ans[9]; // Input values: uint[8] a_in = 5; uint[8] b_in = 4; for i in [0:8] { if (bool(a_in[i])) { x a[i]; } if (bool(b_in[i])) { x b[i]; } } // add a to b, storing result in b majority cin, b[0], a[0]; for i in [0: 7] { majority a[i], b[i + 1], a[i + 1]; } cx a[7], cout; for i in [6: -1: -1] { unmaj a[i], b[i+1], a[i+1]; } unmaj cin, b[0], a[0]; measure b[0:7] -> ans[0:7]; measure cout[0] -> ans[8];)#"; auto llvm_ir = qcor::mlir_compile(sub1, "check_deuteron", qcor::OutputType::LLVMIR, false); std::cout << llvm_ir << "\n"; } int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); auto ret = RUN_ALL_TESTS(); Loading