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 "Verification.hpp" | |||
16 | ||||
17 | namespace tket { | |||
18 | 87 | bool respects_connectivity_constraints( | ||
19 | const Circuit &circ, const Architecture &arch, bool directed, | |||
20 | bool bridge_allowed) { | |||
21 | 87 | unit_set_t qb_lookup; | ||
22 |
3/4✓ Branch 1 taken 87 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 611 times.
✓ Branch 9 taken 77 times.
|
0/1? Decision couldn't be analyzed.
|
688 | for (const Qubit &qb : circ.all_qubits()) { |
23 |
4/6✓ Branch 1 taken 611 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 611 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 10 times.
✓ Branch 8 taken 601 times.
|
2/2✓ Decision 'true' taken 601 times.
✓ Decision 'false' taken 10 times.
|
611 | if (!arch.node_exists(Node(qb))) return false; |
24 |
1/2✓ Branch 1 taken 601 times.
✗ Branch 2 not taken.
|
601 | qb_lookup.insert(qb); | |
25 |
2/2✓ Branch 1 taken 77 times.
✓ Branch 2 taken 10 times.
|
87 | } | |
26 |
5/8✓ Branch 1 taken 77 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 9639 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 9716 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 9648 times.
✓ Branch 12 taken 68 times.
|
0/1? Decision couldn't be analyzed.
|
9716 | for (Circuit::CommandIterator it = circ.begin(); it != circ.end(); ++it) { |
27 |
1/2✓ Branch 1 taken 9648 times.
✗ Branch 2 not taken.
|
9648 | const Command &com = *it; | |
28 | 9648 | unit_vector_t qbs; | ||
29 |
3/4✓ Branch 1 taken 9648 times.
✗ Branch 2 not taken.
✓ Branch 8 taken 18558 times.
✓ Branch 9 taken 9648 times.
|
0/1? Decision couldn't be analyzed.
|
28206 | for (const UnitID &arg : com.get_args()) { |
30 |
4/6✓ Branch 2 taken 18558 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 16484 times.
✓ Branch 6 taken 2074 times.
✓ Branch 8 taken 16484 times.
✗ Branch 9 not taken.
|
2/2✓ Decision 'true' taken 9648 times.
✓ Decision 'false' taken 8910 times.
|
18558 | if (qb_lookup.find(arg) != qb_lookup.end()) qbs.push_back(arg); |
31 | 9648 | } | ||
32 | 9648 | Op_ptr op = com.get_op_ptr(); | ||
33 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 9648 times.
|
1/2✓ Decision 'true' taken 9648 times.
✗ Decision 'false' not taken.
|
9648 | if (op->get_type() == OpType::Barrier) continue; |
34 |
2/2✓ Branch 2 taken 603 times.
✓ Branch 3 taken 9045 times.
|
2/2✓ Decision 'true' taken 603 times.
✓ Decision 'false' taken 9045 times.
|
9648 | if (op->get_type() == OpType::Conditional) { |
35 | std::shared_ptr<const Conditional> cond_ptr = | |||
36 | 603 | std::dynamic_pointer_cast<const Conditional>(op); | ||
37 |
1/2✓ Branch 2 taken 603 times.
✗ Branch 3 not taken.
|
603 | op = cond_ptr->get_op(); | |
38 | 603 | } | ||
39 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 9648 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 9648 times.
|
9648 | if (op->get_type() == OpType::CircBox) { |
40 | std::shared_ptr<const Box> box_ptr = | |||
41 | ✗ | std::dynamic_pointer_cast<const Box>(op); | ||
42 | ✗ | Circuit box_circ = *box_ptr->to_circuit().get(); | ||
43 | ✗ | qubit_vector_t all_units = box_circ.all_qubits(); | ||
44 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (all_units.size() != qbs.size()) return false; | |
45 | ✗ | unit_map_t rename_map; | ||
46 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | for (unsigned i = 0; i < all_units.size(); i++) | |
47 | ✗ | rename_map.insert({all_units[i], qbs[i]}); | ||
48 | ✗ | box_circ.rename_units(rename_map); | ||
49 | ✗ | if (!respects_connectivity_constraints( | ||
50 | box_circ, arch, directed, bridge_allowed)) | |||
51 | ✗ | return false; | ||
52 | ✗ | continue; | ||
53 | } | |||
54 | 9648 | unsigned n_qbs = qbs.size(); | ||
55 |
3/4✓ Branch 0 taken 2866 times.
✓ Branch 1 taken 6728 times.
✓ Branch 2 taken 54 times.
✗ Branch 3 not taken.
|
9648 | switch (n_qbs) { | |
56 | 2866 | case 1: | ||
57 | 2866 | break; | ||
58 | 6728 | case 2: { | ||
59 |
5/8✓ Branch 2 taken 6728 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6728 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 6728 times.
✗ Branch 10 not taken.
✓ Branch 13 taken 4 times.
✓ Branch 14 taken 6724 times.
|
6728 | if (arch.get_distance(Node(qbs[0]), Node(qbs[1])) != 1) { | |
60 | 4 | return false; | ||
61 | } | |||
62 |
2/2✓ Branch 0 taken 1187 times.
✓ Branch 1 taken 5537 times.
|
6724 | if (directed) { | |
63 | 1187 | OpType ot = op->get_type(); | ||
64 |
3/4✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1186 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
2373 | if ((ot == OpType::CX || ot == OpType::ECR) && | |
65 |
11/18✓ Branch 2 taken 1186 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1186 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1186 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 3 times.
✓ Branch 12 taken 1183 times.
✓ Branch 13 taken 1186 times.
✓ Branch 14 taken 1 times.
✓ Branch 16 taken 1186 times.
✓ Branch 17 taken 1 times.
✓ Branch 19 taken 3 times.
✓ Branch 20 taken 1184 times.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
2373 | !arch.edge_exists(Node(qbs[0]), Node(qbs[1]))) | |
66 | 3 | return false; | ||
67 | } | |||
68 | 6721 | break; | ||
69 | } | |||
70 | 54 | case 3: { | ||
71 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 2 times.
|
54 | if (bridge_allowed) { | |
72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 52 times.
|
52 | if (directed) | |
73 | ✗ | throw std::logic_error( | ||
74 | "BRIDGE ops are disallowed on a directed " | |||
75 | ✗ | "architecture. They must be decomposed."); | ||
76 |
1/2✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
|
52 | if (op->get_type() == OpType::BRIDGE) { | |
77 |
6/16✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 52 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 52 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 52 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 52 times.
✗ Branch 15 not taken.
✗ Branch 17 not taken.
✓ Branch 18 taken 52 times.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
|
156 | if (arch.get_distance(Node(qbs[0]), Node(qbs[1])) != 1 || | |
78 |
7/18✓ Branch 2 taken 52 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 52 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 52 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✓ Branch 12 taken 52 times.
✓ Branch 13 taken 52 times.
✗ Branch 14 not taken.
✓ Branch 16 taken 52 times.
✗ Branch 17 not taken.
✓ Branch 19 taken 52 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
|
104 | arch.get_distance(Node(qbs[1]), Node(qbs[2])) != 1) { | |
79 | ✗ | return false; | ||
80 | } | |||
81 | } else | |||
82 | ✗ | return false; | ||
83 | } else | |||
84 | 2 | return false; | ||
85 | 52 | break; | ||
86 | } | |||
87 | ✗ | default: | ||
88 | ✗ | return false; | ||
89 | } | |||
90 |
8/11✓ Branch 1 taken 9639 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✓ Branch 5 taken 9639 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 9 times.
✓ Branch 9 taken 9639 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 9 times.
✓ Branch 13 taken 68 times.
✓ Branch 14 taken 9 times.
|
9743 | } | |
91 | 68 | return true; | ||
92 | 87 | } | ||
93 | ||||
94 | } // namespace tket | |||
95 |