Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | // Copyright 2019-2022 Cambridge Quantum Computing | |||
2 | // | |||
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |||
4 | // you may not use this file except in compliance with the License. | |||
5 | // You may obtain a copy of the License at | |||
6 | // | |||
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |||
8 | // | |||
9 | // Unless required by applicable law or agreed to in writing, software | |||
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |||
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
12 | // See the License for the specific language governing permissions and | |||
13 | // limitations under the License. | |||
14 | ||||
15 | #include "RoutingMethodCircuit.hpp" | |||
16 | ||||
17 | namespace tket { | |||
18 | ||||
19 | 5 | RoutingMethodCircuit::RoutingMethodCircuit( | ||
20 | const std::function<std::tuple<bool, Circuit, unit_map_t, unit_map_t>( | |||
21 | const Circuit&, const ArchitecturePtr&)> | |||
22 | _route_subcircuit, | |||
23 | 5 | unsigned _max_size, unsigned _max_depth) | ||
24 | 5 | : route_subcircuit_(_route_subcircuit), | ||
25 | 5 | max_size_(_max_size), | ||
26 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | max_depth_(_max_depth){}; | |
27 | ||||
28 | 6 | std::pair<bool, unit_map_t> RoutingMethodCircuit::routing_method( | ||
29 | MappingFrontier_ptr& mapping_frontier, | |||
30 | const ArchitecturePtr& architecture) const { | |||
31 | // Produce subcircuit and circuit | |||
32 | Subcircuit frontier_subcircuit = mapping_frontier->get_frontier_subcircuit( | |||
33 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | this->max_depth_, this->max_size_); | |
34 | Circuit frontier_circuit = | |||
35 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
6 | mapping_frontier->circuit_.subcircuit(frontier_subcircuit); | |
36 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | frontier_circuit.rename_units( | |
37 |
1/2✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 | mapping_frontier->get_default_to_linear_boundary_unit_map()); | |
38 | ||||
39 | // get routed subcircuit | |||
40 | std::tuple<bool, Circuit, unit_map_t, unit_map_t> routed_subcircuit = | |||
41 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | this->route_subcircuit_(frontier_circuit, architecture); | |
42 | ||||
43 |
2/2✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
|
2/2✓ Decision 'true' taken 1 times.
✓ Decision 'false' taken 5 times.
|
6 | if (!std::get<0>(routed_subcircuit)) { |
44 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return {false, {}}; | |
45 | } | |||
46 | ||||
47 | // update unit id at boundary in case of relabelling | |||
48 | // The route_subcircuit_ method populates its initial map | |||
49 | // with unit ids from the circuit. e.g. Initial map from frontier == | |||
50 | // q[0]:unplaced[0], circuit.all_qubits() == unplaced[0]. Then the produced | |||
51 | // initial map == unplaced[0]:node[0] We have to update the initial map to | |||
52 | // q[0]:node[0] | |||
53 |
1/2✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
|
5 | mapping_frontier->update_linear_boundary_uids(std::get<2>(routed_subcircuit)); | |
54 |
2/2✓ Branch 5 taken 15 times.
✓ Branch 6 taken 5 times.
|
2/2✓ Decision 'true' taken 15 times.
✓ Decision 'false' taken 5 times.
|
20 | for (const auto& pair : std::get<2>(routed_subcircuit)) { |
55 |
1/2✓ Branch 2 taken 15 times.
✗ Branch 3 not taken.
|
45 | mapping_frontier->update_bimaps( | |
56 |
1/2✓ Branch 3 taken 15 times.
✗ Branch 4 not taken.
|
30 | mapping_frontier->get_qubit_from_circuit_uid(pair.first), pair.second); | |
57 | } | |||
58 | ||||
59 | 5 | unit_map_t swap_permutation; | ||
60 |
2/2✓ Branch 6 taken 15 times.
✓ Branch 7 taken 5 times.
|
2/2✓ Decision 'true' taken 15 times.
✓ Decision 'false' taken 5 times.
|
20 | for (const auto& pair : std::get<2>(routed_subcircuit)) { |
61 |
3/4✓ Branch 1 taken 15 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
✓ Branch 4 taken 2 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 28 times.
|
28 | if (pair.first != pair.second && |
62 |
6/12✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 13 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 13 times.
✓ Branch 9 taken 13 times.
✓ Branch 10 taken 2 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 15 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
|
28 | architecture->node_exists(Node(pair.first))) { | |
63 | ✗ | swap_permutation.insert(pair); | ||
64 | } | |||
65 | } | |||
66 | // permute edges held by unitid at out boundary due to swaps | |||
67 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | mapping_frontier->permute_subcircuit_q_out_hole( | |
68 | 5 | std::get<3>(routed_subcircuit), frontier_subcircuit); | ||
69 | ||||
70 | // substitute old boundary with new cirucit | |||
71 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
5 | std::get<1>(routed_subcircuit).flatten_registers(); | |
72 |
1/2✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
|
10 | mapping_frontier->circuit_.substitute( | |
73 | 5 | std::get<1>(routed_subcircuit), frontier_subcircuit); | ||
74 | // return initial unit_map_t incase swap network required | |||
75 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | return {true, swap_permutation}; | |
76 | 6 | } | ||
77 | ||||
78 | } // namespace tket | |||
79 |