Loading examples/qcor_demos/ibm_qasm3_demo_092021/qcor-qrt/qrt_demo.cpp 0 → 100644 +72 −0 Original line number Diff line number Diff line #include "qcor.hpp" #include "xacc_service.hpp" // qcor qrt_demo.cpp // ./a.out // qcor qrt_demo.cpp -qpu aer:ibmq_jakarta // ./a.out using namespace quantum; int main() { // Hard code the shots for NISQ to 100 qcor::set_shots(100); { // NISQ Mode Execution // Allocate some qubits auto q = qalloc(2); // Get local reference to global qrt_impl pointer QuantumRuntime& local_qrt = *qrt_impl.get(); // Call the quantum gate instructions on the runtime // for NISQ mode, this will build up a CompositeInstruction local_qrt.h(q[0]); local_qrt.cnot(q[0], q[1]); for (auto qi : q) local_qrt.mz(qi); // Submit the CompositeInstruction (just like with xacc) local_qrt.submit(q.results()); // Print the results for (auto [bit, count] : q.counts()) { print(bit, ":", count); } } // Now switch to the FTQC runtime mode // must initialize with a name for the CompositeInstruction qrt_impl = xacc::getService<QuantumRuntime>("ftqc"); qrt_impl->initialize("ftqc_test"); { // FTQC Mode Execution // Allocate the qubits auto q = qalloc(2); // Get local reference to the global qrt_impl pointer // For FTQC, we have to provide the AcceleratorBuffer QuantumRuntime& local_qrt = *qrt_impl.get(); local_qrt.set_current_buffer(q.results()); // Loop over sequential application of the // gate instructions, get measurement feedback, and // reset the state of the qubits. for (int i = 0; i < 20; i++) { local_qrt.h(q.head()); local_qrt.cnot(q.head(), q.tail()); auto r0 = local_qrt.mz(q[0]); auto r1 = local_qrt.mz(q[1]); if (r0 == r1) { print(i, "matched!"); } else { print(i, "error!"); } local_qrt.reset(q[0]); local_qrt.reset(q[1]); } } } No newline at end of file tools/driver/qcor.in +1 −1 Original line number Diff line number Diff line Loading @@ -264,7 +264,7 @@ def main(argv=None): if '@CMAKE_SYSTEM_NAME@' != 'Darwin': baseLibs += ['-lqir-qrt'] baseIncludes = ['-I', '@XACC_ROOT@/include/xacc', '-I', '@CMAKE_INSTALL_PREFIX@/include/qcor', baseIncludes = ['-I', '@XACC_ROOT@/include/xacc', '-I', '@XACC_ROOT@/include/cppmicroservices4', '-I', '@CMAKE_INSTALL_PREFIX@/include/qcor', '-I', '@XACC_ROOT@/include/quantum/gate', '-I', '@XACC_ROOT@/include/eigen'] if '-internal-no-pch' in sys.argv[1:]: if verbose: Loading Loading
examples/qcor_demos/ibm_qasm3_demo_092021/qcor-qrt/qrt_demo.cpp 0 → 100644 +72 −0 Original line number Diff line number Diff line #include "qcor.hpp" #include "xacc_service.hpp" // qcor qrt_demo.cpp // ./a.out // qcor qrt_demo.cpp -qpu aer:ibmq_jakarta // ./a.out using namespace quantum; int main() { // Hard code the shots for NISQ to 100 qcor::set_shots(100); { // NISQ Mode Execution // Allocate some qubits auto q = qalloc(2); // Get local reference to global qrt_impl pointer QuantumRuntime& local_qrt = *qrt_impl.get(); // Call the quantum gate instructions on the runtime // for NISQ mode, this will build up a CompositeInstruction local_qrt.h(q[0]); local_qrt.cnot(q[0], q[1]); for (auto qi : q) local_qrt.mz(qi); // Submit the CompositeInstruction (just like with xacc) local_qrt.submit(q.results()); // Print the results for (auto [bit, count] : q.counts()) { print(bit, ":", count); } } // Now switch to the FTQC runtime mode // must initialize with a name for the CompositeInstruction qrt_impl = xacc::getService<QuantumRuntime>("ftqc"); qrt_impl->initialize("ftqc_test"); { // FTQC Mode Execution // Allocate the qubits auto q = qalloc(2); // Get local reference to the global qrt_impl pointer // For FTQC, we have to provide the AcceleratorBuffer QuantumRuntime& local_qrt = *qrt_impl.get(); local_qrt.set_current_buffer(q.results()); // Loop over sequential application of the // gate instructions, get measurement feedback, and // reset the state of the qubits. for (int i = 0; i < 20; i++) { local_qrt.h(q.head()); local_qrt.cnot(q.head(), q.tail()); auto r0 = local_qrt.mz(q[0]); auto r1 = local_qrt.mz(q[1]); if (r0 == r1) { print(i, "matched!"); } else { print(i, "error!"); } local_qrt.reset(q[0]); local_qrt.reset(q[1]); } } } No newline at end of file
tools/driver/qcor.in +1 −1 Original line number Diff line number Diff line Loading @@ -264,7 +264,7 @@ def main(argv=None): if '@CMAKE_SYSTEM_NAME@' != 'Darwin': baseLibs += ['-lqir-qrt'] baseIncludes = ['-I', '@XACC_ROOT@/include/xacc', '-I', '@CMAKE_INSTALL_PREFIX@/include/qcor', baseIncludes = ['-I', '@XACC_ROOT@/include/xacc', '-I', '@XACC_ROOT@/include/cppmicroservices4', '-I', '@CMAKE_INSTALL_PREFIX@/include/qcor', '-I', '@XACC_ROOT@/include/quantum/gate', '-I', '@XACC_ROOT@/include/eigen'] if '-internal-no-pch' in sys.argv[1:]: if verbose: Loading