Loading examples/qcor_demos/pnnl_tutorials/1_kernels/ccnot_qfast.cpp 0 → 100644 +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 examples/qcor_demos/pnnl_tutorials/1_kernels/circuit_optimization.py 0 → 100644 +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 examples/qcor_demos/pnnl_tutorials/1_kernels/ghz.cpp 0 → 100644 +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 examples/qcor_demos/pnnl_tutorials/1_kernels/ghz.py 0 → 100644 +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) examples/qcor_demos/pnnl_tutorials/1_kernels/grover.cpp 0 → 100644 +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
examples/qcor_demos/pnnl_tutorials/1_kernels/ccnot_qfast.cpp 0 → 100644 +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
examples/qcor_demos/pnnl_tutorials/1_kernels/circuit_optimization.py 0 → 100644 +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
examples/qcor_demos/pnnl_tutorials/1_kernels/ghz.cpp 0 → 100644 +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
examples/qcor_demos/pnnl_tutorials/1_kernels/ghz.py 0 → 100644 +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)
examples/qcor_demos/pnnl_tutorials/1_kernels/grover.cpp 0 → 100644 +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