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

First pass of impl FTQC qrt



Basic functionality implemented.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent b8ee6202
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
#include <qalloc>
// Compile with: qcor -qpu qpp -qrt ftqc simple-demo.cpp
// Execute: ./a.out
// We should get the print out conditioned by the measurement.
// If not using the "ftqc" QRT, this will cause errors since the Measure results
// are not available yet.

__qpu__ void bell(qreg q) {
  using qcor::xasm;
  H(q[0]);
  CX(q[0], q[1]);
  for (int i = 0; i < 2; i++)
    X(q[i]);
  
  Measure(q[0]);
  
  if (q.cReg(0)) {
    std::cout << "Q0 = 1 !\n";
  } 
  
  Measure(q[1]);
  if (q.cReg(1)) {
    std::cout << "Q1 = 1 !\n";
  } 
}

int main() {
  qcor::set_verbose(true);
  auto q = qalloc(2);
  bell(q);
}
+7 −3
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
#include "qrt.hpp"

namespace qcor {
enum class QrtType { NISQ, FTQC };

// The QuantumKernel represents the super-class of all qcor
// quantum kernel functors. Subclasses of this are auto-generated
@@ -50,10 +51,11 @@ public:
  // Flag to indicate we only want to
  // run the pass manager and not execute
  bool optimize_only = false;
  enum class QrtType { NISQ, FTQC };
  QrtType runtime_env = QrtType::NISQ;
  // Default constructor, takes quantum kernel function arguments
  QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) {}
  QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) {
    runtime_env = (__qrt_env == "ftqc") ? QrtType::FTQC : QrtType::NISQ;
  }

  // Internal constructor, provide parent kernel, this
  // kernel now represents a nested kernel call and
@@ -61,7 +63,9 @@ public:
  QuantumKernel(std::shared_ptr<qcor::CompositeInstruction> _parent_kernel,
                Args... args)
      : args_tuple(std::forward_as_tuple(args...)),
        parent_kernel(_parent_kernel), is_callable(false) {}
        parent_kernel(_parent_kernel), is_callable(false) {
    runtime_env = (__qrt_env == "ftqc") ? QrtType::FTQC : QrtType::NISQ;
  }

  // Static method for printing this kernel as a flat qasm string
  static void print_kernel(std::ostream &os, Args... args) {
+4 −0
Original line number Diff line number Diff line
@@ -19,6 +19,10 @@ namespace __internal__ {
class internal_startup {
public:
  internal_startup() {
// IMPORTANT: This needs to be set before quantum::initialize
#ifdef __internal__qcor__compile__qrt__mode
    xacc::internal_compiler::__qrt_env = __internal__qcor__compile__qrt__mode;
#endif
#ifdef __internal__qcor__compile__backend
    quantum::initialize(__internal__qcor__compile__backend, "empty");
#endif
+1 −1
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
# Contributors:
#   Alexander J. McCaskey - initial API and implementation
# *******************************************************************************/
set(LIBRARY_NAME qcor-nisq-ftqc)
set(LIBRARY_NAME qcor-ftqc-qrt)

file(GLOB SRC *.cpp)

+2 −1
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ public:
  }

  // Measure-Z
  virtual void mz(const qubit &qidx) override { /* TODO */
  virtual void mz(const qubit &qidx) override {
    applyGate("Measure", {qidx.second});
  }

  // Common two-qubit gates.
Loading