| 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 "MetaOp.hpp" | |||
| 16 | ||||
| 17 | #include <typeinfo> | |||
| 18 | ||||
| 19 | #include "OpType/EdgeType.hpp" | |||
| 20 | #include "OpType/OpType.hpp" | |||
| 21 | #include "Utils/Json.hpp" | |||
| 22 | ||||
| 23 | namespace tket { | |||
| 24 | ||||
| 25 | 769531 | MetaOp::MetaOp(OpType type, op_signature_t signature, const std::string& _data) | ||
| 26 |
2/4✓ Branch 2 taken 769531 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 769531 times.
✗ Branch 6 not taken.
|
769531 | : Op(type), signature_(signature), data_(_data) { | |
| 27 |
2/6✓ Branch 1 taken 769531 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 769531 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
|
1/2✓ Decision 'true' taken 769531 times.
✗ Decision 'false' not taken.
|
769531 | if (!is_metaop_type(type)) throw BadOpType(type); |
| 28 | 769531 | } | ||
| 29 | ||||
| 30 | 900 | Op_ptr MetaOp::symbol_substitution(const SymEngine::map_basic_basic&) const { | ||
| 31 | 900 | return Op_ptr(); | ||
| 32 | } | |||
| 33 | ||||
| 34 | 672 | SymSet MetaOp::free_symbols() const { return {}; } | ||
| 35 | ||||
| 36 | 5 | unsigned MetaOp::n_qubits() const { | ||
| 37 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | OptUInt n = desc_.n_qubits(); | |
| 38 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
1/2✓ Decision 'true' taken 5 times.
✗ Decision 'false' not taken.
|
5 | if (n == any) { |
| 39 |
1/2✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
|
5 | return std::count(signature_.begin(), signature_.end(), EdgeType::Quantum); | |
| 40 | } else { | |||
| 41 | ✗ | return n.value(); | ||
| 42 | } | |||
| 43 | } | |||
| 44 | ||||
| 45 | 1248 | op_signature_t MetaOp::get_signature() const { | ||
| 46 |
1/2✓ Branch 1 taken 1248 times.
✗ Branch 2 not taken.
|
1248 | std::optional<op_signature_t> sig = desc_.signature(); | |
| 47 |
2/2✓ Branch 1 taken 1138 times.
✓ Branch 2 taken 110 times.
|
2/2✓ Decision 'true' taken 1138 times.
✓ Decision 'false' taken 110 times.
|
1248 | if (sig) |
| 48 |
1/2✓ Branch 2 taken 1138 times.
✗ Branch 3 not taken.
|
1138 | return *sig; | |
| 49 | else | |||
| 50 |
1/2✓ Branch 1 taken 110 times.
✗ Branch 2 not taken.
|
110 | return signature_; | |
| 51 | 1248 | } | ||
| 52 | ||||
| 53 | 2 | nlohmann::json MetaOp::serialize() const { | ||
| 54 | 2 | nlohmann::json j; | ||
| 55 |
2/4✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 2 times.
✗ Branch 6 not taken.
|
2 | j["type"] = get_type(); | |
| 56 |
3/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | j["signature"] = get_signature(); | |
| 57 |
3/6✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 2 times.
✗ Branch 8 not taken.
|
2 | j["data"] = get_data(); | |
| 58 | 2 | return j; | ||
| 59 | } | |||
| 60 | ||||
| 61 | 2 | Op_ptr MetaOp::deserialize(const nlohmann::json& j) { | ||
| 62 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | OpType optype = j.at("type").get<OpType>(); | |
| 63 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | op_signature_t sig = j.at("signature").get<op_signature_t>(); | |
| 64 | 2 | std::string data; | ||
| 65 | try { | |||
| 66 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | data = j.at("data").get<std::string>(); | |
| 67 | ✗ | } catch (const nlohmann::json::out_of_range& e) { | ||
| 68 | ✗ | data = ""; | ||
| 69 | } | |||
| 70 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return std::make_shared<MetaOp>(optype, sig, data); | |
| 71 | 2 | } | ||
| 72 | ||||
| 73 | 41 | bool MetaOp::is_clifford() const { return true; } | ||
| 74 | ||||
| 75 | 1539062 | MetaOp::~MetaOp() {} | ||
| 76 | ||||
| 77 | 7 | bool MetaOp::is_equal(const Op& op_other) const { | ||
| 78 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | const MetaOp& other = dynamic_cast<const MetaOp&>(op_other); | |
| 79 |
2/4✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
|
7 | return (get_signature() == other.get_signature()); | |
| 80 | } | |||
| 81 | ||||
| 82 | ✗ | MetaOp::MetaOp() : Op(OpType::Barrier) {} | ||
| 83 | ||||
| 84 | } // namespace tket | |||
| 85 |