Commit dbfc6719 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

finished updates to syntax handler to auto-gen new quantum kernel subtype...


finished updates to syntax handler to auto-gen new quantum kernel subtype code. most examples now work. implemented quantum kernel static ctrl method, qpe works. next up, updates to qcor hybrid

Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent 00ca132b
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
#include "qcor.hpp"

__qpu__ void measure_qbits(qreg q) {
  for (int i = 0; i < 2; i++) {
    Measure(q[i]);
  }
}

__qpu__ void quantum_kernel(qreg q, double x) {
    X(q[0]);
    Ry(q[1], x);
    CX(q[1],q[0]);
}

__qpu__ void z0z1(qreg q, double x) {
    quantum_kernel(q, x);
    measure_qbits(q);
}

__qpu__ void check_adjoint(qreg q, double x) {
    quantum_kernel(q,x);
    quantum_kernel::adjoint(q,x);
    measure_qbits(q);
}

int main() {
  auto q = qalloc(2);

  quantum_kernel(q, 2.2);

  q.print();

  auto r = qalloc(2);

  z0z1(r, 2.2);
  r.print();

  auto v = qalloc(2);

  check_adjoint(v, 2.2);
  v.print();

}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
#include "qcor.hpp"
#include <random>

__qpu__ void qaoa_ansatz(qreg q, int n_steps, std::vector<double> gamma,
                         std::vector<double> beta,
                         qcor::PauliOperator& cost_ham) {
+2 −4
Original line number Diff line number Diff line
#include "qcor.hpp"
// Use the pre-defined IQFT kernel
#include "qft.hpp"

using namespace qcor;
// using namespace qcor;

// The Oracle: T gate
__qpu__ void compositeOp(qreg q) {
@@ -40,7 +39,7 @@ __qpu__ void QuantumPhaseEstimation(qreg q) {
    for (int j = 0; j < nbCalls; ++j) {
      int ctlBit = i;
      // Controlled-Oracle
      Controlled::Apply(ctlBit, compositeOp, q);
      compositeOp::ctrl(ctlBit, q);
    }
  }

@@ -62,5 +61,4 @@ int main(int argc, char **argv) {
  // dump the results
  // EXPECTED: only "100" bitstring
  q.print();
  qcor::print_kernel(std::cout, QuantumPhaseEstimation, q);
}
+0 −1
Original line number Diff line number Diff line
#include <qalloc>

// Define a multi-register kernel
__qpu__ void bell_multi(qreg q, qreg r) {
+0 −1
Original line number Diff line number Diff line
#include "qcor.hpp"

__qpu__ void ansatz(qreg q, double theta) {
  X(q[0]);
Loading