| 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 "Combinator.hpp" | |||
| 16 | ||||
| 17 | #include <memory> | |||
| 18 | ||||
| 19 | #include "Transform.hpp" | |||
| 20 | ||||
| 21 | namespace tket { | |||
| 22 | ||||
| 23 | 22333 | Transform operator>>(const Transform &lhs, const Transform &rhs) { | ||
| 24 |
3/6✓ Branch 1 taken 22333 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 22333 times.
✗ Branch 5 not taken.
✓ Branch 8 taken 22333 times.
✗ Branch 9 not taken.
|
89332 | std::vector<Transform> l = {lhs, rhs}; | |
| 25 |
1/2✓ Branch 1 taken 22333 times.
✗ Branch 2 not taken.
|
44666 | return Transforms::sequence(l); | |
| 26 | 22333 | } | ||
| 27 | ||||
| 28 | namespace Transforms { | |||
| 29 | ||||
| 30 | 22334 | Transform sequence(std::vector<Transform> &tvec) { | ||
| 31 | 23196 | return Transform([=](Circuit &circ, std::shared_ptr<unit_bimaps_t> maps) { | ||
| 32 | 23196 | bool success = false; | ||
| 33 | 23196 | for (std::vector<Transform>::const_iterator it = tvec.begin(); | ||
| 34 |
2/2✓ Branch 2 taken 46393 times.
✓ Branch 3 taken 23196 times.
|
69589 | it != tvec.end(); ++it) { | |
| 35 |
6/10✓ Branch 3 taken 46393 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 5225 times.
✓ Branch 6 taken 41168 times.
✓ Branch 7 taken 2913 times.
✓ Branch 8 taken 2312 times.
✓ Branch 9 taken 46393 times.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
|
46393 | success = it->apply_fn(circ, maps) || success; | |
| 36 | } | |||
| 37 | 23196 | return success; | ||
| 38 |
2/4✓ Branch 2 taken 22334 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 22334 times.
✗ Branch 6 not taken.
|
22334 | }); | |
| 39 | } | |||
| 40 | ||||
| 41 | 132 | Transform repeat(const Transform &trans) { | ||
| 42 | 300 | return Transform([=](Circuit &circ, std::shared_ptr<unit_bimaps_t> maps) { | ||
| 43 | 300 | bool success = false; | ||
| 44 |
3/4✓ Branch 2 taken 397 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 97 times.
✓ Branch 6 taken 300 times.
|
0/1? Decision couldn't be analyzed.
|
397 | while (trans.apply_fn(circ, maps)) success = true; |
| 45 | 300 | return success; | ||
| 46 |
2/4✓ Branch 2 taken 132 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 132 times.
✗ Branch 6 not taken.
|
132 | }); | |
| 47 | } | |||
| 48 | ||||
| 49 | 96 | Transform repeat_with_metric( | ||
| 50 | const Transform &trans, const Transform::Metric &eval) { | |||
| 51 | 121 | return Transform([=](Circuit &circ, std::shared_ptr<unit_bimaps_t> maps) { | ||
| 52 | 121 | bool success = false; | ||
| 53 |
1/2✓ Branch 1 taken 121 times.
✗ Branch 2 not taken.
|
121 | int currentVal = eval(circ); | |
| 54 | 121 | Circuit *currentCircuit = ˆ | ||
| 55 |
1/2✓ Branch 1 taken 121 times.
✗ Branch 2 not taken.
|
121 | Circuit newCircuit = circ; | |
| 56 |
1/2✓ Branch 2 taken 121 times.
✗ Branch 3 not taken.
|
121 | trans.apply_fn(newCircuit, maps); | |
| 57 |
1/2✓ Branch 1 taken 121 times.
✗ Branch 2 not taken.
|
121 | int newVal = eval(newCircuit); | |
| 58 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 121 times.
|
2/2✓ Decision 'true' taken 24 times.
✓ Decision 'false' taken 121 times.
|
145 | while (newVal < currentVal) { |
| 59 | 24 | currentCircuit = &newCircuit; | ||
| 60 | 24 | currentVal = newVal; | ||
| 61 | 24 | success = true; | ||
| 62 |
1/2✓ Branch 2 taken 24 times.
✗ Branch 3 not taken.
|
24 | trans.apply_fn(newCircuit, maps); | |
| 63 |
1/2✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
|
24 | newVal = eval(newCircuit); | |
| 64 | } | |||
| 65 |
3/4✓ Branch 0 taken 23 times.
✓ Branch 1 taken 98 times.
✓ Branch 3 taken 23 times.
✗ Branch 4 not taken.
|
1/2✓ Decision 'true' taken 121 times.
✗ Decision 'false' not taken.
|
121 | if (&circ != currentCircuit) circ = *currentCircuit; |
| 66 | 121 | return success; | ||
| 67 |
2/4✓ Branch 3 taken 96 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 96 times.
✗ Branch 7 not taken.
|
217 | }); | |
| 68 | } | |||
| 69 | ||||
| 70 | ✗ | Transform repeat_while(const Transform &cond, const Transform &body) { | ||
| 71 | ✗ | return Transform([=](Circuit &circ, std::shared_ptr<unit_bimaps_t> maps) { | ||
| 72 | ✗ | bool success = false; | ||
| 73 |
0/1? Decision couldn't be analyzed.
|
✗ | while (cond.apply_fn(circ, maps)) { | |
| 74 | ✗ | success = true; | ||
| 75 | ✗ | body.apply_fn(circ, maps); | ||
| 76 | } | |||
| 77 | ✗ | return success; | ||
| 78 | ✗ | }); | ||
| 79 | } | |||
| 80 | ||||
| 81 | } // namespace Transforms | |||
| 82 | ||||
| 83 | } // namespace tket | |||
| 84 |