/
layout.py
219 lines (189 loc) · 6.04 KB
/
layout.py
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
import _qca
from collections import OrderedDict
import math
class Layout(object):
def __init__(self):
self._pl = _qca.Layout()
@property
def primitive_layout(self):
return self._pl
def __getstate__(self):
i = OrderedDict()
# This can be very verbose, disabled for now.
# i['r_sites'] = self._pl.r_sites
# i['r_charges'] = self._pl.r_charges
# i['charges'] = self._pl.charges
# i['epc'] = str(self._pl.epc)
return i
def __setstate__(self, i):
# we do not deserialize properly
# TODO: properly reconstruct state
self.__init__()
def coma_getstate(self):
return self.__getstate__()
def coma_setstate(self, i):
self.__setstate__(i)
def __eq__(self, l):
d1 = self.__dict__.copy()
d2 = l.__dict__.copy()
pl1 = d1['_pl']
pl2 = d2['_pl']
del d1['_pl']
del d2['_pl']
return (d1 == d2 and
pl1.r_sites == pl2.r_sites and
pl1.r_charges == pl2.r_charges and
pl1.charges == pl2.charges and
pl1.epc == pl2.epc)
class Wire(Layout):
def __init__(self, N_, V1_, boa_, P_):
Layout.__init__(self)
self.N = N_
self.V1 = V1_
self.boa = boa_
self.P = P_
self._pl.wire(N_, 1.0/V1_, boa_ * 1.0 / V1_, P_)
def __getstate__(self):
i = OrderedDict()
i['type'] = 'wire'
i['N'] = self.N
i['V1'] = self.V1
i['boa'] = self.boa
i['P'] = self.P
i.update(Layout.__getstate__(self))
return i
def __setstate__(self, i):
self.__init__(i['N'], i['V1'], i['boa'], i['P'])
class NonuniformWire(Layout):
def __init__(self, N_, V1_, boas_, P_):
Layout.__init__(self)
self.N = N_
self.V1 = V1_
self.boas = boas_
self.P = P_
a = 1.0 / V1_
bs = [boa * a for boa in boas_]
self._pl.nonuniformWire(N_, a, bs, P_)
def __getstate__(self):
i = OrderedDict()
i['type'] = 'nonuniformwire'
i['N'] = self.N
i['V1'] = self.V1
i['boas'] = self.boas
i['P'] = self.P
i.update(Layout.__getstate__(self))
return i
def __setstate__(self, i):
self.__init__(i['N'], i['V1'], i['boas'], i['P'])
class WireWithTwoDriverCells(Layout):
def __init__(self, N_, V1_, boa_, P1_, P2_):
Layout.__init__(self)
self.N = N_
self.V1 = V1_
self.boa = boa_
self.P1 = P1_
self.P2 = P2_
a = 1.0 / self.V1
b = self.boa * a
for i in range(self.N):
self._pl.addCell((a+b)*i, 0, a)
self._pl.addDriverCell(-b-a, 0, a, self.P1)
self._pl.addDriverCell(self.N*(b+a), 0, a, self.P2)
def __getstate__(self):
i = OrderedDict()
i['type'] = 'wire_with_two_driver_cells'
i['N'] = self.N
i['V1'] = self.V1
i['boa'] = self.boa
i['P1'] = self.P1
i['P2'] = self.P2
i.update(Layout.__getstate__(self))
return i
def __setstate__(self, i):
self.__init__(i['N'], i['V1'], i['boa'], i['P1'], i['P2'])
class NonuniformWireWithTwoDriverCells(Layout):
def __init__(self, N_, V1_, boas_, P1_, P2_):
Layout.__init__(self)
self.N = N_
self.V1 = V1_
self.boas = boas_
self.P1 = P1_
self.P2 = P2_
assert len(self.boas) == self.N+1
a = 1.0 / self.V1
bs = [boa * a for boa in self.boas]
x_off = 0
self._pl.addDriverCell(x_off, 0, a, self.P1)
x_off += bs[0]+a
for b in bs[1:]:
self._pl.addCell(x_off, 0, a)
x_off += b+a
self._pl.addDriverCell(x_off, 0, a, self.P2)
def __getstate__(self):
i = OrderedDict()
i['type'] = 'nonuniformwire_with_two_driver_cells'
i['N'] = self.N
i['V1'] = self.V1
i['boas'] = self.boas
i['P1'] = self.P1
i['P2'] = self.P2
i.update(Layout.__getstate__(self))
return i
def __setstate__(self, i):
self.__init__(i['N'], i['V1'], i['boas'], i['P1'], i['P2'])
class InfiniteWire(Layout):
def __init__(self, N_, N_dead_, V1_, boa_, P_):
Layout.__init__(self)
self.N = N_
self.N_dead = N_dead_
self.V1 = V1_
self.boa = boa_
self.P = P_
self.construct_wire()
def construct_wire(self):
a = 1.0 / self.V1
b = self.boa * a
for i in range(0, self.N_dead):
self._pl.addDriverCell(i*(b+a), 0, a, self.P)
for i in range(self.N_dead, self.N_dead + self.N):
self._pl.addCell(i*(b+a), 0, a)
for i in range(self.N_dead + self.N, 2*self.N_dead + self.N):
self._pl.addDriverCell(i*(b+a), 0, a, self.P)
def __getstate__(self):
i = OrderedDict()
i['type'] = 'infinite_wire'
i['N'] = self.N
i['N_dead'] = self.N_dead
i['V1'] = self.V1
i['boa'] = self.boa
i['P'] = self.P
i.update(Layout.__getstate__(self))
return i
def __setstate__(self, i):
self.__init__(i['N'], i['N_dead'], i['V1'], i['boa'], i['P'])
class AngleWire(Layout):
def __init__(self, N_, V1_, doa_, theta_, P_):
Layout.__init__(self)
self.N = N_
self.V1 = V1_
self.doa = doa_
self.theta = theta_
self.P = P_
a = 1.0 / self.V1
d = self.doa * a
t = self.theta*math.pi/180.0
self._pl.addDriverCell(0, 0, a, self.P)
for i in range(1,self.N+1):
self._pl.addCell(d*math.cos(t)*i, d*math.sin(t)*i, a)
def __getstate__(self):
i = OrderedDict()
i['type'] = 'angle_wire'
i['N'] = self.N
i['V1'] = self.V1
i['doa'] = self.doa
i['theta'] = self.theta
i['P'] = self.P
i.update(Layout.__getstate__(self))
return i
def __setstate__(self, i):
self.__init__(i['N'], i['V1'], i['doa'], i['theta'], i['P'])