Loading examples/ftqc_qrt/simple-demo.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #include <qalloc> // Compile with: qcor -qpu qpp -qrt ftqc simple-demo.cpp // Execute: ./a.out // We should get the print out conditioned by the measurement. // If not using the "ftqc" QRT, this will cause errors since the Measure results // are not available yet. __qpu__ void bell(qreg q) { using qcor::xasm; H(q[0]); CX(q[0], q[1]); for (int i = 0; i < 2; i++) X(q[i]); Measure(q[0]); if (q.cReg(0)) { std::cout << "Q0 = 1 !\n"; } Measure(q[1]); if (q.cReg(1)) { std::cout << "Q1 = 1 !\n"; } } int main() { qcor::set_verbose(true); auto q = qalloc(2); bell(q); } runtime/kernel/quantum_kernel.hpp +7 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ #include "qrt.hpp" namespace qcor { enum class QrtType { NISQ, FTQC }; // The QuantumKernel represents the super-class of all qcor // quantum kernel functors. Subclasses of this are auto-generated Loading Loading @@ -50,10 +51,11 @@ public: // Flag to indicate we only want to // run the pass manager and not execute bool optimize_only = false; enum class QrtType { NISQ, FTQC }; QrtType runtime_env = QrtType::NISQ; // Default constructor, takes quantum kernel function arguments QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) {} QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) { runtime_env = (__qrt_env == "ftqc") ? QrtType::FTQC : QrtType::NISQ; } // Internal constructor, provide parent kernel, this // kernel now represents a nested kernel call and Loading @@ -61,7 +63,9 @@ public: QuantumKernel(std::shared_ptr<qcor::CompositeInstruction> _parent_kernel, Args... args) : args_tuple(std::forward_as_tuple(args...)), parent_kernel(_parent_kernel), is_callable(false) {} parent_kernel(_parent_kernel), is_callable(false) { runtime_env = (__qrt_env == "ftqc") ? QrtType::FTQC : QrtType::NISQ; } // Static method for printing this kernel as a flat qasm string static void print_kernel(std::ostream &os, Args... args) { Loading runtime/qcor.hpp +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ namespace __internal__ { class internal_startup { public: internal_startup() { // IMPORTANT: This needs to be set before quantum::initialize #ifdef __internal__qcor__compile__qrt__mode xacc::internal_compiler::__qrt_env = __internal__qcor__compile__qrt__mode; #endif #ifdef __internal__qcor__compile__backend quantum::initialize(__internal__qcor__compile__backend, "empty"); #endif Loading runtime/qrt/impls/ftqc/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ # Contributors: # Alexander J. McCaskey - initial API and implementation # *******************************************************************************/ set(LIBRARY_NAME qcor-nisq-ftqc) set(LIBRARY_NAME qcor-ftqc-qrt) file(GLOB SRC *.cpp) Loading runtime/qrt/impls/ftqc/ftqc_qrt.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,8 @@ public: } // Measure-Z virtual void mz(const qubit &qidx) override { /* TODO */ virtual void mz(const qubit &qidx) override { applyGate("Measure", {qidx.second}); } // Common two-qubit gates. Loading Loading
examples/ftqc_qrt/simple-demo.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #include <qalloc> // Compile with: qcor -qpu qpp -qrt ftqc simple-demo.cpp // Execute: ./a.out // We should get the print out conditioned by the measurement. // If not using the "ftqc" QRT, this will cause errors since the Measure results // are not available yet. __qpu__ void bell(qreg q) { using qcor::xasm; H(q[0]); CX(q[0], q[1]); for (int i = 0; i < 2; i++) X(q[i]); Measure(q[0]); if (q.cReg(0)) { std::cout << "Q0 = 1 !\n"; } Measure(q[1]); if (q.cReg(1)) { std::cout << "Q1 = 1 !\n"; } } int main() { qcor::set_verbose(true); auto q = qalloc(2); bell(q); }
runtime/kernel/quantum_kernel.hpp +7 −3 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ #include "qrt.hpp" namespace qcor { enum class QrtType { NISQ, FTQC }; // The QuantumKernel represents the super-class of all qcor // quantum kernel functors. Subclasses of this are auto-generated Loading Loading @@ -50,10 +51,11 @@ public: // Flag to indicate we only want to // run the pass manager and not execute bool optimize_only = false; enum class QrtType { NISQ, FTQC }; QrtType runtime_env = QrtType::NISQ; // Default constructor, takes quantum kernel function arguments QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) {} QuantumKernel(Args... args) : args_tuple(std::forward_as_tuple(args...)) { runtime_env = (__qrt_env == "ftqc") ? QrtType::FTQC : QrtType::NISQ; } // Internal constructor, provide parent kernel, this // kernel now represents a nested kernel call and Loading @@ -61,7 +63,9 @@ public: QuantumKernel(std::shared_ptr<qcor::CompositeInstruction> _parent_kernel, Args... args) : args_tuple(std::forward_as_tuple(args...)), parent_kernel(_parent_kernel), is_callable(false) {} parent_kernel(_parent_kernel), is_callable(false) { runtime_env = (__qrt_env == "ftqc") ? QrtType::FTQC : QrtType::NISQ; } // Static method for printing this kernel as a flat qasm string static void print_kernel(std::ostream &os, Args... args) { Loading
runtime/qcor.hpp +4 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,10 @@ namespace __internal__ { class internal_startup { public: internal_startup() { // IMPORTANT: This needs to be set before quantum::initialize #ifdef __internal__qcor__compile__qrt__mode xacc::internal_compiler::__qrt_env = __internal__qcor__compile__qrt__mode; #endif #ifdef __internal__qcor__compile__backend quantum::initialize(__internal__qcor__compile__backend, "empty"); #endif Loading
runtime/qrt/impls/ftqc/CMakeLists.txt +1 −1 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ # Contributors: # Alexander J. McCaskey - initial API and implementation # *******************************************************************************/ set(LIBRARY_NAME qcor-nisq-ftqc) set(LIBRARY_NAME qcor-ftqc-qrt) file(GLOB SRC *.cpp) Loading
runtime/qrt/impls/ftqc/ftqc_qrt.cpp +2 −1 Original line number Diff line number Diff line Loading @@ -56,7 +56,8 @@ public: } // Measure-Z virtual void mz(const qubit &qidx) override { /* TODO */ virtual void mz(const qubit &qidx) override { applyGate("Measure", {qidx.second}); } // Common two-qubit gates. Loading