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 "UnitID.hpp" | |||
16 | ||||
17 | #include <sstream> | |||
18 | ||||
19 | #include "Json.hpp" | |||
20 | ||||
21 | namespace tket { | |||
22 | ||||
23 | 1821 | std::string UnitID::repr() const { | ||
24 |
1/2✓ Branch 1 taken 1821 times.
✗ Branch 2 not taken.
|
1821 | std::stringstream str; | |
25 |
1/2✓ Branch 2 taken 1821 times.
✗ Branch 3 not taken.
|
1821 | str << data_->name_; | |
26 |
2/2✓ Branch 2 taken 1820 times.
✓ Branch 3 taken 1 times.
|
2/2✓ Decision 'true' taken 1820 times.
✓ Decision 'false' taken 1 times.
|
1821 | if (!data_->index_.empty()) { |
27 |
3/6✓ Branch 1 taken 1820 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 1820 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1820 times.
✗ Branch 10 not taken.
|
1820 | str << "[" << std::to_string(data_->index_[0]); | |
28 |
2/2✓ Branch 2 taken 97 times.
✓ Branch 3 taken 1820 times.
|
2/2✓ Decision 'true' taken 97 times.
✓ Decision 'false' taken 1820 times.
|
1917 | for (unsigned i = 1; i < data_->index_.size(); i++) { |
29 |
3/6✓ Branch 1 taken 97 times.
✗ Branch 2 not taken.
✓ Branch 6 taken 97 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 97 times.
✗ Branch 10 not taken.
|
97 | str << ", " << std::to_string(data_->index_[i]); | |
30 | } | |||
31 |
1/2✓ Branch 1 taken 1820 times.
✗ Branch 2 not taken.
|
1820 | str << "]"; | |
32 | } | |||
33 |
1/2✓ Branch 1 taken 1821 times.
✗ Branch 2 not taken.
|
3642 | return str.str(); | |
34 | 1821 | } | ||
35 | ||||
36 | 435 | void to_json(nlohmann::json& j, const Qubit& qb) { unitid_to_json(j, qb); } | ||
37 | 3356 | void from_json(const nlohmann::json& j, Qubit& qb) { json_to_unitid(j, qb); } | ||
38 | ||||
39 | 54 | void to_json(nlohmann::json& j, const Bit& cb) { unitid_to_json(j, cb); } | ||
40 | 38 | void from_json(const nlohmann::json& j, Bit& cb) { json_to_unitid(j, cb); } | ||
41 | ||||
42 | 6660 | void to_json(nlohmann::json& j, const Node& node) { unitid_to_json(j, node); } | ||
43 | 866 | void from_json(const nlohmann::json& j, Node& node) { json_to_unitid(j, node); } | ||
44 | ||||
45 | 42 | void to_json(nlohmann::json& j, const qubit_map_t& qm) { | ||
46 |
2/2✓ Branch 5 taken 92 times.
✓ Branch 6 taken 42 times.
|
2/2✓ Decision 'true' taken 92 times.
✓ Decision 'false' taken 42 times.
|
134 | for (const auto& pair : qm) { |
47 | 92 | nlohmann::json qm_j; | ||
48 |
2/4✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 92 times.
✗ Branch 5 not taken.
|
92 | qm_j.push_back(pair.first); | |
49 |
2/4✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 92 times.
✗ Branch 5 not taken.
|
92 | qm_j.push_back(pair.second); | |
50 |
1/2✓ Branch 1 taken 92 times.
✗ Branch 2 not taken.
|
92 | j.push_back(qm_j); | |
51 | 92 | } | ||
52 | 42 | } | ||
53 | 24 | void from_json(const nlohmann::json& j, qubit_map_t& qm) { | ||
54 |
5/8✓ Branch 3 taken 73 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 73 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 97 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 73 times.
✓ Branch 12 taken 24 times.
|
0/1? Decision couldn't be analyzed.
|
97 | for (const nlohmann::json& j_pair : j) { |
55 |
1/2✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
|
73 | const auto& qb_pair = j_pair.get<std::pair<Qubit, Qubit>>(); | |
56 |
1/2✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
|
73 | qm.insert(qb_pair); | |
57 | 73 | } | ||
58 | 24 | } | ||
59 | ||||
60 | /* The functions below use the "construct on first use" idiom to return "global" | |||
61 | * objects. They use pointers to ensure that the objects returned last | |||
62 | * throughout static initialization and deinitialization. There is no memory | |||
63 | * leak since the objects are only constructed once and the memory is reclaimed | |||
64 | * on program termination. | |||
65 | */ | |||
66 | ||||
67 | 2088000 | const std::string& q_default_reg() { | ||
68 | static std::unique_ptr<const std::string> regname = | |||
69 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2087999 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
2088000 | std::make_unique<const std::string>("q"); | |
70 | 2088000 | return *regname; | ||
71 | } | |||
72 | ||||
73 | 227010 | const std::string& c_default_reg() { | ||
74 | static std::unique_ptr<const std::string> regname = | |||
75 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 227009 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
227010 | std::make_unique<const std::string>("c"); | |
76 | 227010 | return *regname; | ||
77 | } | |||
78 | ||||
79 | 315530 | const std::string& node_default_reg() { | ||
80 | static std::unique_ptr<const std::string> regname = | |||
81 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 315529 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
315530 | std::make_unique<const std::string>("node"); | |
82 | 315530 | return *regname; | ||
83 | } | |||
84 | ||||
85 | 25 | const std::string& c_debug_zero_prefix() { | ||
86 | static std::unique_ptr<const std::string> regname = | |||
87 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 24 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
25 | std::make_unique<const std::string>("tk_DEBUG_ZERO_REG"); | |
88 | 25 | return *regname; | ||
89 | } | |||
90 | ||||
91 | 17 | const std::string& c_debug_one_prefix() { | ||
92 | static std::unique_ptr<const std::string> regname = | |||
93 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 16 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
17 | std::make_unique<const std::string>("tk_DEBUG_ONE_REG"); | |
94 | 17 | return *regname; | ||
95 | } | |||
96 | ||||
97 | 20 | const std::string& c_debug_default_name() { | ||
98 | static std::unique_ptr<const std::string> regname = | |||
99 |
4/8✓ Branch 0 taken 1 times.
✓ Branch 1 taken 19 times.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 times.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
20 | std::make_unique<const std::string>("tket_assert"); | |
100 | 20 | return *regname; | ||
101 | } | |||
102 | ||||
103 | } // namespace tket | |||
104 |