Loading runtime/qcor.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,9 @@ public: #endif #ifdef __internal__qcor__compile__opt__print__stats xacc::internal_compiler::__print_opt_stats = true; #endif #ifdef __internal__qcor__compile__opt__passes xacc::internal_compiler::__user_opt_passes = __internal__qcor__compile__opt__passes; #endif } }; Loading runtime/qrt/pass_manager.cpp +27 −16 Original line number Diff line number Diff line Loading @@ -43,6 +43,32 @@ namespace qcor { namespace internal { PassManager::PassManager(int level) : m_level(level) {} PassStat PassManager::runPass(const std::string &passName, std::shared_ptr<xacc::CompositeInstruction> program) { PassStat stat; stat.passName = passName; // Counts gate before: stat.gateCountBefore = PassStat::countGates(program); xacc::ScopeTimer timer(passName, false); if (!xacc::hasService<xacc::IRTransformation>(passName) && !xacc::hasContributedService<xacc::IRTransformation>(passName)) { // Graciously ignores passes which cannot be located. // Returns empty stats return stat; } auto xaccOptTransform = xacc::getIRTransformation(passName); if (xaccOptTransform) { xaccOptTransform->apply(program, nullptr); } // Stores the elapsed time. stat.wallTimeMs = timer.getDurationMs(); // Counts gate after: stat.gateCountAfter = PassStat::countGates(program); return stat; } std::vector<PassStat> PassManager::optimize( std::shared_ptr<xacc::CompositeInstruction> program) const { std::vector<PassStat> passData; Loading @@ -59,22 +85,7 @@ std::vector<PassStat> PassManager::optimize( }(); for (const auto &passName : passesToRun) { PassStat stat; stat.passName = passName; // Counts gate before: stat.gateCountBefore = PassStat::countGates(program); xacc::ScopeTimer timer(passName, false); auto xaccOptTransform = xacc::getIRTransformation(passName); // Graciously ignores passes which cannot be located. if (xaccOptTransform) { xaccOptTransform->apply(program, nullptr); } // Stores the elapsed time. stat.wallTimeMs = timer.getDurationMs(); // Counts gate after: stat.gateCountAfter = PassStat::countGates(program); passData.emplace_back(std::move(stat)); passData.emplace_back(runPass(passName, program)); } return passData; Loading runtime/qrt/pass_manager.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ struct PassStat { class PassManager { public: PassManager(int level); // Static helper to run an optimization pass static PassStat runPass(const std::string &passName, std::shared_ptr<xacc::CompositeInstruction> program); // Optimizes the input program. // Returns the full statistics about all the passes that have been executed. std::vector<PassStat> Loading runtime/qrt/qrt.cpp +19 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ namespace internal_compiler { int __opt_level = 0; bool __print_opt_stats = false; std::vector<int> __controlledIdx = {}; std::string __user_opt_passes = ""; void simplified_qrt_call_one_qbit(const char *gate_name, const char *buffer_name, Loading @@ -39,7 +40,24 @@ void simplified_qrt_call_two_qbits(const char *gate_name, void execute_pass_manager() { qcor::internal::PassManager passManager(__opt_level); const auto optData = passManager.optimize(::quantum::program); auto optData = passManager.optimize(::quantum::program); std::vector<std::string> user_passes; if (!__user_opt_passes.empty()) { std::stringstream ss(__user_opt_passes); // Parses list of passes while (ss.good()) { std::string passName; std::getline(ss, passName, ','); user_passes.emplace_back(passName); } } // Runs user-specified passes for (const auto& user_pass: user_passes) { optData.emplace_back(qcor::internal::PassManager::runPass(user_pass, ::quantum::program)); } if (__print_opt_stats) { // Prints out the Optimizer Stats if requested. for (const auto &passData : optData) { Loading runtime/qrt/qrt.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,9 @@ extern int __opt_level; // Disabled by default. Enabled by qcor CLI option. extern bool __print_opt_stats; // User-customized passes to run extern std::string __user_opt_passes; void simplified_qrt_call_one_qbit(const char *gate_name, const char *buffer_name, const std::size_t idx); Loading Loading
runtime/qcor.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,9 @@ public: #endif #ifdef __internal__qcor__compile__opt__print__stats xacc::internal_compiler::__print_opt_stats = true; #endif #ifdef __internal__qcor__compile__opt__passes xacc::internal_compiler::__user_opt_passes = __internal__qcor__compile__opt__passes; #endif } }; Loading
runtime/qrt/pass_manager.cpp +27 −16 Original line number Diff line number Diff line Loading @@ -43,6 +43,32 @@ namespace qcor { namespace internal { PassManager::PassManager(int level) : m_level(level) {} PassStat PassManager::runPass(const std::string &passName, std::shared_ptr<xacc::CompositeInstruction> program) { PassStat stat; stat.passName = passName; // Counts gate before: stat.gateCountBefore = PassStat::countGates(program); xacc::ScopeTimer timer(passName, false); if (!xacc::hasService<xacc::IRTransformation>(passName) && !xacc::hasContributedService<xacc::IRTransformation>(passName)) { // Graciously ignores passes which cannot be located. // Returns empty stats return stat; } auto xaccOptTransform = xacc::getIRTransformation(passName); if (xaccOptTransform) { xaccOptTransform->apply(program, nullptr); } // Stores the elapsed time. stat.wallTimeMs = timer.getDurationMs(); // Counts gate after: stat.gateCountAfter = PassStat::countGates(program); return stat; } std::vector<PassStat> PassManager::optimize( std::shared_ptr<xacc::CompositeInstruction> program) const { std::vector<PassStat> passData; Loading @@ -59,22 +85,7 @@ std::vector<PassStat> PassManager::optimize( }(); for (const auto &passName : passesToRun) { PassStat stat; stat.passName = passName; // Counts gate before: stat.gateCountBefore = PassStat::countGates(program); xacc::ScopeTimer timer(passName, false); auto xaccOptTransform = xacc::getIRTransformation(passName); // Graciously ignores passes which cannot be located. if (xaccOptTransform) { xaccOptTransform->apply(program, nullptr); } // Stores the elapsed time. stat.wallTimeMs = timer.getDurationMs(); // Counts gate after: stat.gateCountAfter = PassStat::countGates(program); passData.emplace_back(std::move(stat)); passData.emplace_back(runPass(passName, program)); } return passData; Loading
runtime/qrt/pass_manager.hpp +2 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ struct PassStat { class PassManager { public: PassManager(int level); // Static helper to run an optimization pass static PassStat runPass(const std::string &passName, std::shared_ptr<xacc::CompositeInstruction> program); // Optimizes the input program. // Returns the full statistics about all the passes that have been executed. std::vector<PassStat> Loading
runtime/qrt/qrt.cpp +19 −1 Original line number Diff line number Diff line Loading @@ -14,6 +14,7 @@ namespace internal_compiler { int __opt_level = 0; bool __print_opt_stats = false; std::vector<int> __controlledIdx = {}; std::string __user_opt_passes = ""; void simplified_qrt_call_one_qbit(const char *gate_name, const char *buffer_name, Loading @@ -39,7 +40,24 @@ void simplified_qrt_call_two_qbits(const char *gate_name, void execute_pass_manager() { qcor::internal::PassManager passManager(__opt_level); const auto optData = passManager.optimize(::quantum::program); auto optData = passManager.optimize(::quantum::program); std::vector<std::string> user_passes; if (!__user_opt_passes.empty()) { std::stringstream ss(__user_opt_passes); // Parses list of passes while (ss.good()) { std::string passName; std::getline(ss, passName, ','); user_passes.emplace_back(passName); } } // Runs user-specified passes for (const auto& user_pass: user_passes) { optData.emplace_back(qcor::internal::PassManager::runPass(user_pass, ::quantum::program)); } if (__print_opt_stats) { // Prints out the Optimizer Stats if requested. for (const auto &passData : optData) { Loading
runtime/qrt/qrt.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -121,6 +121,9 @@ extern int __opt_level; // Disabled by default. Enabled by qcor CLI option. extern bool __print_opt_stats; // User-customized passes to run extern std::string __user_opt_passes; void simplified_qrt_call_one_qbit(const char *gate_name, const char *buffer_name, const std::size_t idx); Loading