Loading examples/ftqc_qrt/run-with-shots.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #include <qalloc> // Compile with: qcor -qpu qpp -qrt ftqc -shots 1024 run-with-shots.cpp // Define sub-kernel to print out FTQC execution __qpu__ void h_gate(qreg q) { std::cout << "Run H\n"; H(q[0]); } __qpu__ void cx_gate(qreg q) { std::cout << "Run CNOT\n"; CX(q[0], q[1]); } __qpu__ void bell(qreg q) { using qcor::xasm; h_gate(q); cx_gate(q); const bool q0Result = Measure(q[0]); const bool q1Result = Measure(q[1]); if (q0Result == q1Result) { std::cout << " Matched!\n"; } else { std::cout << "NOT Matched!\n"; } } int main() { auto q = qalloc(2); bell(q); q.print(); } handlers/qcor_syntax_handler.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -215,6 +215,19 @@ void QCORSyntaxHandler::GetReplacement( OS << ");\n"; // If this is a FTQC kernel, skip runtime optimization passes and submit. OS << "if (runtime_env == QrtType::FTQC) {\n"; OS << "if (is_callable) {\n"; // If this is the top-level kernel, during DTor we persit the bit value to Buffer. OS << "quantum::persistBitstring(" << bufferNames[0] << ".results());\n"; // Loop the function calls (at the top level only) if there are multiple shots requested. OS << "for (size_t shotCount = 1; shotCount < quantum::get_shots(); ++shotCount) {\n"; OS << "operator()(" << program_parameters[0]; for (int i = 1; i < program_parameters.size(); i++) { OS << ", " << program_parameters[i]; } OS << ");\n"; OS << "quantum::persistBitstring(" << bufferNames[0] << ".results());\n"; OS << "}\n"; OS << "}\n"; OS << "return;\n"; OS << "}\n"; Loading runtime/qrt/qrt.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -184,4 +184,10 @@ void set_current_buffer(xacc::AcceleratorBuffer* buffer) { qrt_impl->set_current_buffer(buffer); } void persistBitstring(xacc::AcceleratorBuffer *buffer) { const auto bitstring = buffer->single_measurements_to_bitstring(); if (!bitstring.empty()) { buffer->appendMeasurement(bitstring); } } } // namespace quantum No newline at end of file runtime/qrt/qrt.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,8 @@ void set_current_buffer(xacc::AcceleratorBuffer* buffer); // // Clear the current program // void clearProgram(); // Persist bit-string result from single-bit measurements (if any) void persistBitstring(xacc::AcceleratorBuffer *buffer); } // namespace quantum namespace xacc { Loading Loading
examples/ftqc_qrt/run-with-shots.cpp 0 → 100644 +31 −0 Original line number Diff line number Diff line #include <qalloc> // Compile with: qcor -qpu qpp -qrt ftqc -shots 1024 run-with-shots.cpp // Define sub-kernel to print out FTQC execution __qpu__ void h_gate(qreg q) { std::cout << "Run H\n"; H(q[0]); } __qpu__ void cx_gate(qreg q) { std::cout << "Run CNOT\n"; CX(q[0], q[1]); } __qpu__ void bell(qreg q) { using qcor::xasm; h_gate(q); cx_gate(q); const bool q0Result = Measure(q[0]); const bool q1Result = Measure(q[1]); if (q0Result == q1Result) { std::cout << " Matched!\n"; } else { std::cout << "NOT Matched!\n"; } } int main() { auto q = qalloc(2); bell(q); q.print(); }
handlers/qcor_syntax_handler.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -215,6 +215,19 @@ void QCORSyntaxHandler::GetReplacement( OS << ");\n"; // If this is a FTQC kernel, skip runtime optimization passes and submit. OS << "if (runtime_env == QrtType::FTQC) {\n"; OS << "if (is_callable) {\n"; // If this is the top-level kernel, during DTor we persit the bit value to Buffer. OS << "quantum::persistBitstring(" << bufferNames[0] << ".results());\n"; // Loop the function calls (at the top level only) if there are multiple shots requested. OS << "for (size_t shotCount = 1; shotCount < quantum::get_shots(); ++shotCount) {\n"; OS << "operator()(" << program_parameters[0]; for (int i = 1; i < program_parameters.size(); i++) { OS << ", " << program_parameters[i]; } OS << ");\n"; OS << "quantum::persistBitstring(" << bufferNames[0] << ".results());\n"; OS << "}\n"; OS << "}\n"; OS << "return;\n"; OS << "}\n"; Loading
runtime/qrt/qrt.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -184,4 +184,10 @@ void set_current_buffer(xacc::AcceleratorBuffer* buffer) { qrt_impl->set_current_buffer(buffer); } void persistBitstring(xacc::AcceleratorBuffer *buffer) { const auto bitstring = buffer->single_measurements_to_bitstring(); if (!bitstring.empty()) { buffer->appendMeasurement(bitstring); } } } // namespace quantum No newline at end of file
runtime/qrt/qrt.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -153,6 +153,8 @@ void set_current_buffer(xacc::AcceleratorBuffer* buffer); // // Clear the current program // void clearProgram(); // Persist bit-string result from single-bit measurements (if any) void persistBitstring(xacc::AcceleratorBuffer *buffer); } // namespace quantum namespace xacc { Loading