-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_stage.cpp
73 lines (63 loc) · 1.95 KB
/
two_stage.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
#include "main.h"
void SMTSchedule::_add_edge_durations(context &c, SolverType &opt, expr_vector &qx, expr_vector &qy, expr_vector &d){
int j;
Circuit *pC = pCircuit;
Machine *pM = pMachine;
MachineProp *pProp = pM->pProp;
for(j=0; j<pC->nEdges; j++){
int u, v, w;
u = pC->graphEdges[j][0];
v = pC->graphEdges[j][1];
w = pC->graphEdges[j][2];
expr distance = DISTANCE(qx[u], qy[u], qx[v], qy[v]);
opt.add(d[j] == w*( 2*((distance-1)*pProp->gateTime["SWAP"]) + pProp->gateTime["CNOT"]-1) ); //2*swap time + cnot time
//opt.add(d[j] == distance*2*w - w);
}
for(j=0; j<pC->nNodes; j++){
expr_vector myvars(c);
int flag=0;
for(IntVectItr itr = pC->nodeEdgeIds[j].begin();
itr != pC->nodeEdgeIds[j].end();
itr++){
myvars.push_back(d[*itr]);
flag = 1;
}
if(flag){
//opt.add(sum(myvars) < gParams.CNOT_Count_Max);
opt.add(sum(myvars) < gParams.maxTimeSlot);
}else{
cout << "node id" << j << "no d" << endl;
}
}
}
void SMTSchedule::ts_create_mapping_instance(context &c, SolverType &opt){
assert(pCircuit->nQubits <= pMachine->nQubits);
cout << "TwoStage: Creating mapping instance...\n";
//qubit mapping vars
expr_vector qx(c);
expr_vector qy(c);
int i;
for(i=0; i<pCircuit->nQubits; i++){
std::stringstream qx_name;
qx_name << "qx_" << pCircuit->pQubits[i].id;
qx.push_back( c.int_const(qx_name.str().c_str()) );
std::stringstream qy_name;
qy_name << "qy_" << pCircuit->pQubits[i].id;
qy.push_back( c.int_const(qy_name.str().c_str()) );
}
// duration vars
expr_vector d(c);
int j;
for(j=0; j<pCircuit->nEdges; j++){
std::stringstream d_name;
d_name << "d_" << j;
d.push_back( c.int_const(d_name.str().c_str()) );
}
_add_qubit_mapping_bounds(opt, qx, qy); //space to explore
_add_edge_durations(c, opt, qx, qy, d);
if(opt.check() == sat){
model m = opt.get_model();
}else{
cout << "Not sat!\n";
}
}