Unverified Commit a6fcb6af authored by Thien Nguyen's avatar Thien Nguyen Committed by GitHub
Browse files

Merge pull request #237 from tnguyen-ornl/tnguyen/pnnl-tutorials

Added source files from PNNL demo/tutorial session

Example files only, no code changes.
parents f198798c 5d580a23
Loading
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line


__qpu__ void ccnot(qreg q) {
  decompose {
    UnitaryMatrix ccnot_mat = UnitaryMatrix::Identity(8, 8);
    ccnot_mat(6, 6) = 0.0;
    ccnot_mat(7, 7) = 0.0;
    ccnot_mat(6, 7) = 1.0;
    ccnot_mat(7, 6) = 1.0;
  }
  (q, QFAST);
}

int main() {
  auto q = qalloc(3);
  ccnot::print_kernel(q);
  return 0;
}
 No newline at end of file
+16 −0
Original line number Diff line number Diff line
from qcor import *

@qjit
def nothing(q : qreg):
  # This is Z Z = I
  Z(q[0])
  H(q[0])
  X(q[0])
  H(q[0])

  H(q[1])
  Rx(q[1], 1.2345)
  H(q[1])

set_opt_level(2)
nothing.print_kernel(qalloc(2))
 No newline at end of file
+27 −0
Original line number Diff line number Diff line
// Demonstrate the programmability of a simple kernel
// (1) Run with QPP first
// (2) Run with noisy backend (remote Honeywell simulator)
// qcor -set-credentials honeywell
// qcor ghz.cpp -qpu honeywell:HQS-LT-S1-SIM -shots 1024
// (3) Run with IonQ 
// qcor ghz.cpp -qpu ionq -shots 1024
// (4) Run with OLCF QLM simulator (QLMaaS)
// qcor ghz.cpp -qpu atos-qlm -shots 1024
// (5) Run with just print_kernel to show automatic placement
// Uncomment print_kernel
// qcor ghz.cpp -qpu ibm:ibmq_toronto

__qpu__ void ghz(qreg q) {
  H(q[0]);
  for (int i = 0; i < q.size() - 1; i++) {
    CX(q[i], q[i + 1]);
  }
  Measure(q);
}

int main() {
  auto q = qalloc(6);
  ghz(q);
  q.print();
  // ghz::print_kernel(q);
}
 No newline at end of file
+17 −0
Original line number Diff line number Diff line
from qcor import *

@qjit
def ghz(q : qreg):
    H(q[0])
    for i in range(q.size()-1):
        X.ctrl([q[i]], q[i+1])

    Measure(q)

set_qpu('ionq')
set_shots(1024)
q = qalloc(6)

ghz(q)
q.print()
# ghz.print_kernel(q)
+55 −0
Original line number Diff line number Diff line
// Create a general grover search algorithm.
// Let's create that marks 2 states
// Show figures Init - [Oracle - Amplification for i in iters] - Measure
// https://www.nature.com/articles/s41467-017-01904-7

// Show off kernel composition, common patterns, 
// functional programming (kernels taking other kernels)

using GroverPhaseOracle = KernelSignature<qreg>;

__qpu__ void amplification(qreg q) {
  // H q X q ctrl-ctrl-...-ctrl-Z H q Xq
  // compute - action - uncompute

  compute {
    H(q);
    X(q);
  }
  action {
    auto ctrl_bits = q.head(q.size() - 1);
    auto last_qubit = q.tail();
    Z::ctrl(ctrl_bits, last_qubit);
  }
}

__qpu__ void run_grover(qreg q, GroverPhaseOracle oracle,
                        const int iterations) {
  H(q);

  for (int i = 0; i < iterations; i++) {
    oracle(q);
    amplification(q);
  }

  Measure(q);
}

__qpu__ void oracle(qreg q) {
  // Mark 101 and 011
  CZ(q[0], q[2]);
  CZ(q[1], q[2]);
}

int main() {
  const int N = 3;

  // Allocate some qubits
  auto q = qalloc(N);

  // Call grover given the oracle and n iterations
  run_grover(q, oracle, 1);

  // print the histogram
  q.print();
}
 No newline at end of file
Loading