Commit 2eca0f53 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

first pass at demo package for aide-qc all hands meeting 2021

parent 8b1398a0
Loading
Loading
Loading
Loading
+52 −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

// 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
+66.3 KiB
Loading image diff...
+37 −0
Original line number Diff line number Diff line
// Demonstrate simple optimizations
// simple rotation gate mergers
// h rx ry h

// Show opt level 1, should have gates remaining, but 
// they are == I, then show opt level 2

__qpu__ void nothing(qreg qbits, const int n, double x) {
  auto q = qbits.head();
  auto r = qbits.tail();

  for (int i = 0; i < 100; i++) {
    H(q);
  }

  // This is Z Z = I
  Z(q);
  H(q);
  X(q);
  H(q);

  // Should be I if Rx on 0.0
  H(q);
  CX(q, r);
  Rx(q, x);
  X::ctrl(q, r);
  H(q);
}

int main() {
  // get a qubit
  auto qbits = qalloc(2);

  nothing(qbits, 100, 0.0);

  std::cout << nothing::as_unitary_matrix(qbits, 100, 0.0) << "\n";
}
 No newline at end of file
+33 −0
Original line number Diff line number Diff line
// Demonstrate the programmability of a simple kernel
// Run with QPP first
// Run with Aer noisy backend
// Run with just print_kernel to show automatic placement
// Run on IBM

__qpu__ void ghz(qreg q) {
    auto first = q.head();

    H(first);

    for (int i = 0; i < q.size()-1; i++) {
        CX(q[i], q[i+1]);
    }

    Measure(q);
}

int main() {

    set_shots(100);
    auto q = qalloc(6);

    ghz(q);

    auto counts = q.counts();

    for (auto [bit, count] : counts) {
        print(bit, ": ", count);
    }

    ghz::print_kernel(q);
}
 No newline at end of file
+2420 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading