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 | ||||
17 | #include <list> | |||
18 | #include <optional> | |||
19 | #include <set> | |||
20 | #include <string> | |||
21 | #include <unordered_map> | |||
22 | #include <unordered_set> | |||
23 | #include <utility> | |||
24 | #include <vector> | |||
25 | ||||
26 | #include "OpType/EdgeType.hpp" | |||
27 | #include "Ops/Op.hpp" | |||
28 | #include "Utils/GraphHeaders.hpp" | |||
29 | ||||
30 | namespace tket { | |||
31 | ||||
32 | /** Description of a node in a circuit, representing some operation */ | |||
33 | struct VertexProperties { | |||
34 | Op_ptr op; /**< operation */ | |||
35 | std::optional<std::string> opgroup; /**< operation group identfier */ | |||
36 | ||||
37 | 5484755 | VertexProperties( | ||
38 | Op_ptr op = 0, std::optional<std::string> opgroup = std::nullopt) | |||
39 |
1/2✓ Branch 2 taken 5484755 times.
✗ Branch 3 not taken.
|
5484755 | : op(op), opgroup(opgroup) {} | |
40 | }; | |||
41 | ||||
42 | /** A specific entry or exit port of a vertex */ | |||
43 | typedef unsigned port_t; | |||
44 | ||||
45 | /** Whether a vertex port is out-going (source) or in-coming (target) */ | |||
46 | enum class PortType { Source, Target }; | |||
47 | ||||
48 | /** Description of an edge in a circuit, representing a directional wire */ | |||
49 | struct EdgeProperties { | |||
50 | EdgeType type; /**< type of wire */ | |||
51 | std::pair<port_t, port_t> ports; | |||
52 | }; | |||
53 | ||||
54 | /** Graph representing a circuit, with operations as nodes. */ | |||
55 | typedef boost::adjacency_list< | |||
56 | // OutEdgeList | |||
57 | boost::listS, | |||
58 | ||||
59 | // VertexList (use listS because we want to be able to remove vertices | |||
60 | // without invalidating iterators) | |||
61 | boost::listS, | |||
62 | ||||
63 | // we want access to incoming and outgoing edges | |||
64 | boost::bidirectionalS, | |||
65 | ||||
66 | // indexing needed for algorithms such as topological sort | |||
67 | boost::property<boost::vertex_index_t, int, VertexProperties>, | |||
68 | ||||
69 | EdgeProperties> | |||
70 | DAG; | |||
71 | ||||
72 | typedef boost::graph_traits<DAG>::vertex_descriptor Vertex; | |||
73 | typedef boost::graph_traits<DAG>::vertex_iterator V_iterator; | |||
74 | typedef std::unordered_set<Vertex> VertexSet; | |||
75 | typedef std::vector<Vertex> VertexVec; | |||
76 | typedef std::list<Vertex> VertexList; | |||
77 | typedef std::unordered_map<Vertex, unsigned> IndexMap; | |||
78 | typedef boost::adj_list_vertex_property_map< | |||
79 | DAG, int, int&, boost::vertex_index_t> | |||
80 | VIndex; | |||
81 | ||||
82 | /** | |||
83 | * A vertex with an index. | |||
84 | * | |||
85 | * This can be used instead of a plain @ref Vertex in associative containers | |||
86 | * where control over the order of iteration is required. | |||
87 | */ | |||
88 | typedef std::pair<unsigned, Vertex> IVertex; | |||
89 | ||||
90 | typedef boost::graph_traits<DAG>::edge_descriptor Edge; | |||
91 | typedef boost::graph_traits<DAG>::edge_iterator E_iterator; | |||
92 | typedef DAG::in_edge_iterator E_in_iterator; | |||
93 | typedef DAG::out_edge_iterator E_out_iterator; | |||
94 | typedef std::set<Edge> EdgeSet; | |||
95 | typedef std::vector<Edge> EdgeVec; | |||
96 | typedef std::list<Edge> EdgeList; | |||
97 | ||||
98 | typedef std::pair<Vertex, port_t> VertPort; | |||
99 | ||||
100 | } // namespace tket | |||
101 |