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 <utility> | |||
16 | ||||
17 | #include "GateUnitaryMatrixImplementations.hpp" | |||
18 | #include "GateUnitaryMatrixUtils.hpp" | |||
19 | #include "Utils/Constants.hpp" | |||
20 | ||||
21 | // This file is for gates with unitary matrices | |||
22 | // computed using other ("primitive") gates. | |||
23 | // Of course, this choice is subjective and could change. | |||
24 | ||||
25 | namespace tket { | |||
26 | namespace internal { | |||
27 | ||||
28 | 128 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::CU1(double lambda) { | ||
29 |
1/2✓ Branch 2 taken 128 times.
✗ Branch 3 not taken.
|
256 | return GateUnitaryMatrixUtils::get_controlled_gate_unitary(U1(lambda)); | |
30 | } | |||
31 | ||||
32 | 2466 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::CU3( | ||
33 | double theta, double phi, double lambda) { | |||
34 | return GateUnitaryMatrixUtils::get_controlled_gate_unitary( | |||
35 |
1/2✓ Branch 2 taken 2466 times.
✗ Branch 3 not taken.
|
4932 | U3(theta, phi, lambda)); | |
36 | } | |||
37 | ||||
38 | 217 | Eigen::Matrix2cd GateUnitaryMatrixImplementations::U2( | ||
39 | double phi, double lambda) { | |||
40 | 217 | return U3(0.5, phi, lambda); | ||
41 | } | |||
42 | ||||
43 | 11570 | Eigen::Matrix2cd GateUnitaryMatrixImplementations::U3( | ||
44 | double theta, double phi, double lambda) { | |||
45 |
5/10✓ Branch 1 taken 11570 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 11570 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 11570 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 11570 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 11570 times.
✗ Branch 15 not taken.
|
11570 | return std::polar(1.0, 0.5 * PI * (lambda + phi)) * Rz(phi) * Ry(theta) * | |
46 |
1/2✓ Branch 2 taken 11570 times.
✗ Branch 3 not taken.
|
34710 | Rz(lambda); | |
47 | } | |||
48 | ||||
49 | 9240 | Eigen::Matrix2cd GateUnitaryMatrixImplementations::TK1( | ||
50 | double alpha, double beta, double gamma) { | |||
51 |
5/10✓ Branch 2 taken 9240 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 9240 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 9240 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 9240 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 9240 times.
✗ Branch 15 not taken.
|
18480 | return Rz(alpha) * Rx(beta) * Rz(gamma); | |
52 | } | |||
53 | ||||
54 | 5383 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::CRx(double alpha) { | ||
55 |
1/2✓ Branch 2 taken 5383 times.
✗ Branch 3 not taken.
|
10766 | return GateUnitaryMatrixUtils::get_controlled_gate_unitary(Rx(alpha)); | |
56 | } | |||
57 | ||||
58 | 207 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::CRy(double alpha) { | ||
59 |
1/2✓ Branch 2 taken 207 times.
✗ Branch 3 not taken.
|
414 | return GateUnitaryMatrixUtils::get_controlled_gate_unitary(Ry(alpha)); | |
60 | } | |||
61 | ||||
62 | 183 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::CRz(double alpha) { | ||
63 |
1/2✓ Branch 2 taken 183 times.
✗ Branch 3 not taken.
|
366 | return GateUnitaryMatrixUtils::get_controlled_gate_unitary(Rz(alpha)); | |
64 | } | |||
65 | ||||
66 | 2451 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::TK2( | ||
67 | double alpha, double beta, double gamma) { | |||
68 |
5/10✓ Branch 2 taken 2451 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2451 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 2451 times.
✗ Branch 9 not taken.
✓ Branch 11 taken 2451 times.
✗ Branch 12 not taken.
✓ Branch 14 taken 2451 times.
✗ Branch 15 not taken.
|
4902 | return XXPhase(alpha) * YYPhase(beta) * ZZPhase(gamma); | |
69 | } | |||
70 | ||||
71 | 86 | Eigen::Matrix4cd GateUnitaryMatrixImplementations::PhasedISWAP( | ||
72 | double p, double t) { | |||
73 |
1/2✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
|
86 | auto matr = ISWAP(t); | |
74 | 86 | const auto exp_term = std::polar(1.0, -2 * PI * p); | ||
75 |
1/2✓ Branch 1 taken 86 times.
✗ Branch 2 not taken.
|
86 | matr(2, 1) *= exp_term; | |
76 |
1/2✓ Branch 2 taken 86 times.
✗ Branch 3 not taken.
|
86 | matr(1, 2) *= std::conj(exp_term); | |
77 | 172 | return matr; | ||
78 | } | |||
79 | ||||
80 | Eigen::Matrix<std::complex<double>, 1, 1> | |||
81 | 1 | GateUnitaryMatrixImplementations::Phase(double alpha) { | ||
82 |
1/2✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | return Eigen::Matrix<std::complex<double>, 1, 1>(std::exp(i_ * PI * alpha)); | |
83 | } | |||
84 | ||||
85 | 381 | Eigen::Matrix2cd GateUnitaryMatrixImplementations::PhasedX( | ||
86 | double alpha, double beta) { | |||
87 |
1/2✓ Branch 1 taken 381 times.
✗ Branch 2 not taken.
|
381 | const auto rz_beta_matr = Rz(beta); | |
88 |
5/10✓ Branch 1 taken 381 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 381 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 381 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 381 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 381 times.
✗ Branch 14 not taken.
|
762 | return rz_beta_matr * Rx(alpha) * rz_beta_matr.conjugate(); | |
89 | } | |||
90 | ||||
91 | 239 | Eigen::MatrixXcd GateUnitaryMatrixImplementations::NPhasedX( | ||
92 | unsigned number_of_qubits, double alpha, double beta) { | |||
93 |
1/2✓ Branch 1 taken 239 times.
✗ Branch 2 not taken.
|
239 | const auto phasedx_matr = PhasedX(alpha, beta); | |
94 |
2/4✓ Branch 1 taken 239 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 239 times.
✗ Branch 5 not taken.
|
239 | Eigen::MatrixXcd U = Eigen::MatrixXcd::Identity(1, 1); | |
95 |
2/2✓ Branch 0 taken 708 times.
✓ Branch 1 taken 239 times.
|
2/2✓ Decision 'true' taken 708 times.
✓ Decision 'false' taken 239 times.
|
947 | for (unsigned i = 0; i < number_of_qubits; i++) { |
96 |
2/4✓ Branch 1 taken 708 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 708 times.
✗ Branch 5 not taken.
|
708 | Eigen::MatrixXcd V = Eigen::kroneckerProduct(phasedx_matr, U); | |
97 | 708 | U = std::move(V); | ||
98 | 708 | } | ||
99 | 478 | return U; | ||
100 | } | |||
101 | ||||
102 | 30 | Eigen::MatrixXcd GateUnitaryMatrixImplementations::CnRy( | ||
103 | unsigned int number_of_qubits, double alpha) { | |||
104 | return GateUnitaryMatrixUtils::get_multi_controlled_gate_dense_unitary( | |||
105 |
3/4✓ Branch 2 taken 30 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 28 times.
✓ Branch 6 taken 2 times.
|
32 | Ry(alpha), number_of_qubits); | |
106 | } | |||
107 | ||||
108 | 18 | Eigen::MatrixXcd GateUnitaryMatrixImplementations::CnX( | ||
109 | unsigned int number_of_qubits) { | |||
110 | return GateUnitaryMatrixUtils::get_multi_controlled_gate_dense_unitary( | |||
111 |
2/2✓ Branch 3 taken 16 times.
✓ Branch 4 taken 2 times.
|
18 | X(), number_of_qubits); | |
112 | } | |||
113 | ||||
114 | 18 | Eigen::MatrixXcd GateUnitaryMatrixImplementations::CnZ( | ||
115 | unsigned int number_of_qubits) { | |||
116 | return GateUnitaryMatrixUtils::get_multi_controlled_gate_dense_unitary( | |||
117 |
2/2✓ Branch 3 taken 16 times.
✓ Branch 4 taken 2 times.
|
18 | Z(), number_of_qubits); | |
118 | } | |||
119 | ||||
120 | 18 | Eigen::MatrixXcd GateUnitaryMatrixImplementations::CnY( | ||
121 | unsigned int number_of_qubits) { | |||
122 | return GateUnitaryMatrixUtils::get_multi_controlled_gate_dense_unitary( | |||
123 |
2/2✓ Branch 3 taken 16 times.
✓ Branch 4 taken 2 times.
|
18 | Y(), number_of_qubits); | |
124 | } | |||
125 | ||||
126 | } // namespace internal | |||
127 | } // namespace tket | |||
128 |