GCC Code Coverage Report


Directory: ./
File: ArchAwareSynth/include/ArchAwareSynth/Path.hpp
Date: 2022-10-15 05:10:18
Exec Total Coverage
Lines: 2 5 40.0%
Functions: 1 4 25.0%
Branches: 0 4 0.0%
Decisions: 0 0 -%

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 #pragma once
16 #include "Architecture/Architecture.hpp"
17 #include "Placement/Placement.hpp"
18 #include "Utils/MatrixAnalysis.hpp"
19 #include "Utils/UnitID.hpp"
20 namespace tket {
21 namespace aas {
22
23 typedef Eigen::Matrix<unsigned, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
24 MatrixXu;
25
26 class NoHamiltonPath : public std::logic_error {
27 public:
28 3 explicit NoHamiltonPath(const std::string &message)
29 3 : std::logic_error(message) {}
30 };
31
32 /**
33 * Holds distances & paths between nodes -- can optionally remove edges to form
34 * a tree.
35 */
36 class PathHandler {
37 public:
38 PathHandler() {}
39
40 /**
41 * Initialises the pathhandler with a given architecture. Architecture
42 * initialisation assumes symmetric connectivity.
43 * @param arch architecture giving the undirected graph for the initialisation
44 * graph
45 */
46 explicit PathHandler(const Architecture &arch);
47
48 /**
49 * Initialises the pathhandler with a given connectivity matrix. This function
50 * should only be used in the aas code. This function interprets the matrix as
51 * a directed graph.
52 * @param connectivity matrix with the different connections of the directed
53 * graph
54 */
55 explicit PathHandler(const MatrixXb &connectivity);
56
57 /**
58 * Returns a handler for a spanning tree of the architecture.
59 */
60 PathHandler construct_acyclic_handler() const;
61
62 /**
63 * Find a path between two vertices in the architecture.
64 * @param i start node for the path
65 * @param j end node for the path
66 */
67 std::list<unsigned> find_path(unsigned i, unsigned j);
68
69 /**
70 * get connectivity_matrix_ of the pathhandler
71 * @return connectivity_matrix_
72 */
73 MatrixXb get_connectivity_matrix() const;
74
75 /**
76 * get distance_matrix_ of the pathhandler
77 * @return distance_matrix_
78 */
79 MatrixXu get_distance_matrix() const;
80
81 /**
82 * get path_matrix_ of the pathhandler
83 * @return path_matrix_
84 */
85 MatrixXu get_path_matrix() const;
86
87 /**
88 * get size of the pathhandler
89 * @return size
90 */
91 unsigned get_size() const;
92
93 private:
94 MatrixXb connectivity_matrix_;
95 MatrixXu distance_matrix_;
96 MatrixXu path_matrix_;
97 unsigned size;
98 };
99
100 /**
101 * class to calculate and store the iteration order needed for the cnot synth in
102 * the architecture aware synth code. The iteration order makes sure, that the
103 * not yet iterated nodes are still connected.
104 */
105 class IterationOrder {
106 public:
107 IterationOrder() {}
108 /**
109 * construct and calculate the iterationorder.
110 * @param arch given architecture
111 */
112 explicit IterationOrder(const Architecture &arch);
113
114 /**
115 * give the in the constructur calculated iteration order
116 * @return ordered vector of the architecutre in which they can be iterated.
117 */
118 std::vector<Node> get_iterationorder() { return iterationorder; }
119
120 /**
121 * give the in the constructur calculated edges used for the iteration
122 * @return vector of edges pf the architecutre which are used for the
123 * iteration.
124 */
125 std::vector<std::pair<Node, Node>> get_edgelist() { return edgelist; }
126
127 private:
128 std::vector<Node> iterationorder;
129 std::vector<std::pair<Node, Node>> edgelist;
130 };
131
132 /**
133 * Find a Hamiltonian path in the architecture. Timeout is in ms.
134 *
135 * The architecture is always treated as undirected, i.e. the path may traverse
136 * a connection in either direction even if only one direction is specified in
137 * the architecture.
138 *
139 * @param arch architecture where the path is searched
140 * @param timeout give the timeout for the search of the hamiltonpath,
141 * default value is 10000
142 * @return ordered vector of nodes in the path
143 * @throws NoHamiltonPath if no Hamiltonian path is found within timeout
144 */
145 std::vector<Node> find_hampath(const Architecture &arch, long timeout = 10000);
146
147 } // namespace aas
148 } // namespace tket
149