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 "OpDesc.hpp" | |||
16 | ||||
17 | #include <algorithm> | |||
18 | ||||
19 | #include "OpTypeFunctions.hpp" | |||
20 | ||||
21 | namespace tket { | |||
22 | ||||
23 | 2012801 | OpDesc::OpDesc(OpType type) | ||
24 | 2012801 | : type_(type), | ||
25 | 2012801 | info_(optypeinfo().at(type)), | ||
26 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_meta_(is_metaop_type(type)), | |
27 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_box_(is_box_type(type)), | |
28 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_gate_(is_gate_type(type)), | |
29 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_flowop_(is_flowop_type(type)), | |
30 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_classical_(is_classical_type(type)), | |
31 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_rotation_(is_rotation_type(type)), | |
32 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_oneway_(is_oneway_type(type)), | |
33 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_clifford_(is_clifford_type(type)), | |
34 | 2012801 | is_parameterised_pauli_rotation_( | ||
35 |
1/2✓ Branch 1 taken 2012801 times.
✗ Branch 2 not taken.
|
2012801 | is_parameterised_pauli_rotation_type(type)) {} | |
36 | ||||
37 | 332220 | OpType OpDesc::type() const { return type_; } | ||
38 | ||||
39 | 6093 | std::string OpDesc::name() const { return info_.name; } | ||
40 | ||||
41 | 13 | std::string OpDesc::latex() const { return info_.latex_name; } | ||
42 | ||||
43 | 3 | unsigned OpDesc::n_params() const { return info_.n_params(); } | ||
44 | ||||
45 | 3069325 | std::optional<op_signature_t> OpDesc::signature() const { | ||
46 | 3069325 | return info_.signature; | ||
47 | } | |||
48 | ||||
49 | 816378 | OptUInt OpDesc::n_qubits() const { | ||
50 |
2/2✓ Branch 1 taken 813400 times.
✓ Branch 2 taken 2978 times.
|
2/2✓ Decision 'true' taken 813400 times.
✓ Decision 'false' taken 2978 times.
|
816378 | if (info_.signature) { |
51 |
1/2✓ Branch 4 taken 813400 times.
✗ Branch 5 not taken.
|
813400 | unsigned n = std::count( | |
52 | 813400 | info_.signature->begin(), info_.signature->end(), EdgeType::Quantum); | ||
53 | 813400 | return n; | ||
54 | } | |||
55 | 2978 | return any; | ||
56 | } | |||
57 | ||||
58 | ✗ | OptUInt OpDesc::n_boolean() const { | ||
59 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (info_.signature) { | |
60 | ✗ | unsigned n = std::count( | ||
61 | ✗ | info_.signature->begin(), info_.signature->end(), EdgeType::Boolean); | ||
62 | ✗ | return n; | ||
63 | } | |||
64 | ✗ | return any; | ||
65 | } | |||
66 | ||||
67 | ✗ | OptUInt OpDesc::n_classical() const { | ||
68 |
0/2✗ Decision 'true' not taken.
✗ Decision 'false' not taken.
|
✗ | if (info_.signature) { | |
69 | ✗ | unsigned n = std::count( | ||
70 | ✗ | info_.signature->begin(), info_.signature->end(), EdgeType::Classical); | ||
71 | ✗ | return n; | ||
72 | } | |||
73 | ✗ | return any; | ||
74 | } | |||
75 | ||||
76 | 1544 | bool OpDesc::is_meta() const { return is_meta_; } | ||
77 | ||||
78 | 48080 | bool OpDesc::is_box() const { return is_box_; } | ||
79 | ||||
80 | 671159 | bool OpDesc::is_gate() const { return is_gate_; } | ||
81 | ||||
82 | ✗ | bool OpDesc::is_flowop() const { return is_flowop_; } | ||
83 | ||||
84 | ✗ | bool OpDesc::is_classical() const { return is_classical_; } | ||
85 | ||||
86 | 44223 | bool OpDesc::is_rotation() const { return is_rotation_; } | ||
87 | ||||
88 | 23700 | unsigned OpDesc::param_mod(unsigned i) const { return info_.param_mod[i]; } | ||
89 | ||||
90 | 188713 | bool OpDesc::is_oneway() const { return is_oneway_; } | ||
91 | ||||
92 | 18786 | bool OpDesc::is_singleq_unitary() const { | ||
93 |
10/14✓ Branch 1 taken 18786 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18784 times.
✓ Branch 5 taken 2 times.
✓ Branch 7 taken 18784 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 18784 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 15735 times.
✓ Branch 13 taken 3049 times.
✓ Branch 15 taken 15735 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 15722 times.
✓ Branch 18 taken 13 times.
|
18786 | return n_qubits() && n_qubits().value() == 1 && !is_oneway(); | |
94 | } | |||
95 | ||||
96 | ✗ | bool OpDesc::is_clifford_gate() const { return is_clifford_; } | ||
97 | ||||
98 | ✗ | bool OpDesc::is_parameterised_pauli_rotation() const { | ||
99 | ✗ | return is_parameterised_pauli_rotation_; | ||
100 | } | |||
101 | ||||
102 | } // namespace tket | |||
103 |