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

Added a util print function to examine FTQC execution



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 5e7b016b
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ class pyxasm_visitor : public pyxasmBaseVisitor {
        // reassemble the call:
        // Check that the *first* argument is a *qreg* in the current context of
        // *this* kernel.
        if (!context->trailer().empty() &&
        if (!context->trailer().empty() && context->trailer()[0]->arglist() &&
            !context->trailer()[0]->arglist()->argument().empty() &&
            xacc::container::contains(
                bufferNames,
@@ -195,6 +195,14 @@ class pyxasm_visitor : public pyxasmBaseVisitor {
          ss << ");\n";
          result.first = ss.str();
        }
        else {
          // A classical call-like expression: i.e. not a kernel call:
          // Just output it *as-is* to the C++ stream.
          // We can hook more sophisticated code-gen here if required.
          std::stringstream ss;
          ss << context->getText() << ";\n";
          result.first = ss.str();
        }
      }
    }
    return 0;
+8 −2
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ def measureSyndrome(q : qreg, logicalIdx: int, ancIdx: int):
    if parity12:
        #Reset anc qubit
        X(q[ancIdx])
    # Note: only in FTQC runtime that we can examine the measure results in realtime.
    print("Parity01 =", parity01, "Parity12 =", parity12)

@qjit
def testBitflipCode(q : qreg):
@@ -39,8 +41,12 @@ def testBitflipCode(q : qreg):
    encodeLogicalQubit(q)
    measureSyndrome(q, 0, 3)
    # Apply an X error
    X(q[0])
    for i in range(3):
        print("Apply X error @ ", i)
        X(q[i])
        measureSyndrome(q, 0, 3)
        # Cancel the error for the next test
        X(q[i])


# Allocate 4 qubits: 3 qubits + 1 ancilla
+7 −0
Original line number Diff line number Diff line
@@ -90,6 +90,13 @@ inline std::vector<int> range(int start, int stop) {
template <typename T> int len(const T &countable) { return countable.size(); }
template <typename T> int len(T &countable) { return countable.size(); }

// Python-like print instructions:
inline void print() { std::cout << "\n"; }
template <typename T, typename... TAIL> void print(const T &t, TAIL... tail) {
  std::cout << t << " ";
  print(tail...);
}

// The TranslationFunctor maps vector<double> to a tuple of Args...
template <typename... Args>
using TranslationFunctor =