GCC Code Coverage Report


Directory: ./
File: Mapping/AASLabelling.cpp
Date: 2022-10-15 05:10:18
Warnings: 1 unchecked decisions!
Exec Total Coverage
Lines: 58 58 100.0%
Functions: 3 3 100.0%
Branches: 68 104 65.4%
Decisions: 6 8 75.0%

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 "Mapping/AASLabelling.hpp"
16
17 namespace tket {
18
19 94 std::pair<bool, unit_map_t> AASLabellingMethod::routing_method(
20 std::shared_ptr<MappingFrontier>& mapping_frontier,
21 const ArchitecturePtr& architecture) const {
22 94 bool found_unplaced_qubit = false;
23 94 bool found_unplaced_ppb = false;
24
25 // search for unplaced qubitto speed up the runtime
26
3/4
✓ Branch 2 taken 94 times.
✗ Branch 3 not taken.
✓ Branch 10 taken 953 times.
✓ Branch 11 taken 74 times.
0/1
? Decision couldn't be analyzed.
1027 for (Qubit q : mapping_frontier->circuit_.all_qubits()) {
27
4/6
✓ Branch 2 taken 953 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 953 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 20 times.
✓ Branch 9 taken 933 times.
2/2
✓ Decision 'true' taken 20 times.
✓ Decision 'false' taken 933 times.
953 if (!architecture->node_exists(Node(q))) {
28 20 found_unplaced_qubit = true;
29 20 break;
30 }
31
2/2
✓ Branch 1 taken 933 times.
✓ Branch 2 taken 20 times.
1027 }
32
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 74 times.
2/2
✓ Decision 'true' taken 20 times.
✓ Decision 'false' taken 74 times.
94 if (found_unplaced_qubit) {
33 std::shared_ptr<unit_frontier_t> next_frontier =
34 frontier_convert_vertport_to_edge(
35
1/2
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
20 mapping_frontier->circuit_, mapping_frontier->linear_boundary);
36
37 20 CutFrontier next_cut = mapping_frontier->circuit_.next_cut(
38
2/4
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 7 not taken.
40 next_frontier, std::make_shared<b_frontier_t>());
39
40
2/2
✓ Branch 6 taken 38 times.
✓ Branch 7 taken 20 times.
2/2
✓ Decision 'true' taken 38 times.
✓ Decision 'false' taken 20 times.
58 for (const Vertex& v : *next_cut.slice) {
41
3/4
✓ Branch 2 taken 38 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✓ Branch 5 taken 35 times.
38 if (mapping_frontier->circuit_.get_OpType_from_Vertex(v) ==
42 OpType::PhasePolyBox) {
43 TKET_ASSERT(mapping_frontier->circuit_.is_quantum_node(v));
44 Op_ptr op_ptr_ppb =
45
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 mapping_frontier->circuit_.get_Op_ptr_from_Vertex(v);
46
47 6 for (const Edge& e : mapping_frontier->circuit_.get_in_edges_of_type(
48
3/4
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 17 times.
✓ Branch 9 taken 3 times.
23 v, EdgeType::Quantum)) {
49 17 for (const std::pair<UnitID, Edge>& pair :
50
5/8
✓ Branch 5 taken 139 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 139 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 156 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 139 times.
✓ Branch 14 taken 17 times.
173 next_frontier->get<TagKey>()) {
51
3/4
✓ Branch 1 taken 139 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
✓ Branch 4 taken 122 times.
139 if (pair.second == e) {
52
4/6
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 10 times.
17 if (!architecture->node_exists(Node(pair.first))) {
53 7 found_unplaced_ppb = true;
54 }
55 }
56 }
57 3 }
58 3 }
59 }
60 20 }
61
62
2/2
✓ Branch 0 taken 91 times.
✓ Branch 1 taken 3 times.
94 if (!found_unplaced_ppb) {
63
1/2
✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
91 return {false, {}};
64 } else {
65
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 qubit_vector_t q_vec = mapping_frontier->circuit_.all_qubits();
66 3 unit_map_t qubit_to_nodes_place;
67 3 node_set_t node_set_placed;
68
69
2/2
✓ Branch 6 taken 17 times.
✓ Branch 7 taken 3 times.
20 for (Qubit q : q_vec) {
70
4/6
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 10 times.
✓ Branch 9 taken 7 times.
17 if (architecture->node_exists(Node(q))) {
71
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
10 qubit_to_nodes_place.insert({q, Node(q)});
72
2/4
✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 10 times.
✗ Branch 5 not taken.
10 node_set_placed.insert(Node(q));
73 }
74 17 }
75
76
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 node_vector_t nodes_vec = architecture->get_all_nodes_vec();
77
78 // place all unplaced qubits
79
80
2/2
✓ Branch 6 taken 17 times.
✓ Branch 7 taken 3 times.
20 for (Qubit q : q_vec) {
81
4/6
✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 7 times.
✓ Branch 9 taken 10 times.
17 if (!architecture->node_exists(Node(q))) {
82 // found unplaced qubit
83 // other checks could be added here to avoid placing unused qubits or
84 // qubits that are not in an ppb
85
86 7 unsigned index_to_use = 0;
87
1/2
✓ Branch 2 taken 23 times.
✗ Branch 3 not taken.
30 while (node_set_placed.find(nodes_vec[index_to_use]) !=
88
2/2
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 7 times.
46 node_set_placed.end()) {
89 16 ++index_to_use;
90 }
91
1/2
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
7 qubit_to_nodes_place.insert({q, nodes_vec[index_to_use]});
92
1/2
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
7 node_set_placed.insert(nodes_vec[index_to_use]);
93
1/2
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
28 mapping_frontier->update_bimaps(
94
1/2
✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
14 mapping_frontier->get_qubit_from_circuit_uid(q),
95 7 nodes_vec[index_to_use]);
96 }
97 17 }
98
99
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 mapping_frontier->update_linear_boundary_uids(qubit_to_nodes_place);
100
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 mapping_frontier->circuit_.rename_units(qubit_to_nodes_place);
101
102
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 return {true, {}};
103 3 }
104 }
105
106 1 nlohmann::json AASLabellingMethod::serialize() const {
107 1 nlohmann::json j;
108
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 j["name"] = "AASLabellingMethod";
109 1 return j;
110 }
111
112 1 AASLabellingMethod AASLabellingMethod::deserialize(
113 const nlohmann::json& /*j*/) {
114 1 return AASLabellingMethod();
115 }
116
117 } // namespace tket
118