Commit 22652cf6 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

update all variables to be memref<TYPE> on shape of rank 0. fixed how const...


update all variables to be memref<TYPE> on shape of rank 0. fixed how const global vars are handled, they are now global memrefs

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 731de70f
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -155,7 +155,6 @@ void OpenQasmV3MLIRGenerator::finalize_mlirgen() {

      builder.setInsertionPointToEnd(b);
    } else {
      //   std::cout << "CURRENT BLOCK WAS NULL\n";
      builder.setInsertionPointToEnd(main_entry_block);
    }

+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ class qasm3_visitor : public qasm3::qasm3BaseVisitor {
    qubit_type = mlir::OpaqueType::get(context, dialect, qubit_type_name);
    array_type = mlir::OpaqueType::get(context, dialect, array_type_name);
    result_type = mlir::IntegerType::get(context, 1);
    symbol_table.set_op_builder(builder);
  }

  // Visit nodes corresponding to quantum variable and gate declarations.
+4 −4
Original line number Diff line number Diff line
@@ -48,10 +48,10 @@ target_include_directories(qasm3CompilerTester_Subroutine PRIVATE . ../../ ${XAC
target_link_libraries(qasm3CompilerTester_Subroutine qcor-mlir-api gtest gtest_main)


#add_executable(qasm3CompilerTester_GlobalConstInSubroutine test_use_global_const_in_subroutine.cpp)
#add_test(NAME qcor_qasm3_test_global_const_subroutine COMMAND qasm3CompilerTester_GlobalConstInSubroutine)
#target_include_directories(qasm3CompilerTester_GlobalConstInSubroutine PRIVATE . ../../ ${XACC_ROOT}/include/gtest)
#target_link_libraries(qasm3CompilerTester_GlobalConstInSubroutine qcor-mlir-api gtest gtest_main)
add_executable(qasm3CompilerTester_GlobalConstInSubroutine test_use_global_const_in_subroutine.cpp)
add_test(NAME qcor_qasm3_test_global_const_subroutine COMMAND qasm3CompilerTester_GlobalConstInSubroutine)
target_include_directories(qasm3CompilerTester_GlobalConstInSubroutine PRIVATE . ../../ ${XACC_ROOT}/include/gtest)
target_link_libraries(qasm3CompilerTester_GlobalConstInSubroutine qcor-mlir-api gtest gtest_main)


add_executable(qasm3CompilerTester_Arithmetic test_complex_arithmetic.cpp)
+14 −6
Original line number Diff line number Diff line
@@ -4,8 +4,10 @@
TEST(qasm3VisitorTester, checkDeclaration) {
  const std::string src = R"#(OPENQASM 3;
include "qelib1.inc";
int[10] x, y;
QCOR_EXPECT_TRUE(x == 0);
int[10] x = 5;
int[10] y;
print(x);
QCOR_EXPECT_TRUE(x == 5);
QCOR_EXPECT_TRUE(y == 0);

int[5] xx=2, yy=1;
@@ -22,30 +24,36 @@ 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);
}

float[64] f = 3.14;
float[64] test = 3.14 - f;
QCOR_EXPECT_TRUE(test < .001);
)#";
  auto mlir =
      qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::MLIR, true);
  std::cout << "MLIR:\n" << mlir << "\n";
      auto llvmi =
      qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::LLVMMLIR, true);
  std::cout << "LLVM:\n" << llvmi << "\n";
    auto llvm =
      qcor::mlir_compile("qasm3", src, "test", qcor::OutputType::LLVMIR, true);
  std::cout << "LLVM:\n" << llvm << "\n";
  EXPECT_FALSE(qcor::execute("qasm3", src, "test"));

  const std::string src2 = R"#(OPENQASM 3;
+56 −0
Original line number Diff line number Diff line
#include "gtest/gtest.h"
#include "qcor_mlir_api.hpp"

TEST(qasm3VisitorTester, checkGlobalConstInSubroutine) {
  const std::string global_const = R"#(OPENQASM 3;
include "qelib1.inc";
const shots = 1024;
print(shots);
int[32] i = shots + 1;
print(i);

const t =  22;
print(t);

const n = t / 2 ;

def test(float[32]:tt)-> int[64] {
    int[64] s = 10;
    print("s = ", s);
    print(tt);
    tt = 2.2;
    print(tt);
    s = shots;
    for i in [0:n] {
      print(i);
    }
    return s;
}

// qubit q;
float[32] ttt;
int[64] r = test(ttt) ;
print(r);
print(ttt);
QCOR_EXPECT_TRUE(r == 1024);
)#";

  int opt_level = 0;

  auto mlir = qcor::mlir_compile("qasm3", global_const, "global_const",
                                 qcor::OutputType::MLIR, true);
  std::cout << mlir << "\n";

  auto llvm = qcor::mlir_compile("qasm3", global_const, "global_const",
                                 qcor::OutputType::LLVMIR, true);
  std::cout << llvm << "\n";

  // Hvae to set opt level 0 since llvm.lifetime.start.* can't be found by JIT
  EXPECT_FALSE(qcor::execute("qasm3", global_const, "global_const", 0));
}

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