Unverified Commit 5dcf66d8 authored by Mccaskey, Alex's avatar Mccaskey, Alex Committed by GitHub
Browse files

Merge pull request #109 from tnguyen-ornl/tnguyen/mcu

QCOR Kernel to support multiple controls
parents 96165454 f09854e3
Loading
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -26,3 +26,6 @@ add_test(NAME quasimo_qaoa COMMAND ${CMAKE_BINARY_DIR}/qcor ${CMAKE_CURRENT_SOUR
add_test(NAME quasimo_qite COMMAND ${CMAKE_BINARY_DIR}/qcor ${CMAKE_CURRENT_SOURCE_DIR}/quasimo/QiteWorkflow.cpp)
add_test(NAME quasimo_heisenberg COMMAND ${CMAKE_BINARY_DIR}/qcor ${CMAKE_CURRENT_SOURCE_DIR}/quasimo/TdWorkflowHeisenbergModel.cpp)
add_test(NAME quasimo_verified_qpe COMMAND ${CMAKE_BINARY_DIR}/qcor ${CMAKE_CURRENT_SOURCE_DIR}/quasimo/VerifiedQuantumPhaseEstimation.cpp)
add_test(NAME hadamard_ctrl_test COMMAND ${CMAKE_BINARY_DIR}/qcor ${CMAKE_CURRENT_SOURCE_DIR}/ctrl-gates/simple_hadamard_test.cpp)
add_test(NAME multi_ctrl_test COMMAND ${CMAKE_BINARY_DIR}/qcor ${CMAKE_CURRENT_SOURCE_DIR}/ctrl-gates/multiple_controls.cpp)
+22 −0
Original line number Diff line number Diff line
// X kernel
__qpu__ void x_gate(qreg q) { X(q[0]); }

__qpu__ void ccxtest(qreg q) {
  for (int i = 0; i < q.size(); i++) {
    X(q[i]);
  } 

  // apply ctrl-U (CCX = Toffoli)
  x_gate::ctrl({q[1], q[2]}, q);

  // measure
  for (int i = 0; i < q.size(); i++) {
    Measure(q[i]);
  } 
}

int main() {
  auto q = qalloc(3);
  ccxtest(q);
  q.print();
}
 No newline at end of file
+22 −2
Original line number Diff line number Diff line
@@ -265,11 +265,31 @@ class pyxasm_visitor : public pyxasmBaseVisitor {
          }
        }
      } else {
        // Handle Python list assignment:
        // i.e. lhs = [a, b, c] => { a, b, c }
        // NOTE: we only support simple lists, i.e. no nested.
        const auto transformListAssignmentIfAny =
            [](const std::string &in_expr) -> std::string {
          const auto whitespace = " ";
          // Trim leading and trailing spaces:
          const auto strBegin = in_expr.find_first_not_of(whitespace);
          const auto strEnd = in_expr.find_last_not_of(whitespace);
          const auto strRange = strEnd - strBegin + 1;
          const auto trim_expr = in_expr.substr(strBegin, strRange);

          if (trim_expr.front() == '[' && trim_expr.back() == ']') {
            return "{" + trim_expr.substr(1, trim_expr.size() - 2) + "}";
          }

          // Returns the original expression:
          return in_expr;
        };

        if (xacc::container::contains(declared_var_names, lhs)) {
          ss << lhs << " = " << rhs << "; \n";
          ss << lhs << " = " << transformListAssignmentIfAny(rhs) << "; \n";
        } else {
          // New variable: need to add *auto*
          ss << "auto " << lhs << " = " << rhs << "; \n";
          ss << "auto " << lhs << " = " << transformListAssignmentIfAny(rhs) << "; \n";
          new_var = lhs;
        }
      }
+7 −0
Original line number Diff line number Diff line
@@ -52,3 +52,10 @@ add_test (NAME qcor_python_jit_pass_manager
 )
 set_tests_properties(qcor_python_jit_pass_manager
     PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}")

add_test (NAME qcor_python_jit_multi_ctrl
  COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test_jit_multi_ctrl.py
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
set_tests_properties(qcor_python_jit_multi_ctrl
  PROPERTIES ENVIRONMENT "PYTHONPATH=${CMAKE_INSTALL_PREFIX}:$ENV{PYTHONPATH}")
 No newline at end of file
Loading