Skip to content

Commit

Permalink
add QMDLA config in placer
Browse files Browse the repository at this point in the history
  • Loading branch information
Enfest committed Feb 4, 2025
1 parent e2c23d0 commit fcb3d2b
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/cmd/duostra_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ DuostraConfig DUOSTRA_CONFIG{
// SECTION - Global settings for Duostra mapper
.scheduler_type = SchedulerType::search,
.router_type = RouterType::duostra,
.placer_type = PlacerType::dfs,
.placer_type = PlacerType::qmdla,
.tie_breaking_strategy = MinMaxOptionType::min,
.algorithm_type = AlgorithmType::subcircuit,

Expand Down Expand Up @@ -62,8 +62,8 @@ duostra_config_cmd() {
.choices({"shortest_path", "duostra"})
.help("<shortest_path | duostra>");
parser.add_argument<std::string>("--placer")
.choices({"naive", "random", "dfs"})
.help("<naive | random | dfs>");
.choices({"naive", "random", "dfs", "qmdla"})
.help("<naive | random | dfs | QMDLA>");
parser.add_argument<std::string>("--algorithm")
.choices({"duostra", "subcircuit"})
.help("<duostra | subcircuit>");
Expand Down Expand Up @@ -270,7 +270,7 @@ Command duostra_cmd(qcir::QCirMgr& qcir_mgr, device::DeviceMgr& device_mgr) {
// #endif
qcir::QCir* logical_qcir = qcir_mgr.get();
if (DUOSTRA_CONFIG.algorithm_type == AlgorithmType::subcircuit) {
LayoutCirMgr layout_cir_mgr{logical_qcir, *device_mgr.get()};
LayoutCirMgr layout_cir_mgr{logical_qcir, *device_mgr.get(), DUOSTRA_CONFIG};
// spdlog::error("Duostra is not available for subcircuit");
// return CmdExecResult::error;
}
Expand Down
3 changes: 3 additions & 0 deletions src/duostra/duostra_def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ std::string get_placer_type_str(PlacerType const& type) {
return "naive";
case PlacerType::random:
return "random";
case PlacerType::qmdla:
return "QMDLA";
case PlacerType::dfs:
default:
return "dfs";
Expand Down Expand Up @@ -134,6 +136,7 @@ std::optional<PlacerType> get_placer_type(std::string const& str) {
if (str == "naive") return PlacerType::naive;
if (str == "random") return PlacerType::random;
if (str == "dfs") return PlacerType::dfs;
if (str == "qmdla" || str == "QMDLA") return PlacerType::qmdla;

return std::nullopt;
}
Expand Down
1 change: 1 addition & 0 deletions src/duostra/duostra_def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ enum class PlacerType : std::uint8_t {
naive,
random,
dfs,
qmdla
};

enum class RouterType : std::uint8_t {
Expand Down
27 changes: 27 additions & 0 deletions src/duostra/layoutcir_mgr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "layoutcir_mgr.hpp"
#include <fmt/core.h>
#include <cstddef>
#include "placer.hpp"

namespace qsyn::duostra {

bool LayoutCirMgr::map() {
fmt::println("start mapping layout circuit");

fmt::println("Initial Placement...");

std::vector<QubitIdType> assign;
spdlog::info("Calculating Initial Placement...");
auto placer = get_placer(_config.placer_type);
assign = placer->place_and_assign(_device);

size_t gate_idx = 0;

while (true){


}
return true;
};

} // namespace qsyn::duostra
11 changes: 8 additions & 3 deletions src/duostra/layoutcir_mgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ class LayoutCirMgr: public dvlab::utils::DataStructureManager<LayoutCir>{

LayoutCirMgr(
qcir::QCir* qcir,
Device dev)
Device dev,
DuostraConfig const& config)
// DuostraConfig const& config)
: dvlab::utils::DataStructureManager<LayoutCir>("LayoutCirMgr"),
_device(std::move(dev)),
// _config{config},
_logical_circuit{std::make_shared<qcir::QCir>(*qcir)} { fmt::println("create layout circuit mgr"); };
_logical_circuit(std::make_shared<qcir::QCir>(*qcir)),
_config(config) { fmt::println("create layout circuit mgr"); };

bool map();


private:

Expand All @@ -55,6 +59,7 @@ class LayoutCirMgr: public dvlab::utils::DataStructureManager<LayoutCir>{
// std::unique_ptr<BaseScheduler> _scheduler;
std::shared_ptr<qcir::QCir> _logical_circuit;
std::vector<qcir::QCirGate> _result;
DuostraConfig _config;


};
Expand Down
17 changes: 17 additions & 0 deletions src/duostra/placer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ std::unique_ptr<BasePlacer> get_placer(PlacerType type) {
return std::make_unique<RandomPlacer>();
case PlacerType::dfs:
return std::make_unique<DFSPlacer>();
case PlacerType::qmdla:
return std::make_unique<QMDLAPlacer>();
break;
}
return nullptr;
}
Expand Down Expand Up @@ -137,4 +140,18 @@ void DFSPlacer::_dfs_device(QubitIdType current, Device& device, std::vector<Qub
}
}

/**
* @brief Place logical qubit
*
* @param device
* @return vector<size_t>
*/
std::vector<QubitIdType> QMDLAPlacer::_place(Device& device) const {
std::vector<QubitIdType> assign;
// TODO

return assign;
}


} // namespace qsyn::duostra
9 changes: 9 additions & 0 deletions src/duostra/placer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@ class DFSPlacer : public BasePlacer {

std::unique_ptr<BasePlacer> get_placer(PlacerType type);

class QMDLAPlacer : public BasePlacer {
public:
using Device = BasePlacer::Device;

protected:
std::vector<QubitIdType> _place(Device& /*unused*/) const override;
};


} // namespace qsyn::duostra

0 comments on commit fcb3d2b

Please sign in to comment.