Commit 7730c48b authored by Nguyen, Thien Minh's avatar Nguyen, Thien Minh
Browse files

First pass of adding placement



Signed-off-by: default avatarThien Nguyen <nguyentm@ornl.gov>
parent 76f8d090
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
#include "InstructionIterator.hpp"
#include "xacc.hpp"
#include "xacc_service.hpp"
#include "xacc_internal_compiler.hpp"
#include <iomanip>
#include <numeric>
namespace {
@@ -91,6 +92,23 @@ std::vector<PassStat> PassManager::optimize(
  return passData;
}

void PassManager::applyPlacement(std::shared_ptr<xacc::CompositeInstruction> program, const std::string &placementName) {
  if (!xacc::hasService<xacc::IRTransformation>(placementName)
      && !xacc::hasContributedService<xacc::IRTransformation>(placementName)) {
    // Graciously ignores services which cannot be located.
    return;
  }

  auto irt = xacc::getIRTransformation(placementName);
  if (irt->type() == xacc::IRTransformationType::Placement &&
    xacc::internal_compiler::qpu &&
    !xacc::internal_compiler::qpu->getConnectivity().empty()) {
    irt->apply(program, xacc::internal_compiler::qpu);
  }
  // DEBUG:
  std::cout << "HOWDY:\n" << program->toString() << "\n";
}

std::unordered_map<std::string, int> PassStat::countGates(
    const std::shared_ptr<xacc::CompositeInstruction> &program) {
  std::unordered_map<std::string, int> gateCount;
+5 −0
Original line number Diff line number Diff line
@@ -29,6 +29,11 @@ public:
  PassManager(int level);
  // Static helper to run an optimization pass
  static PassStat runPass(const std::string &passName, std::shared_ptr<xacc::CompositeInstruction> program);
  // Default placement strategy
  static constexpr const char *DEFAULT_PLACEMENT = "swap-shortest-path";
  // Apply placement
  static void applyPlacement(std::shared_ptr<xacc::CompositeInstruction> program, const std::string &placementName = DEFAULT_PLACEMENT);

  // Optimizes the input program.
  // Returns the full statistics about all the passes that have been executed.
  std::vector<PassStat>
+3 −0
Original line number Diff line number Diff line
@@ -64,6 +64,9 @@ void execute_pass_manager() {
      std::cout << passData.toString(false);
    }
  }
  // Apply placement:
  // TODO: add option to change the placement strategy.
  qcor::internal::PassManager::applyPlacement(::quantum::program);
}