-
Notifications
You must be signed in to change notification settings - Fork 1
/
initial_mapping.h
131 lines (103 loc) · 3.02 KB
/
initial_mapping.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <utility>
#include <algorithm>
#include <queue>
#include <bitset>
#include <boost/graph/undirected_graph.hpp>
#include <boost/variant/get.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/connected_components.hpp>
using namespace std;
const float ROUNDING_ERROR_f32 = 0.000001f;
inline bool equals(const float a, const float b, const float tolerance = ROUNDING_ERROR_f32);
class ChipTopology{
private:
public:
ChipTopology();
~ChipTopology();
pair<std::vector<int>, float> shortest_path_AG(int source, int destination) {std::vector<int> tmp; tmp.push_back(0); tmp.push_back(1);return make_pair(tmp,1.0);};
std::vector<std::vector<pair<std::vector<int>, float>>> shortest_path_AG_map;
int num_qubit = 2;
int diameter = 3;
};
struct CircuitGate{
std::string gate_name;
int num_qubit;
std::vector<int> logic_qubit_list;
std::vector<int> virtual_qubit_list;
std::vector<int> physic_qubit_list;
std::vector<float> experssion_list;
};
class QubitData{
public:
std::string vertex_name;
int num;
};
class Gate{
public:
};
class UnaryGate : public Gate{
public:
std::string gate_name;
int m_qubit;
std::vector<float> expression_list;
};
class BinaryGate : public Gate{
public:
std::string gate_name;
int circuit_list_index;
int m_fromqubit;
int m_toqubit;
vector<UnaryGate*> m_from_followings;
vector<UnaryGate*> m_to_followings;
int circuit_graph_index;
std::vector<float> expression_list;
};
class EdgeData{
public:
std::string edge_name;
double dist;
};
class CircuitGraph:public boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, BinaryGate, EdgeData>{
private:
public:
CircuitGraph(ChipTopology* AG, std::vector<CircuitGate> circuit_gate_list);
~CircuitGraph();
int num_qubit_logical;
std::vector<int> first_nodes;
int node_cnt;
std::vector<UnaryGate*> single_gates_before_first_layer;
std::vector<std::vector<int> > gate_for_qubit;
private:
};
class Initial_Mapping{
public:
Initial_Mapping(CircuitGraph* CG, ChipTopology* AG);
virtual ~Initial_Mapping(){}
public:
std::vector<int> get_initial_mapping();
protected:
void compute_initial_mapping();
private:
std::vector<int> CANDI;
static double ALPHA, BETA, GAMMA;
protected:
CircuitGraph* m_p_CG;
ChipTopology* m_p_AG;
double m_best_h;
std::vector<int> m_best_map;
bool m_best_map_available;
private:
std::vector<int> m_tmp_log_to_phy;
std::vector<int> m_tmp_phy_to_log;
std::vector<int> m_tmp_valid;
std::vector<std::priority_queue<std::pair<double, int> > > m_tmp_que;
std::vector<int> m_tmp_c;
std::vector<int> m_tmp_in_degree;
std::vector<int> m_tmp_front_layer;
void dfs(int pos);
void update();
void swap_map(int x, int y);
std::vector<int> find_exe_gate();
double cost_h();
};