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

Revert changes to the XASM token collector



It has more complex functionality hence left as is.

Modify the examples to work around this.

Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 0f5114d3
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
// If not using the "ftqc" QRT, this will cause errors since the Measure results
// are not available yet.

void setVar(int &var, int val) { var = val; }
// Using Repeat-Until-Success pattern to prepare a quantum state.
// https://docs.microsoft.com/en-us/quantum/user-guide/using-qsharp/control-flow#rus-to-prepare-a-quantum-state
__qpu__ void PrepareStateUsingRUS(qreg q, int maxIter) {
@@ -22,10 +23,13 @@ __qpu__ void PrepareStateUsingRUS(qreg q, int maxIter) {
    H(q[1]);
    Measure(q[1]);
    bool outcome = q.cReg(1);
    if (!outcome) {
    if (outcome == false) {
      // Success (until (outcome == Zero))
      std::cout << "Success after " << i + 1 << " iterations.\n";
      break;
      // Hack to implement break:
      // the 'break' keywork seems to be eaten by the XASM token collector.
      // break;
      setVar(i, maxIter);
    }
    // Fix up: Bring the auxiliary and target qubits back to |+> state.
    if (outcome) {
+0 −4
Original line number Diff line number Diff line
@@ -4,7 +4,6 @@
// 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, int nbRuns) {
  using qcor::xasm;
  for (int i = 0; i < nbRuns; ++i) {
@@ -14,9 +13,6 @@ __qpu__ void bell(qreg q, int nbRuns) {
    Measure(q[1]);
    if (q.cReg(0) == q.cReg(1)) {
      std::cout << "Iter " << i << ": Matched!\n";
    } else {
      // Should only happen if using a real (noisy) backend.
      std::cout << "Iter " << i << ": Not matched!\n";
    }
    // Reset qubits
    if (q.cReg(0)) {
+2 −6
Original line number Diff line number Diff line
@@ -186,12 +186,8 @@ void XasmTokenCollector::collect(clang::Preprocessor &PP,
      ss << qrt_visitor.get_new_src();

    } else {
      // this was a classical code string;
      // hence, append the original source line.
      // IMPORTANT: the ANTLR tokenized string may be different,
      // e.g. it may parse '&&' as two tokens hence adding a space
      // which will mess up the C++ code.
      ss << line;
      // this was a classical code string
      ss << visitor.result.first;
    }
  }
}