GCC Code Coverage Report


Directory: ./
File: Gate/GateUnitaryMatrixVariableQubits.cpp
Date: 2022-10-15 05:10:18
Exec Total Coverage
Lines: 34 35 97.1%
Functions: 4 4 100.0%
Branches: 18 122 14.8%
Decisions: 10 13 76.9%

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 "GateUnitaryMatrixVariableQubits.hpp"
16
17 #include <tkassert/Assert.hpp>
18
19 #include "GateUnitaryMatrixImplementations.hpp"
20
21 namespace tket {
22 namespace internal {
23
24 197293 GateUnitaryMatrixVariableQubits::GateUnitaryMatrixVariableQubits(
25 197293 OpType op_type_)
26 197293 : op_type(op_type_), known_type(true), number_of_parameters(0) {
27
4/4
✓ Branch 0 taken 283 times.
✓ Branch 1 taken 234 times.
✓ Branch 2 taken 269 times.
✓ Branch 3 taken 196507 times.
197293 switch (op_type) {
28
0/1
✗ Decision 'true' not taken.
283 case OpType::CnRy:
29 // Fall through.
30 case OpType::PhaseGadget:
31 283 number_of_parameters = 1;
32 283 break;
33 234 case OpType::CnX:
34 case OpType::CnZ:
35 case OpType::CnY:
36 234 break;
37
1/1
✓ Decision 'true' taken 269 times.
269 case OpType::NPhasedX:
38 269 number_of_parameters = 2;
39 269 break;
40
1/1
✓ Decision 'true' taken 196507 times.
196507 default:
41 196507 known_type = false;
42 }
43 197293 }
44
45 197293 bool GateUnitaryMatrixVariableQubits::is_known_type() const {
46 197293 return known_type;
47 }
48
49 786 unsigned GateUnitaryMatrixVariableQubits::get_number_of_parameters() const {
50 786 return number_of_parameters;
51 }
52
53 396 Eigen::MatrixXcd GateUnitaryMatrixVariableQubits::get_dense_unitary(
54 unsigned number_of_qubits, const std::vector<double>& parameters) const {
55 // This class is internal only, so an assert is OK.
56 TKET_ASSERT(known_type);
57 TKET_ASSERT(parameters.size() == number_of_parameters);
58
3/4
✓ Branch 1 taken 54 times.
✓ Branch 2 taken 103 times.
✓ Branch 3 taken 239 times.
✗ Branch 4 not taken.
396 switch (parameters.size()) {
59
1/1
✓ Decision 'true' taken 54 times.
54 case 0:
60
5/108
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 18 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 61 not taken.
✗ Branch 62 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 74 not taken.
✗ Branch 75 not taken.
✗ Branch 77 not taken.
✗ Branch 78 not taken.
✗ Branch 80 not taken.
✗ Branch 81 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✗ Branch 86 not taken.
✗ Branch 87 not taken.
✗ Branch 89 not taken.
✗ Branch 90 not taken.
✗ Branch 92 not taken.
✗ Branch 93 not taken.
✗ Branch 96 not taken.
✗ Branch 97 not taken.
✗ Branch 99 not taken.
✗ Branch 100 not taken.
✗ Branch 102 not taken.
✗ Branch 103 not taken.
✗ Branch 105 not taken.
✗ Branch 106 not taken.
✗ Branch 108 not taken.
✗ Branch 109 not taken.
✗ Branch 112 not taken.
✗ Branch 113 not taken.
✗ Branch 116 not taken.
✗ Branch 117 not taken.
✗ Branch 119 not taken.
✗ Branch 120 not taken.
✗ Branch 125 not taken.
✗ Branch 126 not taken.
✗ Branch 128 not taken.
✗ Branch 129 not taken.
✗ Branch 131 not taken.
✗ Branch 132 not taken.
✗ Branch 134 not taken.
✗ Branch 135 not taken.
✗ Branch 137 not taken.
✗ Branch 138 not taken.
✗ Branch 140 not taken.
✗ Branch 141 not taken.
✗ Branch 143 not taken.
✗ Branch 144 not taken.
✗ Branch 146 not taken.
✗ Branch 147 not taken.
✗ Branch 149 not taken.
✗ Branch 150 not taken.
✗ Branch 152 not taken.
✗ Branch 153 not taken.
✗ Branch 155 not taken.
✗ Branch 156 not taken.
✗ Branch 158 not taken.
✗ Branch 159 not taken.
✗ Branch 161 not taken.
✗ Branch 162 not taken.
✗ Branch 165 not taken.
✗ Branch 166 not taken.
✗ Branch 169 not taken.
✗ Branch 170 not taken.
✗ Branch 172 not taken.
✗ Branch 173 not taken.
54 TKET_ASSERT(
61 op_type == OpType::CnX || op_type == OpType::CnZ ||
62 op_type == OpType::CnY);
63
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 36 times.
2/2
✓ Decision 'true' taken 18 times.
✓ Decision 'false' taken 36 times.
54 if (op_type == OpType::CnX) {
64 18 return GateUnitaryMatrixImplementations::CnX(number_of_qubits);
65
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 18 times.
2/2
✓ Decision 'true' taken 18 times.
✓ Decision 'false' taken 18 times.
36 } else if (op_type == OpType::CnZ) {
66 18 return GateUnitaryMatrixImplementations::CnZ(number_of_qubits);
67 } else {
68 18 return GateUnitaryMatrixImplementations::CnY(number_of_qubits);
69 }
70
1/1
✓ Decision 'true' taken 103 times.
103 case 1:
71
2/2
✓ Branch 0 taken 30 times.
✓ Branch 1 taken 73 times.
2/2
✓ Decision 'true' taken 30 times.
✓ Decision 'false' taken 73 times.
103 if (op_type == OpType::CnRy) {
72 return GateUnitaryMatrixImplementations::CnRy(
73 30 number_of_qubits, parameters[0]);
74 } else {
75 TKET_ASSERT(op_type == OpType::PhaseGadget);
76 return GateUnitaryMatrixImplementations::PhaseGadget(
77 73 number_of_qubits, parameters[0]);
78 }
79
0/1
✗ Decision 'true' not taken.
239 case 2:
80 TKET_ASSERT(op_type == OpType::NPhasedX);
81 return GateUnitaryMatrixImplementations::NPhasedX(
82 239 number_of_qubits, parameters[0], parameters[1]);
83
0/1
✗ Decision 'true' not taken.
default:
84 TKET_ASSERT(false);
85 }
86 }
87
88 } // namespace internal
89 } // namespace tket
90