Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge RoutingMethod::check_method and RoutingMethod::routing_method #244

Merged
merged 158 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from 157 commits
Commits
Show all changes
158 commits
Select commit Hold shift + click to select a range
3c84f72
Update build_and_test.yml
sjdilkes Oct 22, 2021
39f46d3
Feature/TokenSwapping (#94)
sjdilkes Oct 25, 2021
8ba7968
Add "MappingManager" class and port older routing solution (#95)
sjdilkes Oct 25, 2021
5b50029
Add token swapping stage to routing v3 (#96)
sjdilkes Oct 26, 2021
4c92d8d
Assert candidate swaps size (#108)
yao-cqc Nov 9, 2021
edba555
Merge branch 'develop' into feature/routing-v3
sjdilkes Dec 13, 2021
6592cfd
Update Architecture method names
sjdilkes Dec 13, 2021
b3cda73
get_all_nodes -> nodes
sjdilkes Dec 13, 2021
a61e1fb
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 4, 2022
af08810
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 5, 2022
24be612
Update Compilation Passes to use RoutingV3 (#115)
sjdilkes Jan 7, 2022
8295443
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 7, 2022
ad98c38
Remove outdated Routing code from repository (#165)
sjdilkes Jan 11, 2022
d46a49c
Improve LexiRoute.cpp coverage
sjdilkes Jan 14, 2022
1f71597
Improve MappingFrontier.cpp test coverage
sjdilkes Jan 14, 2022
1319c0e
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 17, 2022
b31c2c0
Rmoeve decmopose_module method
sjdilkes Jan 17, 2022
b18a8db
readd missing test
sjdilkes Jan 17, 2022
0941f74
Update LexiRoute test coverage
sjdilkes Jan 17, 2022
d9aa114
Remove redundant comments
sjdilkes Jan 18, 2022
eba680a
Feature/reorder multi qubit gates (#157)
yao-cqc Jan 18, 2022
89a3dfe
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Jan 18, 2022
c9cf8b2
modify TKET_ASSERT: allow extra messages, catch exceptions in evaluation
drzenharper Jan 19, 2022
b2b0680
replace some exceptions with tket asserts; should be ignored by test …
drzenharper Jan 19, 2022
7b6289b
Merge branch 'develop' into feature/routing-v3
sjdilkes Jan 19, 2022
05c3908
Start moving files for modularisation
sjdilkes Jan 20, 2022
548e52e
compilation refactor commit
sjdilkes Feb 1, 2022
edeaf70
Reorder base cmake
sjdilkes Feb 1, 2022
8b5f108
add assertmessage.cpp to compiilation
sjdilkes Feb 1, 2022
c1f3e53
Rework TokenSwapping includes
sjdilkes Feb 2, 2022
e0d7dee
clang format
sjdilkes Feb 2, 2022
568283f
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 2, 2022
33436f1
update linking for pytket
sjdilkes Feb 2, 2022
66ce863
reformat with black
sjdilkes Feb 2, 2022
3aab473
Revert "reformat with black"
sjdilkes Feb 2, 2022
a9f7478
reformat setup.py
sjdilkes Feb 2, 2022
0516423
update proptests cmakelists
sjdilkes Feb 2, 2022
7e37426
Feature/add serialisation for multi qubit reorder (#184)
yao-cqc Feb 3, 2022
25bf193
Update test coverage for RoutingMethod serialization
sjdilkes Feb 3, 2022
df0c739
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 3, 2022
c4f427e
make mapping_frontier from mapping_frontier
sjdilkes Feb 3, 2022
389fc2a
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 3, 2022
991b85d
routing -> mapping
sjdilkes Feb 3, 2022
df99fbf
use TKET_ASSERT_WITH_THROW instead of TKET_ASSERT
drzenharper Feb 3, 2022
8fbe2f4
Replace TKET_ASSERT with throw and use GCOVR_EXCL_START,STOP where ap…
drzenharper Feb 3, 2022
719498a
replace throws with TKET_ASSERT_WITH_THROW where appropriate
drzenharper Feb 3, 2022
fd09f42
Add the TKET_ASSERT_WITH_THROW macro
drzenharper Feb 3, 2022
fc6bbe8
add simple swap functions tests
drzenharper Feb 3, 2022
3e4ee20
add TKET_ASSERT_WITH_THROW tests, for detailed error messages
drzenharper Feb 3, 2022
2d3a1ab
clang format
drzenharper Feb 3, 2022
740cfc6
try to fix code coverage branching problems in TKET_ASSERT_WITH_THROW…
drzenharper Feb 4, 2022
04efd72
correct "does not return a value" error
drzenharper Feb 4, 2022
1b667a5
Infra/use bimap for quantum boundary (#185)
yao-cqc Feb 4, 2022
7fede77
remove try/catch from tket assert with throw, to cut down branching
drzenharper Feb 4, 2022
ca40c43
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 4, 2022
5991a8c
remove TKET_ASSERT_WITH_THROW, replace with TKET_ASSERT
drzenharper Feb 7, 2022
032f64e
Remove AssertMessage(), add TKET_ASSERT_WITH_MESSAGE
drzenharper Feb 7, 2022
52f221c
manually add coverage exclusion tags for now, until the branching pro…
drzenharper Feb 8, 2022
7d7ba1f
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 8, 2022
dc761e0
Add copyright information
sjdilkes Feb 8, 2022
d805b0b
[RV3] [refactor] Clean up of the dependencies of the modules (#199)
cqc-melf Feb 8, 2022
e3f2b68
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 9, 2022
e8f23dc
add bimaps attribute to MappingFrontier
sjdilkes Feb 9, 2022
4a210cc
update_quantum_boundary_uids remaps bimaps entries
sjdilkes Feb 9, 2022
bac8cc2
Update build_and_test.yml
sjdilkes Feb 11, 2022
2d2d25d
Update changelog.rst
sjdilkes Feb 11, 2022
20404bf
Update copyright dates
sjdilkes Feb 11, 2022
3cffd1f
Update pytket/binders/mapping.cpp
sjdilkes Feb 11, 2022
7c092f2
Update pytket/binders/mapping.cpp
sjdilkes Feb 11, 2022
9a9007d
Update pytket/binders/mapping.cpp
sjdilkes Feb 11, 2022
849c7c5
Corrections for PR
sjdilkes Feb 11, 2022
8ed2f2b
Remove tokenswapping from dependneices
sjdilkes Feb 14, 2022
2b20d2f
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 14, 2022
86fb61e
Feature/decompose boxes in routing (#197)
yao-cqc Feb 14, 2022
4d2dbce
update compilation for tokenswapping
sjdilkes Feb 14, 2022
0202c30
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 14, 2022
a112236
Revert "Feature/decompose boxes in routing (#197)"
sjdilkes Feb 14, 2022
650a189
Address PR Requested changes
sjdilkes Feb 14, 2022
0e742a8
change copyright to 2022
drzenharper Feb 14, 2022
ca30a50
remove unused code, including PathFinderInterface
drzenharper Feb 14, 2022
3366e22
rename HybridTsa00 -> HybridTsa; move files out of include directory
drzenharper Feb 14, 2022
b67528c
move DebugFunctions into tests
drzenharper Feb 14, 2022
db33a86
move get_swaps_lower_bound out of tket into tests
drzenharper Feb 14, 2022
3e518df
simple typos; unused code; extra comments, asserts
drzenharper Feb 14, 2022
8719249
rename main_entry_functions -> SwapsFromQubitMapping; remove unused f…
drzenharper Feb 14, 2022
07aa0ed
move RNG from token swapping to Utils; erase tests/Graphs/RNG
drzenharper Feb 14, 2022
f065447
move get_random_set out of token swapping into test utils
drzenharper Feb 14, 2022
34507b6
move some stuff out of namespace tsa_internal into namespace tket
drzenharper Feb 14, 2022
7e08c8c
more cleanup
drzenharper Feb 14, 2022
067782d
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 15, 2022
efeb704
clang format
drzenharper Feb 15, 2022
c88e949
added OpType dependency to token swapping
drzenharper Feb 15, 2022
ef57306
clang format
drzenharper Feb 15, 2022
192171a
replace throws with TKET_ASSERT_WITH_MESSAGE
drzenharper Feb 15, 2022
61a7b7e
move BruteForceColouring.hpp, ColouringPriority.hpp out of include di…
drzenharper Feb 15, 2022
51cabf0
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 15, 2022
fff97a9
add TokenSwappingWithArch project; move files out of TokenSwapping
drzenharper Feb 15, 2022
96a8aa6
remove architecture from TokenSwapping
drzenharper Feb 15, 2022
890180b
move DistancesInterface, NeighboursInterface out of namespace tsa_int…
drzenharper Feb 15, 2022
b460561
update TokenSwapping tests to use TokenSwappingWithArch
drzenharper Feb 15, 2022
97b1efa
bool type for delay_measures
sjdilkes Feb 15, 2022
f7878df
Create architecture_test.py
sjdilkes Feb 15, 2022
3a1ce49
Reduce test times: add TSGlobalTestParameters with run_long_tests option
drzenharper Feb 15, 2022
f1e2c0b
add test_DebugFunctions.cpp and remove test coverage exclusion
drzenharper Feb 15, 2022
281e70a
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 15, 2022
de2f963
Remove unreachable code.
drzenharper Feb 15, 2022
d7bbd01
update architecture binder
sjdilkes Feb 16, 2022
c6259aa
Revert "update architecture binder"
sjdilkes Feb 16, 2022
7533f90
formatting, remove nodegraph test
sjdilkes Feb 16, 2022
220a7b0
update architecture and mapping tests
sjdilkes Feb 16, 2022
1bd2dfd
add architecture_aware_synthesis_test.py
sjdilkes Feb 16, 2022
770ac41
Create placement_test.py
sjdilkes Feb 16, 2022
9fbbd95
Update range of python mapping tests
sjdilkes Feb 16, 2022
f7452df
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
sjdilkes Feb 16, 2022
f10be47
update routing test coverage
sjdilkes Feb 16, 2022
b75e7f9
Cover Alec's comments
sjdilkes Feb 16, 2022
abe3445
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 16, 2022
a1b5a49
format transform_test
sjdilkes Feb 16, 2022
f24e76b
change length of line
sjdilkes Feb 16, 2022
7eaf6fe
remove trailing white space
sjdilkes Feb 16, 2022
904bd16
name -> name_of_ethod
sjdilkes Feb 16, 2022
8fe485f
name -> name_of_method RoutingMethod
sjdilkes Feb 16, 2022
ecd9b51
tokenswappingwitharch
sjdilkes Feb 16, 2022
329f223
add type ignores
sjdilkes Feb 17, 2022
05661f6
Comment out check_method, rewrite types and methods
sjdilkes Feb 17, 2022
53fef17
Update tests to not use check_method
sjdilkes Feb 17, 2022
2d56e46
update test_routingmethod
sjdilkes Feb 17, 2022
f9394eb
"name_of_method" -> "name'
sjdilkes Feb 18, 2022
4f2ded6
Update valid_operation description
sjdilkes Feb 18, 2022
517c883
Merge branch 'develop' into feature/routing-v3
sjdilkes Feb 18, 2022
a53b7ee
reformat transform_test
sjdilkes Feb 18, 2022
4999115
remove second auto_rebase_pass
sjdilkes Feb 18, 2022
8575f32
Merge branch 'develop' into feature/routing-v3
cqc-melf Feb 18, 2022
ac29545
Add missing import.
cqc-alec Feb 18, 2022
222fee6
Merge branch 'develop' into feature/routing-v3
cqc-alec Feb 18, 2022
e3ae6bc
Add option to tket-tests conan build determining whether full tests a…
cqc-alec Feb 18, 2022
5245c1f
remove TokenSwappingWithArch project; move files into Architecture
drzenharper Feb 18, 2022
3435365
Set "full tests" option on scheduled CI runs only.
cqc-alec Feb 18, 2022
237e23e
change TKET_ASSERT_WITH_MESSAGE to have parentheses around message
drzenharper Feb 18, 2022
042ab9b
Add note to README.
cqc-alec Feb 18, 2022
d40c098
rename HybridTSA_00 to HybridTsa
drzenharper Feb 18, 2022
080a878
Replace TSGlobalTestParameters with #ifdef TKET_TESTS_FULL
drzenharper Feb 18, 2022
61dde34
commit other forgotten files
drzenharper Feb 18, 2022
8820c92
Merge branch 'feature/routing-v3' of https://github.com/CQCL/tket int…
drzenharper Feb 18, 2022
6809f96
Remove GetTketAssertMessage and TKET_ASSERT_WITH_MESSAGE, go back to …
drzenharper Feb 18, 2022
587780a
clang format
drzenharper Feb 18, 2022
c7a830a
Move test_Utils.cpp to test/Utils directory, rename to test_HelperFun…
drzenharper Feb 18, 2022
efeeca3
fix "function does not return a value" error
drzenharper Feb 18, 2022
ac4d57c
fix "non-void function does not return a value" error, attempt 2!
drzenharper Feb 18, 2022
b704bb1
Forgot to remove final TokenSwappingWithArch bits
drzenharper Feb 18, 2022
ea540e8
Merge branch 'feature/routing-v3' into merge-check_method-routing_method
sjdilkes Feb 21, 2022
6ebf1cc
Merge branch 'develop' into merge-check_method-routing_method
sjdilkes Feb 21, 2022
1a6d41a
update test_json
sjdilkes Feb 21, 2022
b2f0c58
update python binders and tests
sjdilkes Feb 21, 2022
fbbab7a
remove commented out code, format
sjdilkes Feb 21, 2022
1e7afaa
change type return of method
sjdilkes Feb 21, 2022
957c382
address PR Comments
sjdilkes Feb 21, 2022
53baa75
use std::get
sjdilkes Feb 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions pytket/binders/mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,23 @@ PYBIND11_MODULE(mapping, m) {
"whole circuits.")
.def(
py::init<
const std::function<std::tuple<Circuit, unit_map_t, unit_map_t>(
const Circuit&, const ArchitecturePtr&)>&,
const std::function<bool(const Circuit&, const ArchitecturePtr&)>,
const std::function<
std::tuple<bool, Circuit, unit_map_t, unit_map_t>(
const Circuit&, const ArchitecturePtr&)>&,
unsigned, unsigned>(),
"Constructor for a routing method defined by partially routing "
"subcircuits.\n\n:param route_subcircuit: A function declaration "
"that given a Circuit and Architecture object, returns a tuple "
"containing a new modified circuit, the initial logical to physical "
"containing a bool informing MappingManager whether to substitue "
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"containing a bool informing MappingManager whether to substitue "
"containing a bool informing MappingManager whether to substitute "

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"the returned circuit into the circuit being routed, "
"a new modified circuit, the initial logical to physical "
"qubit mapping of the modified circuit and the permutation of "
"logical to physical qubit mapping given operations in the "
"modified circuit\n:param check_subcircuit: A function declaration "
"that given a Circuit and Architecture object, returns a bool "
"stating whether the given method can modify the "
"given circuit\n:param max_size: The maximum number of gates "
"modified circuit\n:param max_size: The maximum number of gates "
"permitted in a subcircuit\n:param max_depth: The maximum permitted "
"depth of a subcircuit.",
py::arg("route_subcircuit"), py::arg("check_subcircuit"),
py::arg("max_size"), py::arg("max_depth"));
py::arg("route_subcircuit"), py::arg("max_size"),
py::arg("max_depth"));

py::class_<
LexiRouteRoutingMethod, std::shared_ptr<LexiRouteRoutingMethod>,
Expand Down
26 changes: 10 additions & 16 deletions pytket/tests/mapping_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# simple deterministic heuristic used for testing purposes
def route_subcircuit_func(
circuit: Circuit, architecture: Architecture
) -> Tuple[Circuit, Dict[Node, Node], Dict[Node, Node]]:
) -> Tuple[bool, Circuit, Dict[Node, Node], Dict[Node, Node]]:
# make a replacement circuit with identical unitds
replacement_circuit = Circuit()
for qb in circuit.qubits:
Expand Down Expand Up @@ -60,7 +60,7 @@ def route_subcircuit_func(
for com in circuit.get_commands():
rp_qubits = [permutation_map[relabelling_map[q]] for q in com.qubits]
if len(com.qubits) > 2:
raise ValueError("Command must have maximum two qubits")
return (False, Circuit(), {}, {})
if len(com.qubits) == 1:
replacement_circuit.add_gate(com.op.type, rp_qubits)
if len(com.qubits) == 2:
Expand Down Expand Up @@ -90,15 +90,13 @@ def route_subcircuit_func(

replacement_circuit.add_gate(com.op.type, rp_qubits)

return (replacement_circuit, relabelling_map, permutation_map)
return (True, replacement_circuit, relabelling_map, permutation_map)


def check_subcircuit_func_true(circuit: Circuit, architecture: Architecture) -> bool:
return True


def check_subcircuit_func_false(circuit: Circuit, architecture: Architecture) -> bool:
return False
def route_subcircuit_func_false(
circuit: Circuit, architecture: Architecture
) -> Tuple[bool, Circuit, Dict[Node, Node], Dict[Node, Node]]:
return (False, Circuit(), {}, {})


def test_LexiRouteRoutingMethod() -> None:
Expand Down Expand Up @@ -127,7 +125,7 @@ def test_RoutingMethodCircuit_custom() -> None:
test_mm = MappingManager(test_a)
test_mm.route_circuit(
test_c,
[RoutingMethodCircuit(route_subcircuit_func, check_subcircuit_func_true, 5, 5)],
[RoutingMethodCircuit(route_subcircuit_func, 5, 5)],
)
routed_commands = test_c.get_commands()

Expand All @@ -152,9 +150,7 @@ def test_RoutingMethodCircuit_custom_list() -> None:
test_mm.route_circuit(
test_c,
[
RoutingMethodCircuit(
route_subcircuit_func, check_subcircuit_func_false, 5, 5
),
RoutingMethodCircuit(route_subcircuit_func_false, 5, 5),
LexiRouteRoutingMethod(),
],
)
Expand All @@ -173,9 +169,7 @@ def test_RoutingMethodCircuit_custom_list() -> None:
test_mm.route_circuit(
test_c,
[
RoutingMethodCircuit(
route_subcircuit_func, check_subcircuit_func_true, 5, 5
),
RoutingMethodCircuit(route_subcircuit_func, 5, 5),
LexiRouteRoutingMethod(),
],
)
Expand Down
10 changes: 2 additions & 8 deletions tket/src/Mapping/LexiRoute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,18 +509,12 @@ void LexiRoute::solve(unsigned lookahead) {
LexiRouteRoutingMethod::LexiRouteRoutingMethod(unsigned _max_depth)
: max_depth_(_max_depth){};

bool LexiRouteRoutingMethod::check_method(
const std::shared_ptr<MappingFrontier>& /*mapping_frontier*/,
const ArchitecturePtr& /*architecture*/) const {
return true;
}

unit_map_t LexiRouteRoutingMethod::routing_method(
std::pair<bool, unit_map_t> LexiRouteRoutingMethod::routing_method(
std::shared_ptr<MappingFrontier>& mapping_frontier,
const ArchitecturePtr& architecture) const {
LexiRoute lr(architecture, mapping_frontier);
lr.solve(this->max_depth_);
return {};
return {true, {}};
}

unsigned LexiRouteRoutingMethod::get_max_depth() const {
Expand Down
13 changes: 6 additions & 7 deletions tket/src/Mapping/MappingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,19 @@ bool MappingManager::route_circuit_with_maps(
bool circuit_modified = !check_finish();
while (!check_finish()) {
// The order methods are passed in std::vector<RoutingMethod> is
// the order they are iterated through to call "check_method"
// the order they are run
// If a method performs better but only on specific subcircuits,
// rank it earlier in the passed vector
bool valid_methods = false;
for (const auto& rm : routing_methods) {
// true => can use held routing method
if (rm->check_method(mapping_frontier, this->architecture_)) {
std::pair<bool, unit_map_t> bool_map =
rm->routing_method(mapping_frontier, this->architecture_);
if (bool_map.first) {
valid_methods = true;
unit_map_t partial_permutation =
rm->routing_method(mapping_frontier, this->architecture_);

if (partial_permutation.size() > 0) {
if (bool_map.second.size() > 0) {
std::map<Node, Node> node_map;
for (const auto& x : partial_permutation) {
for (const auto& x : bool_map.second) {
node_map.insert({Node(x.first), Node(x.second)});
}
for (const std::pair<Node, Node>& swap :
Expand Down
38 changes: 8 additions & 30 deletions tket/src/Mapping/MultiGateReorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static void partial_rewire(
}
}

void MultiGateReorder::solve(unsigned max_depth, unsigned max_size) {
bool MultiGateReorder::solve(unsigned max_depth, unsigned max_size) {
// Assume the frontier has been advanced

// store a copy of the original this->mapping_frontier_->quantum_boundray
Expand All @@ -199,6 +199,9 @@ void MultiGateReorder::solve(unsigned max_depth, unsigned max_size) {
// Get a subcircuit only for iterating vertices
Subcircuit circ =
this->mapping_frontier_->get_frontier_subcircuit(max_depth, max_size);

// for return value
bool modification_made = false;
// since we assume that the frontier has been advanced
// we are certain that any multi-q vert lies after the frontier
for (const Vertex &vert : circ.verts) {
Expand All @@ -213,6 +216,7 @@ void MultiGateReorder::solve(unsigned max_depth, unsigned max_size) {
this->mapping_frontier_->circuit_, this->u_frontier_edges_, vert);

if (commute_pairs != std::nullopt) {
modification_made = true;
partial_rewire(
vert, this->mapping_frontier_->circuit_, (*commute_pairs).first,
(*commute_pairs).second);
Expand All @@ -227,44 +231,18 @@ void MultiGateReorder::solve(unsigned max_depth, unsigned max_size) {
}
// Return the quantum boundary to its original setting
this->mapping_frontier_->set_quantum_boundary(copy);
return modification_made;
}

MultiGateReorderRoutingMethod::MultiGateReorderRoutingMethod(
unsigned _max_depth, unsigned _max_size)
: max_depth_(_max_depth), max_size_(_max_size) {}

bool MultiGateReorderRoutingMethod::check_method(
const std::shared_ptr<MappingFrontier> &mapping_frontier,
const ArchitecturePtr &architecture) const {
const EdgeVec u_frontier_edges =
convert_u_frontier_to_edges(*frontier_convert_vertport_to_edge(
mapping_frontier->circuit_, mapping_frontier->quantum_boundary));

Subcircuit circ = mapping_frontier->get_frontier_subcircuit(
this->max_depth_, this->max_size_);
// since we assume that the frontier has been advanced
// we are certain that any multi-q vert lies after the frontier
for (const Vertex &vert : circ.verts) {
if (is_multiq_quantum_gate(mapping_frontier->circuit_, vert) &&
is_physically_permitted(mapping_frontier, architecture, vert)) {
std::optional<std::pair<EdgeVec, EdgeVec>> commute_pairs =
try_find_commute_edges(
mapping_frontier->circuit_, u_frontier_edges, vert);

if (commute_pairs != std::nullopt) {
return true;
}
}
}
return false;
}

unit_map_t MultiGateReorderRoutingMethod::routing_method(
std::pair<bool, unit_map_t> MultiGateReorderRoutingMethod::routing_method(
std::shared_ptr<MappingFrontier> &mapping_frontier,
const ArchitecturePtr &architecture) const {
MultiGateReorder mr(architecture, mapping_frontier);
mr.solve(this->max_depth_, this->max_size_);
return {};
return {mr.solve(this->max_depth_, this->max_size_), {}};
}

unsigned MultiGateReorderRoutingMethod::get_max_depth() const {
Expand Down
40 changes: 13 additions & 27 deletions tket/src/Mapping/RoutingMethodCircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,15 @@
namespace tket {

RoutingMethodCircuit::RoutingMethodCircuit(
const std::function<std::tuple<Circuit, unit_map_t, unit_map_t>(
const std::function<std::tuple<bool, Circuit, unit_map_t, unit_map_t>(
const Circuit&, const ArchitecturePtr&)>
_route_subcircuit,
const std::function<bool(const Circuit&, const ArchitecturePtr&)>
_check_subcircuit,
unsigned _max_size, unsigned _max_depth)
: route_subcircuit_(_route_subcircuit),
check_subcircuit_(_check_subcircuit),
max_size_(_max_size),
max_depth_(_max_depth){};

bool RoutingMethodCircuit::check_method(
const std::shared_ptr<MappingFrontier>& mapping_frontier,
const ArchitecturePtr& architecture) const {
// Get circuit, pass to held check method
Subcircuit frontier_subcircuit = mapping_frontier->get_frontier_subcircuit(
this->max_depth_, this->max_size_);
Circuit frontier_circuit =
mapping_frontier->circuit_.subcircuit(frontier_subcircuit);
frontier_circuit.rename_units(
mapping_frontier->get_default_to_quantum_boundary_unit_map());

return this->check_subcircuit_(frontier_circuit, architecture);
}

unit_map_t RoutingMethodCircuit::routing_method(
std::pair<bool, unit_map_t> RoutingMethodCircuit::routing_method(
std::shared_ptr<MappingFrontier>& mapping_frontier,
const ArchitecturePtr& architecture) const {
// Produce subcircuit and circuit
Expand All @@ -54,30 +37,33 @@ unit_map_t RoutingMethodCircuit::routing_method(
mapping_frontier->get_default_to_quantum_boundary_unit_map());

// get routed subcircuit
std::tuple<Circuit, unit_map_t, unit_map_t> routed_subcircuit =
std::tuple<bool, Circuit, unit_map_t, unit_map_t> routed_subcircuit =
this->route_subcircuit_(frontier_circuit, architecture);
unit_map_t new_labelling = std::get<1>(routed_subcircuit);

if (!get<0>(routed_subcircuit)) {
return {false, {}};
}

// update unit id at boundary in case of relabelling
mapping_frontier->update_quantum_boundary_uids(new_labelling);
mapping_frontier->update_quantum_boundary_uids(get<2>(routed_subcircuit));

unit_map_t swap_permutation;
for (const auto& pair : new_labelling) {
for (const auto& pair : get<2>(routed_subcircuit)) {
if (pair.first != pair.second &&
architecture->node_exists(Node(pair.first))) {
swap_permutation.insert(pair);
}
}
// permute edges held by unitid at out boundary due to swaps
mapping_frontier->permute_subcircuit_q_out_hole(
std::get<2>(routed_subcircuit), frontier_subcircuit);
get<3>(routed_subcircuit), frontier_subcircuit);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this builds: I couldn't find a using declaration for std::get anywhere in our code, so I guess it is coming from a header in some dependency. Anyway, can we please use std::get rather than rely on an accidental inclusion? Or put using std::get; at the top of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


// substitute old boundary with new cirucit
std::get<0>(routed_subcircuit).flatten_registers();
get<1>(routed_subcircuit).flatten_registers();
mapping_frontier->circuit_.substitute(
std::get<0>(routed_subcircuit), frontier_subcircuit);
get<1>(routed_subcircuit), frontier_subcircuit);
// return initial unit_map_t incase swap network required
return swap_permutation;
return {true, swap_permutation};
}

} // namespace tket
12 changes: 3 additions & 9 deletions tket/src/Mapping/include/Mapping/LexiRoute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,21 +169,15 @@ class LexiRouteRoutingMethod : public RoutingMethod {
*/
LexiRouteRoutingMethod(unsigned _max_depth = 100);

/**
* @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 Map between relabelled Qubit, always empty.
*
* @return true bool, map between relabelled Qubit, always empty.
*
*/
unit_map_t routing_method(
std::pair<bool, unit_map_t> routing_method(
std::shared_ptr<MappingFrontier>& mapping_frontier,
const ArchitecturePtr& architecture) const override;

Expand Down
16 changes: 6 additions & 10 deletions tket/src/Mapping/include/Mapping/MultiGateReorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ class MultiGateReorder {
* Try to commute any multi-qubit gates to the quantum frontier
* @param max_depth Maximum number of layers of gates checked for commutation.
* @param max_size Maximum number of gates checked for commutation.
*
* @return true if modification made
*/
void solve(unsigned max_depth, unsigned max_size);
bool solve(unsigned max_depth, unsigned max_size);

private:
// Architecture all new physical operations must respect
Expand All @@ -55,21 +57,15 @@ class MultiGateReorderRoutingMethod : public RoutingMethod {
MultiGateReorderRoutingMethod(
unsigned _max_depth = 10, unsigned _max_size = 10);

/**
* @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.
* @return Whether circuit is modified and Logical to Physical mapping at
* boundary due to modification (always empty)
*
*/
unit_map_t routing_method(
std::pair<bool, unit_map_t> routing_method(
std::shared_ptr<MappingFrontier>& mapping_frontier,
const ArchitecturePtr& architecture) const override;

Expand Down
Loading