Commit 06411560 authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

Fixing the alias test to work prevent name collision



hence, no need to work around by creating new qubit variable names.
i.e., we need consistent qubit variable names for SSA value tracing (including when this is a broadcast)

Also, fixed the handling of negative range bounds.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 87b35412
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -37,8 +37,8 @@ QCOR_EXPECT_TRUE(m1[5] == 0);

// Test 2: Alias by slice:
// 0, 1, 2, 3 (inclusive)
let myreg1 = q[0:3];
x myreg1;
let myreg_1 = q[0:3];
x myreg_1;
// Measure all qubits
bit m2[6];
m2 = measure q;
@@ -57,8 +57,8 @@ QCOR_EXPECT_TRUE(m2[5] == 0);
reset q;

// Range with step size (0, 2, 4)
let myreg2 = q[0:2:5];
x myreg2;
let myreg_2 = q[0:2:5];
x myreg_2;
// Measure all qubits
bit m3[6];
m3 = measure q;
@@ -77,8 +77,8 @@ QCOR_EXPECT_TRUE(m3[5] == 0);
reset q;
// Range with negative step:
// 4, 3, 2
let myreg3 = q[4:-1:2];
x myreg3;
let myreg_3 = q[4:-1:2];
x myreg_3;
// Measure all qubits
bit m4[6];
m4 = measure q;
@@ -97,8 +97,8 @@ QCOR_EXPECT_TRUE(m4[5] == 0);
reset q;
// Range with start = stop
// This is q[5]
let myreg4 = q[5:5];
x myreg4;
let myreg_4 = q[5:5];
x myreg_4;
// Measure all qubits
bit m5[6];
m5 = measure q;
+4 −4
Original line number Diff line number Diff line
@@ -71,8 +71,8 @@ mlir::Type get_custom_opaque_type(const std::string& type,
mlir::Value get_or_extract_qubit(const std::string &qreg_name,
                                 const std::size_t idx, mlir::Location location,
                                 ScopedSymbolTable &symbol_table,
                                 mlir::OpBuilder& builder, std::string prepended_st_name) {
  auto key = prepended_st_name + qreg_name + std::to_string(idx);
                                 mlir::OpBuilder &builder) {
  auto key = qreg_name + std::to_string(idx);
  if (symbol_table.has_symbol(key)) {
    return symbol_table.get_symbol(key);  // global_symbol_table[key];
  } else {
+3 −3
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ mlir::Type get_custom_opaque_type(const std::string& type,
mlir::Value get_or_extract_qubit(const std::string &qreg_name,
                                 const std::size_t idx, mlir::Location location,
                                 ScopedSymbolTable &symbol_table,
                                 mlir::OpBuilder& builder, std::string prepended_st_name = "");
                                 mlir::OpBuilder &builder);

mlir::Value get_or_create_constant_integer_value(
    const std::size_t idx, mlir::Location location, mlir::Type int_like_type,
+5 −2
Original line number Diff line number Diff line
@@ -196,8 +196,10 @@ antlrcpp::Any qasm3_visitor::visitAliasStatement(
                slice_size_calc(orig_size, range_start, range_step, range_stop);
            // std::cout << "Adding symbol 2 " << in_aliasName << "\n";
            for (int dest_idx = 0; dest_idx < new_size; ++dest_idx) {
              const int source_idx = range_start + dest_idx * range_step;

              const int64_t range_start_pos =
                  range_start >= 0 ? range_start : orig_size + range_start;
              const int source_idx = range_start_pos + dest_idx * range_step;
              assert(source_idx >= 0);
              // Put the *alias* qubit (alias-name + index) into the symbol
              // table: mapped to the original qubit:
              const std::string alias_qubit_var_name =
@@ -288,6 +290,7 @@ antlrcpp::Any qasm3_visitor::visitAliasStatement(
            mlir::Value source_qreg_value = dest_idx < first_reg_size
                                                ? first_reg_symbol
                                                : second_reg_symbol;
            assert(source_idx >= 0);
            // Put the *alias* qubit (alias-name + index) into the symbol
            // table: mapped to the original qubit:
            const std::string alias_qubit_var_name =
+1 −2
Original line number Diff line number Diff line
@@ -58,8 +58,7 @@ void qasm3_visitor::createInstOps_HandleBroadcast(
        auto qubit_type = get_custom_opaque_type("Qubit", builder.getContext());

        auto extract_value = get_or_extract_qubit(
            qreg_names[0], i, location, symbol_table, builder,
            "__mlir__qasm3__expand__bcast_single_inst_");
            qreg_names[0], i, location, symbol_table, builder);

        std::vector<mlir::Type> ret_types;
        for (auto q : qbit_values) {