Loading benchmarks/openqasm3/compute_action/bench.qasm 0 → 100644 +49 −0 Original line number Diff line number Diff line OPENQASM 3; const nb_qubits = 5; def oracle() qubit[nb_qubits]:r { int nb_steps = 100; double step_size = .01; double Jz = 1.0; double h = 1.0; // -h*sigma_x layers for step in [0:nb_steps] { // -h*sigma_x layers rx(-h * step_size) r; // -Jz*sigma_z*sigma_z layers for i in [0:nb_qubits - 1] { cx r[i], r[i+1]; rz(-Jz * step_size) r[i + 1]; cx r[i], r[i+1]; } } } def oracle_compute_action() qubit[nb_qubits]:r { int nb_steps = 100; double step_size = .01; double Jz = 1.0; double h = 1.0; // -h*sigma_x layers for step in [0:nb_steps] { // -h*sigma_x layers rx (-h * step_size) r; // -Jz*sigma_z*sigma_z layers for i in [0:nb_qubits - 1] { compute { cx r[i], r[i+1]; } action { rz(-Jz * step_size) r[i + 1]; } } } } qubit r[nb_qubits], c; ctrl @ oracle_compute_action c, r; // ctrl @ oracle c, r; benchmarks/openqasm3/compute_action/bench.sh 0 → 100644 +13 −0 Original line number Diff line number Diff line #!/bin/bash # From 6 to 50 qubits, even only, # create the benchmark qasm code, compile it with -O3 # and execute collecting total number of gates # Change 'Total G' to 'Total C' to count total # ctrl opertions for NQUBITS in `seq 6 2 50` do sed "s/nb_qubits =.*/nb_qubits = $NQUBITS;/" bench.qasm > bench$NQUBITS.qasm qcor -O3 bench$NQUBITS.qasm -qrt ftqc -qpu tracer ./a.out | grep 'Total G' | sed 's/.*\: //' done runtime/qrt/impls/ftqc/tracer/ResourcesTracerAccelerator.cpp +21 −2 Original line number Diff line number Diff line #include "ResourcesTracerAccelerator.hpp" #include <iomanip> #include <random> #include "xacc_service.hpp" using namespace xacc; namespace qcor { void TracerAccelerator::initialize(const HeterogeneousMap ¶ms) { Loading Loading @@ -62,8 +64,7 @@ void TracerAccelerator::printResourcesEstimationReport() { // Currently, simply print gate count: std::cout << "Resources Estimation Result:\n"; std::cout << "Number of qubit required: " << qubit_idxs.size() << "\n"; std::cout << "Gate Count Report: \n"; size_t totalNumberGates = 0; size_t totalNumberGates = 0, totalCtrlOperations = 0; std::stringstream stream; const size_t nbColumns = 2; const size_t columnWidth = 8; Loading @@ -81,10 +82,28 @@ void TracerAccelerator::printResourcesEstimationReport() { stream << std::setw(8) << count << " |\n"; }; auto insts = xacc::getServices<xacc::Instruction>(); std::vector<std::string> two_qubit_names; for (auto inst : insts) { if (inst->nRequiredBits() > 1) { two_qubit_names.push_back(inst->name()); } } // Print each row, and count total number of instructions, and // count any 2 qubit control operations. for (const auto &[gateName, count] : gateNameToCount) { printEachRow(gateName, count); totalNumberGates += count; if (xacc::container::contains(two_qubit_names, gateName)) { totalCtrlOperations += count; } } stream << std::string(totalWidth, '-') << "\n"; std::cout << "Total Gates: " << totalNumberGates << "\n"; std::cout << "Total Control Operations: " << totalCtrlOperations << "\n"; std::cout << "Gate Count Report: \n"; std::cout << stream.str(); } } // namespace qcor Loading
benchmarks/openqasm3/compute_action/bench.qasm 0 → 100644 +49 −0 Original line number Diff line number Diff line OPENQASM 3; const nb_qubits = 5; def oracle() qubit[nb_qubits]:r { int nb_steps = 100; double step_size = .01; double Jz = 1.0; double h = 1.0; // -h*sigma_x layers for step in [0:nb_steps] { // -h*sigma_x layers rx(-h * step_size) r; // -Jz*sigma_z*sigma_z layers for i in [0:nb_qubits - 1] { cx r[i], r[i+1]; rz(-Jz * step_size) r[i + 1]; cx r[i], r[i+1]; } } } def oracle_compute_action() qubit[nb_qubits]:r { int nb_steps = 100; double step_size = .01; double Jz = 1.0; double h = 1.0; // -h*sigma_x layers for step in [0:nb_steps] { // -h*sigma_x layers rx (-h * step_size) r; // -Jz*sigma_z*sigma_z layers for i in [0:nb_qubits - 1] { compute { cx r[i], r[i+1]; } action { rz(-Jz * step_size) r[i + 1]; } } } } qubit r[nb_qubits], c; ctrl @ oracle_compute_action c, r; // ctrl @ oracle c, r;
benchmarks/openqasm3/compute_action/bench.sh 0 → 100644 +13 −0 Original line number Diff line number Diff line #!/bin/bash # From 6 to 50 qubits, even only, # create the benchmark qasm code, compile it with -O3 # and execute collecting total number of gates # Change 'Total G' to 'Total C' to count total # ctrl opertions for NQUBITS in `seq 6 2 50` do sed "s/nb_qubits =.*/nb_qubits = $NQUBITS;/" bench.qasm > bench$NQUBITS.qasm qcor -O3 bench$NQUBITS.qasm -qrt ftqc -qpu tracer ./a.out | grep 'Total G' | sed 's/.*\: //' done
runtime/qrt/impls/ftqc/tracer/ResourcesTracerAccelerator.cpp +21 −2 Original line number Diff line number Diff line #include "ResourcesTracerAccelerator.hpp" #include <iomanip> #include <random> #include "xacc_service.hpp" using namespace xacc; namespace qcor { void TracerAccelerator::initialize(const HeterogeneousMap ¶ms) { Loading Loading @@ -62,8 +64,7 @@ void TracerAccelerator::printResourcesEstimationReport() { // Currently, simply print gate count: std::cout << "Resources Estimation Result:\n"; std::cout << "Number of qubit required: " << qubit_idxs.size() << "\n"; std::cout << "Gate Count Report: \n"; size_t totalNumberGates = 0; size_t totalNumberGates = 0, totalCtrlOperations = 0; std::stringstream stream; const size_t nbColumns = 2; const size_t columnWidth = 8; Loading @@ -81,10 +82,28 @@ void TracerAccelerator::printResourcesEstimationReport() { stream << std::setw(8) << count << " |\n"; }; auto insts = xacc::getServices<xacc::Instruction>(); std::vector<std::string> two_qubit_names; for (auto inst : insts) { if (inst->nRequiredBits() > 1) { two_qubit_names.push_back(inst->name()); } } // Print each row, and count total number of instructions, and // count any 2 qubit control operations. for (const auto &[gateName, count] : gateNameToCount) { printEachRow(gateName, count); totalNumberGates += count; if (xacc::container::contains(two_qubit_names, gateName)) { totalCtrlOperations += count; } } stream << std::string(totalWidth, '-') << "\n"; std::cout << "Total Gates: " << totalNumberGates << "\n"; std::cout << "Total Control Operations: " << totalCtrlOperations << "\n"; std::cout << "Gate Count Report: \n"; std::cout << stream.str(); } } // namespace qcor