-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/decompose boxes in routing (#197)
* Reject boxes in Architecture::valid_operation * Add `next_q_cut` method to a quantum cut Only consider quantum edges * Use `next_q_cut` in `advance_frontier_boundary` * Add BoxDecompositionRoutingMethod * Add tests * Reformat * Reject boxes in LexiRouteMethod::check_method * Update tests * Add JSON serialisation * Handle unused arguments * Refactor Circuit::decompose_boxes * fix naming Co-authored-by: sjdilkes <[email protected]>
- Loading branch information
Showing
21 changed files
with
452 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "Mapping/BoxDecomposition.hpp" | ||
|
||
#include "Mapping/MappingFrontier.hpp" | ||
|
||
namespace tket { | ||
|
||
BoxDecomposition::BoxDecomposition( | ||
const ArchitecturePtr &_architecture, | ||
std::shared_ptr<MappingFrontier> &_mapping_frontier) | ||
: architecture_(_architecture), mapping_frontier_(_mapping_frontier) {} | ||
|
||
void BoxDecomposition::solve() { | ||
// Box type vertices are later removed from DAG | ||
VertexList bin; | ||
|
||
std::shared_ptr<unit_frontier_t> frontier_edges = | ||
frontier_convert_vertport_to_edge( | ||
this->mapping_frontier_->circuit_, | ||
this->mapping_frontier_->quantum_boundary); | ||
CutFrontier next_cut = | ||
this->mapping_frontier_->circuit_.next_q_cut(frontier_edges); | ||
for (Vertex &vert : *next_cut.slice) { | ||
if (this->mapping_frontier_->circuit_.substitute_box_vertex( | ||
vert, Circuit::VertexDeletion::No)) | ||
bin.push_back(vert); | ||
} | ||
|
||
// Delete vertices | ||
this->mapping_frontier_->circuit_.remove_vertices( | ||
bin, Circuit::GraphRewiring::No, Circuit::VertexDeletion::Yes); | ||
} | ||
|
||
BoxDecompositionRoutingMethod::BoxDecompositionRoutingMethod(){}; | ||
|
||
bool BoxDecompositionRoutingMethod::check_method( | ||
const std::shared_ptr<MappingFrontier> &mapping_frontier, | ||
const ArchitecturePtr & /*architecture*/) const { | ||
std::shared_ptr<unit_frontier_t> frontier_edges = | ||
frontier_convert_vertport_to_edge( | ||
mapping_frontier->circuit_, mapping_frontier->quantum_boundary); | ||
CutFrontier next_cut = mapping_frontier->circuit_.next_q_cut(frontier_edges); | ||
for (const Vertex &vert : *next_cut.slice) { | ||
Op_ptr op = mapping_frontier->circuit_.get_Op_ptr_from_Vertex(vert); | ||
if (op->get_desc().is_box() || | ||
(op->get_type() == OpType::Conditional && | ||
static_cast<const Conditional &>(*op).get_op()->get_desc().is_box())) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
unit_map_t BoxDecompositionRoutingMethod::routing_method( | ||
std::shared_ptr<MappingFrontier> &mapping_frontier, | ||
const ArchitecturePtr &architecture) const { | ||
BoxDecomposition bd(architecture, mapping_frontier); | ||
bd.solve(); | ||
return {}; | ||
} | ||
|
||
nlohmann::json BoxDecompositionRoutingMethod::serialize() const { | ||
nlohmann::json j; | ||
j["name"] = "BoxDecompositionRoutingMethod"; | ||
return j; | ||
} | ||
|
||
BoxDecompositionRoutingMethod BoxDecompositionRoutingMethod::deserialize( | ||
const nlohmann::json & /*j*/) { | ||
return BoxDecompositionRoutingMethod(); | ||
} | ||
|
||
} // namespace tket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef _TKET_BoxDecomposition_H_ | ||
#define _TKET_BoxDecomposition_H_ | ||
|
||
#include "Mapping/MappingFrontier.hpp" | ||
#include "Mapping/RoutingMethod.hpp" | ||
|
||
namespace tket { | ||
|
||
class BoxDecomposition { | ||
public: | ||
/** | ||
* Class Constructor | ||
* @param _architecture Architecture object added operations must respect | ||
* @param _mapping_frontier Contains Circuit object to be modified | ||
*/ | ||
BoxDecomposition( | ||
const ArchitecturePtr& _architecture, | ||
std::shared_ptr<MappingFrontier>& _mapping_frontier); | ||
|
||
/** | ||
* Decompose any boxes in the next slice after the frontier | ||
*/ | ||
void solve(); | ||
|
||
private: | ||
// Architecture all new physical operations must respect | ||
ArchitecturePtr architecture_; | ||
std::shared_ptr<MappingFrontier> mapping_frontier_; | ||
}; | ||
|
||
class BoxDecompositionRoutingMethod : public RoutingMethod { | ||
public: | ||
/** | ||
* Decompose any boxes on the frontier | ||
*/ | ||
BoxDecompositionRoutingMethod(); | ||
|
||
/** | ||
* @return true if method can route subcircuit, false if not | ||
*/ | ||
bool check_method( | ||
const std::shared_ptr<MappingFrontier>& mapping_frontier, | ||
const ArchitecturePtr& /*architecture*/) const override; | ||
|
||
/** | ||
* @param mapping_frontier Contains boundary of routed/unrouted circuit for | ||
* modifying | ||
* @param architecture Architecture providing physical constraints | ||
* @return Logical to Physical mapping at boundary due to modification. | ||
* | ||
*/ | ||
unit_map_t routing_method( | ||
std::shared_ptr<MappingFrontier>& mapping_frontier, | ||
const ArchitecturePtr& architecture) const override; | ||
|
||
nlohmann::json serialize() const override; | ||
|
||
static BoxDecompositionRoutingMethod deserialize(const nlohmann::json& /*j*/); | ||
}; | ||
|
||
} // namespace tket | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.