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

Single-qubit aliasing to return a qubit rather than an array



Also, rename the test name to be consistent with others

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent a361900f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -7,10 +7,10 @@ link_directories(${XACC_ROOT}/lib)
#target_include_directories(qasm3VisitorTester PRIVATE . ../../ ${XACC_ROOT}/include/gtest)
#target_link_libraries(qasm3VisitorTester qcor-mlir-api gtest gtest_main)

add_executable(qasm3VisitorAliasTester test_alias_handler.cpp)
add_test(NAME qcor_qasm3_quantum_alias_decl_tester COMMAND qasm3VisitorAliasTester)
target_include_directories(qasm3VisitorAliasTester PRIVATE . ../../ ${XACC_ROOT}/include/gtest)
target_link_libraries(qasm3VisitorAliasTester qcor-mlir-api gtest gtest_main)
add_executable(qasm3CompilerTester_Alias test_alias_handler.cpp)
add_test(NAME qcor_qasm3_quantum_alias_decl_tester COMMAND qasm3CompilerTester_Alias)
target_include_directories(qasm3CompilerTester_Alias PRIVATE . ../../ ${XACC_ROOT}/include/gtest)
target_link_libraries(qasm3CompilerTester_Alias qcor-mlir-api gtest gtest_main)

add_executable(qasm3CompilerTester_Assignment test_assignment.cpp)
add_test(NAME qcor_qasm3_classical_assignment_tester COMMAND qasm3CompilerTester_Assignment)
+19 −0
Original line number Diff line number Diff line
@@ -195,6 +195,25 @@ QCOR_EXPECT_TRUE(m9[2] == 1);
QCOR_EXPECT_TRUE(m9[3] == 0);
QCOR_EXPECT_TRUE(m9[4] == 1);
QCOR_EXPECT_TRUE(m9[5] == 1);

// Check one-qubit alias:
// Reset q to start next test
reset q;
let first_qubit = q[0];
let last_qubit = q[5];
x first_qubit;
ctrl @ x first_qubit, last_qubit;
// Measure all qubits
bit m10[6];
m10 = measure q;

// First and last qubits are 1:
QCOR_EXPECT_TRUE(m10[0] == 1);
QCOR_EXPECT_TRUE(m10[1] == 0);
QCOR_EXPECT_TRUE(m10[2] == 0);
QCOR_EXPECT_TRUE(m10[3] == 0);
QCOR_EXPECT_TRUE(m10[4] == 0);
QCOR_EXPECT_TRUE(m10[5] == 1);
)#";
  auto mlir = qcor::mlir_compile("qasm3", alias_by_indicies, "test",
                                 qcor::OutputType::MLIR, true);
+12 −0
Original line number Diff line number Diff line
@@ -247,6 +247,18 @@ antlrcpp::Any qasm3_visitor::visitAliasStatement(
  // e.g. alias = q[1,3,5] || q[2] || q[4:2:8]
  processIdentifierDef(alias, context->indexIdentifier());

  // If the aliasing qreg is of size 1, just returns the Qubit.
  // (rather than an array of size 1).
  assert(!symbol_table.get_variable_attributes(alias).empty());
  const size_t alias_reg_size =
      std::stoi(symbol_table.get_variable_attributes(alias)[0]);
  if (alias_reg_size == 1) {
    auto qubit_value =
        get_or_extract_qubit(alias, 0, location, symbol_table, builder);
    // Overwrite the alias with the qubit.
    symbol_table.add_symbol(alias, qubit_value, {"1"}, true);
  }

  return 0;
}
} // namespace qcor
 No newline at end of file