-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmachine.cpp
91 lines (80 loc) · 2.24 KB
/
machine.cpp
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
#include "main.h"
//up id
int Machine::get_id2uid(int id){
int x = _get_id2i(this, id);
int y = _get_id2j(this, id);
int xp = x-1;
int yp = y;
if(xp >= 0) return (_get_ij2id(this, xp, yp));
else return(INVALID);
}
//down id
int Machine::get_id2did(int id){
int x = _get_id2i(this, id);
int y = _get_id2j(this, id);
int xp = x+1;
int yp = y;
if(xp < nRows) return (_get_ij2id(this, xp, yp));
else return(INVALID);
}
//left id
int Machine::get_id2lid(int id){
int x = _get_id2i(this, id);
int y = _get_id2j(this, id);
int xp = x;
int yp = y-1;
if(yp >= 0) return (_get_ij2id(this, xp, yp));
else return(INVALID);
}
//right id
int Machine::get_id2rid(int id){
int x = _get_id2i(this, id);
int y = _get_id2j(this, id);
int xp = x;
int yp = y+1;
if(yp < nCols) return (_get_ij2id(this, xp, yp));
else return(INVALID);
}
void Machine::_add_neighbor_if_valid(HwQubit *pQ, int id){
if(id != INVALID) pQ->pEdgeList[pQ->nEdges++] = pQubitList + id;
}
void Machine::setup_grid_transmons(int m, int n){
nRows = m;
nCols = n;
nQubits = m*n;
pQubitList = new HwQubit[nQubits];
int i;
HwQubit *pQ;
cout << "nrows: " << nRows << " nCols: " << nCols << "\n";
for(i=0; i<nQubits; i++){
pQ = pQubitList + i;
// position of this qubit
pQ->id = i;
pQ->pos_x = _get_id2i(this, i);
pQ->pos_y = _get_id2j(this, i);
// add edges for this qubit
pQ->nEdges = 0;
_add_neighbor_if_valid(pQ, get_id2uid(i));
_add_neighbor_if_valid(pQ, get_id2did(i));
_add_neighbor_if_valid(pQ, get_id2lid(i));
_add_neighbor_if_valid(pQ, get_id2rid(i));
}
}
void Machine::setup_gate_times(){
pProp = new MachineProp;
pProp->gateTime["CNOT"] = gParams.time_CNOT;
pProp->gateTime["X"] = gParams.time_X;
pProp->gateTime["Y"] = gParams.time_Y;
pProp->gateTime["H"] = gParams.time_H;
pProp->gateTime["MeasZ"] = gParams.time_MeasZ;
//derived time
pProp->gateTime["SWAP"] = (gParams.time_CNOT * 3) + (gParams.time_H * 2);
/* TODO below times are actually 0, they are software gates */
pProp->gateTime["Z"] = 1;
pProp->gateTime["S"] = 1;
pProp->gateTime["Sdag"] = 1;
pProp->gateTime["T"] = 1;
pProp->gateTime["Tdag"] = 1;
pProp->gateTime["PrepZ"] = 1;
pProp->gateTime["MeasZ"] = 1;
}