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 "UnitaryTableauBox.hpp" | |||
16 | ||||
17 | #include "Ops/OpJsonFactory.hpp" | |||
18 | ||||
19 | namespace tket { | |||
20 | ||||
21 | 6 | UnitaryTableauBox::UnitaryTableauBox(const UnitaryTableau& tab) | ||
22 |
2/4✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 6 times.
✗ Branch 7 not taken.
|
6 | : Box(OpType::UnitaryTableauBox), tab_(tab) { | |
23 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | std::set<Qubit> tab_qbs = tab_.get_qubits(); | |
24 | 6 | std::set<Qubit> qbs; | ||
25 |
2/2✓ Branch 1 taken 18 times.
✓ Branch 2 taken 6 times.
|
2/2✓ Decision 'true' taken 18 times.
✓ Decision 'false' taken 6 times.
|
24 | for (unsigned i = 0; i < tab_qbs.size(); ++i) { |
26 |
2/4✓ Branch 1 taken 18 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
|
18 | qbs.insert(Qubit(i)); | |
27 | } | |||
28 |
2/4✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
1/2✗ Decision 'true' not taken.
✓ Decision 'false' taken 6 times.
|
6 | if (tab_qbs != qbs) |
29 | ✗ | throw std::invalid_argument( | ||
30 | "UnitaryTableauBox requires tableau qubits to have default, " | |||
31 | ✗ | "consecutive indexing"); | ||
32 | 6 | } | ||
33 | ||||
34 | 1 | UnitaryTableauBox::UnitaryTableauBox( | ||
35 | const MatrixXb& xx, const MatrixXb& xz, const VectorXb& xph, | |||
36 | 1 | const MatrixXb& zx, const MatrixXb& zz, const VectorXb& zph) | ||
37 |
2/4✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
|
1 | : Box(OpType::UnitaryTableauBox), tab_(xx, xz, xph, zx, zz, zph) {} | |
38 | ||||
39 | 1 | Op_ptr UnitaryTableauBox::dagger() const { | ||
40 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return std::make_shared<const UnitaryTableauBox>(tab_.dagger()); | |
41 | } | |||
42 | ||||
43 | 1 | Op_ptr UnitaryTableauBox::transpose() const { | ||
44 |
1/2✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
|
1 | return std::make_shared<const UnitaryTableauBox>(tab_.transpose()); | |
45 | } | |||
46 | ||||
47 | ✗ | Op_ptr UnitaryTableauBox::symbol_substitution( | ||
48 | const SymEngine::map_basic_basic&) const { | |||
49 | ✗ | return Op_ptr(); | ||
50 | } | |||
51 | ||||
52 | ✗ | SymSet UnitaryTableauBox::free_symbols() const { return SymSet(); } | ||
53 | ||||
54 | 1 | bool UnitaryTableauBox::is_equal(const Op& op_other) const { | ||
55 | const UnitaryTableauBox& other = | |||
56 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | dynamic_cast<const UnitaryTableauBox&>(op_other); | |
57 | 1 | return this->tab_ == other.tab_; | ||
58 | } | |||
59 | ||||
60 | 1 | const UnitaryTableau& UnitaryTableauBox::get_tableau() const { return tab_; } | ||
61 | ||||
62 | 1 | nlohmann::json UnitaryTableauBox::to_json(const Op_ptr& op) { | ||
63 | 1 | const auto& box = static_cast<const UnitaryTableauBox&>(*op); | ||
64 | 1 | nlohmann::json j = core_box_json(box); | ||
65 |
3/6✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
|
1 | j["tab"] = box.get_tableau(); | |
66 | 1 | return j; | ||
67 | } | |||
68 | ||||
69 | 1 | Op_ptr UnitaryTableauBox::from_json(const nlohmann::json& j) { | ||
70 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | UnitaryTableau tab(0); | |
71 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
1 | j.at("tab").get_to(tab); | |
72 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return std::make_shared<const UnitaryTableauBox>(tab); | |
73 | 1 | } | ||
74 | ||||
75 | REGISTER_OPFACTORY(UnitaryTableauBox, UnitaryTableauBox) | |||
76 | ||||
77 | 11 | op_signature_t UnitaryTableauBox::get_signature() const { | ||
78 |
2/4✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 11 times.
✗ Branch 7 not taken.
|
22 | return op_signature_t(tab_.get_qubits().size(), EdgeType::Quantum); | |
79 | } | |||
80 | ||||
81 | 3 | void UnitaryTableauBox::generate_circuit() const { | ||
82 |
1/2✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
3 | circ_ = std::make_shared<Circuit>(unitary_tableau_to_circuit(tab_)); | |
83 | 3 | } | ||
84 | ||||
85 | } // namespace tket | |||
86 |