Commit 975c2531 authored by Mccaskey, Alex's avatar Mccaskey, Alex
Browse files

adding jit example


Signed-off-by: Mccaskey, Alex's avatarAlex McCaskey <mccaskeyaj@ornl.gov>
parent ef8197da
Pipeline #116058 passed with stages
in 67 minutes and 36 seconds
// To use the QCOR JIT utilities
// just include the qcor_jit.hpp header
#include "qcor_jit.hpp"
int main() {
// QJIT is the entry point to QCOR quantum kernel
// just in time compilation
QJIT qjit;
// Define a quantum kernel string dynamically
const auto kernel_src = R"#(__qpu__ void bell(qreg q) {
using qcor::openqasm;
h q[0];
cx q[0], q[1];
creg c[2];
measure q -> c;
})#";
// Use the QJIT instance to compile this at runtime
qjit.jit_compile(kernel_src);
// Now, one can get the compiled kernel as a
// functor to execute, must provide the kernel
// argument types as template parameters
auto bell_functor = qjit.get_kernel<qreg>("bell");
// Allocate some qubits and run the kernel functor
auto q = qalloc(2);
bell_functor(q);
q.print();
// Or, one can call the QJIT invoke method
// with the name of the kernel function and
// the necessary function arguments.
auto r = qalloc(2);
qjit.invoke("bell", r);
r.print();
// Note, if QCOR QJIT has not seen this kernel
// source code before, it will run through the
// entire JIT compile process. If you have run
// this JIT compile before, QCOR QJIT will read a
// cached representation of the kernel and load that,
// increasing JIT compile performance.
}
\ No newline at end of file
#include "qcor.hpp"
#include "qcor_jit.hpp"
int main() {
QJIT qjit;
qjit.jit_compile(R"#(__qpu__ void bell(qreg q) {
printf("hello world\n");
using qcor::openqasm;
h q[0];
cx q[0], q[1];
creg c[2];
measure q -> c;
})#");
auto q = qalloc(2);
qjit.invoke("bell", q);
q.print();
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment