forked from Youngkyu-Sung/sonpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonpy.py
2946 lines (2544 loc) · 131 KB
/
sonpy.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
__license__ = 'GNU General Public License 3.0'
__docformat__ = 'reStructuredText'
import subprocess
import time
import os
from win32com.client import GetObject
class Project():
# Only geometry projects are supported
def __init__(self):
self.preheader = None
self.header = None
self.dim = None
self.geo = None
self.control = None
self.freq = None
self.opt = None
self.varswp = None
self.fileout = None
self.subdiv = None
self.qsg = None
class Preheader():
def __init__(self):
self.lines = []
class Header():
def __init__(self):
self.lines = []
class Dim():
def __init__(self):
self.lines = []
class Geo():
def __init__(self):
self.tmet = None
self.bmet = None
self.met = None
self.box = None
self.bricks = [] # Stores list of brick materials
self.dlayers = []
self.valvars = []
self.lorgn = None
self.npoly = None
class Tmet():
def __init__(self):
self.name = "Lossless"
self.patternid = 0
self.type = "SUP"
self.values = [0, 0, 0, 0]
class Bmet():
def __init__(self):
self.name = "Lossless"
self.patternid = 0
self.type = "SUP"
self.values = [0, 0, 0, 0]
class Met():
def __init__(self):
self.name = "Lossless"
self.patternid = 0
self.type = "SUP"
self.values = [0, 0, 0, 0]
class Brick():
def __init__(self):
self.name = "Air"
self.patternid = 0
self.values = [0, 0, 0] # [Erel, Loss Tan, Cond] elements can be lists length 3 (isotropic) or length 9 (anisotropic)
self.isIsotropic = True
class Box():
def __init__(self):
self.nlev = None
self.xwidth = None
self.ywidth = None
self.xcells2 = None
self.ycells2 = None
self.nsubs = None
self.eeff = None
class Dlayer():
def __init__(self):
self.ilevel = 0
self.thickness = 0
self.erel = 1
self.mrel = 1
self.eloss = 0
self.mloss = 0
self.esignma = 0
self.nzpart = 0
self.name = "New layer"
# Stuff in the same layer
self.tlayers = []
self.ports = []
self.components = []
class Tlayer():
def __init__(self):
self.lay_type = "METAL" # "METAL", "BRICK" or "VIA"
self.lay_name = None
self.dxf_layer = "<UNSPECIFIED>"
self.gds_stream = None
self.gds_object = None
self.type = "MET POL" # "MET POL", "BRI POL" or "VIA POLYGON"
self.ilevel = None
self.nvertices = None
self.mtype = -1
self.filltype = "N"
self.debugid = 0
self.xmin = 1
self.ymin = 1
self.xmax = 100
self.ymax = 100
self.conmax = 0
self.res1 = 0
self.res2 = 0
self.edgemesh = "Y"
self.to_level = None
self.meshingfill = "RING"
self.pads = "NOCOVERS"
# List of associated polygons
self.polygons = []
class Polygon():
def __init__(self):
self.type = "MET POL" # "MET POL", "BRI POL" or "VIA POLYGON"
self.ilevel = None
self.nvertices = None
self.mtype = -1
self.filltype = "N"
self.debugid = 0
self.xmin = 1
self.ymin = 1
self.xmax = 100
self.ymax = 100
self.conmax = 0
self.res1 = 0
self.res2 = 0
self.edgemesh = "Y"
self.to_level = None
self.meshingfill = "RING"
self.pads = "NOCOVERS"
self.lay_name = None
self.inherit = "INH"
# List of [xvertex, yvertex]
self.vertices = []
class Port():
def __init__(self):
self.type = "STD"
self.ipolygon = None
self.ivertex = None
self.portnum = None
self.resist = 50
self.react = 0
self.induct = 0
self.capac = 0
self.xcoord = None
self.ycoord = None
class Component():
# Only ideal components are implemeted
def __init__(self):
self.levelnum = None
self.label = None
self.objectid = None
self.gndref = "F"
self.twtype = "1CELL"
self.leftpos = None
self.rightpos = None
self.toppos = None
self.bottompos = None
self.pbshw = "N"
self.xpos = None
self.ypos = None
self.smdp1_levelnum = None
self.smdp1_x = None
self.smdp1_y = None
self.smdp1_orientation = None
self.smdp1_portnum = None
self.smdp1_pinnum = 1 # unclear what pinnum is
self.smdp2_levelnum = None
self.smdp2_x = None
self.smdp2_y = None
self.smdp2_orientation = None
self.smdp2_portnum = None
self.smdp2_pinnum = 2 # unclear what pinnum is
self.idealtype = "IND"
self.compval = 30
class Valvar():
def __init__(self):
self.varname = None
self.unittype = None
self.value = 30
self.description = ""
class Lorgn():
def __init__(self):
self.x = None
self.y = None
self.locked = "U"
class Control():
def __init__(self):
self.sweep = "ABS" # SIMPLE, ABS or VARSWP
self.options = "-d"
self.subsplam = None
self.subsplam_subslambda = None
self.edgecheck = None
self.edgecheck_numlevels = None
self.edgecheck_checktype = None
self.cfmax = None
self.cfmax_subfreq = None
self.cepsy = None
self.cepsy_epsilon = None
self.filename = None
self.speed = 1
self.res_abs = None
self.res_abs_resolution = None
self.cache_abs = 1
self.targ_abs = 300
self.q_acc = "Y"
self.det_abs_res = None
class Freq():
# Only SIMPLE and ABS sweeps are implemeted
def __init__(self):
self.sweep = "ABS" # SIMPLE or ABS
self.f1 = None
self.f2 = None
self.fstep = None
class Opt():
def __init__(self):
self.lines = []
class Varswp():
def __init__(self):
# List of Psweep instances
self.psweeps = []
class Psweep():
# Only SWEEP and ABS_ENTRY sweeps are implemeted
def __init__(self):
self.sweeptype = "ABS_ENTRY" # SWEEP or ABS_ENTRY
self.f1 = 5
self.f2 = 8
self.fstep = None
# List of Var instances
self.vars = []
class Var():
def __init__(self):
self.parameter = None
self.ytype = "Y" # "N" or any of the Ytypes
self.min = None
self.max = None
self.step = None
class Fileout():
# Only a single "Response" file (for geometry projects) is implemented
def __init__(self):
self.filetype = "CSV"
self.embed = "D"
self.abs_inc = "Y"
self.filename = "$BASENAME.csv"
self.comments = "NC"
self.sig = 8
self.partype = "S"
self.parform = "DB"
self.ports = "R 50"
self.folder = None
class Subdiv():
def __init__(self):
self.lines = []
class Qsg():
def __init__(self):
self.lines = []
class sonnet(object):
"""
Basic class for all interactions between Sonnet and Python, and for storing the Sonnet project. Start your interactions with SonPy by creating an instance of this class, like so:
>>> import sonpy
>>> snt = sonpy.sonnet()
All the functions of SonPy described in this API documention are functions defined in the :class:`sonnet` class.
"""
# Tested on Windows, can be extended to Linux (but not Mac)
def __init__(self):
# Settings for em simulator
self.exception = Exception
self.executable_path = "C:\\Program Files (x86)\\Sonnet Software\\14.54\\bin\\"
self.executable_file = "em.exe"
self.executable_and_monitor_file = "emstatus.exe"
self.executable_and_monitor_options = "-Run"
self.sonnet_file_path = "C:\\Users\\Lab\\Desktop\\sonnet_test\\"
self.sonnet_file = "test.son"
self.sonnet_options = "-v"
self.done_flag = 1
self.run_count = 0
self.em_process = None
self.emstatus_process = None
self.parentPID = None
self.emPID = None
# Settings for the gds to son translator
self.gds_translator_file = "gds.exe"
self.gds_translator_options = "-v"
self.gds_file_path = self.sonnet_file_path
self.gds_file = "test.gds"
self.gds_process = None
# Settings for data extraction and plotting
self.data_file = self.sonnet_file[:-3] + "csv"
self.data_file_path = self.sonnet_file_path
# Class containing the Sonnet project
self.project = None
def __del__(self):
self.em_process = None
self.emstatus_process = None
self.project = None
########################################################################
# SET FILEPATHS AND FILENAMES #
########################################################################
def setSonnetInstallationPath(self, path):
"""
Sets the path of the Sonnet installation.
:param str path: Path to Sonnet executables ``em.exe``, ``emstatus.exe`` and ``gds.exe``. Default is ``C:\\Program Files (x86)\\Sonnet Software\\14.54\\bin\\``.
"""
self.executable_path = path
if self.executable_path[-1] != '\\':
self.executable_path += '\\'
def setSonnetFile(self, filename):
"""
Sets the filename of the Sonnet project file.
:param str filename: Sonnet project file. Default is ``test.son``.
"""
self.sonnet_file = filename
def setSonnetFilePath(self, path):
"""
Sets the path of the Sonnet project file.
:param str path: Path to the Sonnet project file. Default is ``C:\\Users\\Lab\\Desktop\\sonnet_test\\``.
"""
self.sonnet_file_path = path
if self.sonnet_file_path[-1] != '\\':
self.sonnet_file_path += '\\'
def setGdsFile(self, filename):
"""
Sets the filename of the GDSII file. It furthermore sets the Sonnet project file and data file to the same name (but with extensions .son and .csv, respectively).
:param str filename: GDSII file. Default is ``test.gds``.
"""
self.gds_file = filename
# Also set Sonnet and data file name
self.setSonnetFile(self.gds_file[:-3] + 'son')
self.setDataFile(self.gds_file[:-3] + 'csv')
def setGdsFilePath(self, path):
"""
Sets the path of the GDSII file. It furthermore sets the paths to the Sonnet project file and data file to the same path.
:param str path: Path to the GDSII file. Default is the Sonnet project path.
:Example:
Say you have ``myproject.gds`` that you want to use that as a starting point for a Sonnet project.
>>> import os
>>> snt.setGdsFilePath(os.getcwd()) # get current work directory
>>> snt.setGdsFile('myproject.gds')
SonPy will now associate ``myproject.son`` and ``myproject.csv`` (in the current directory) with the current project, even if these files do not exist yet.
"""
self.gds_file_path = path
if self.gds_file_path[-1] != '\\':
self.gds_file_path += '\\'
# Also set Sonnet and data file paths
self.setSonnetFilePath(self.gds_file_path)
self.setDataFilePath(self.gds_file_path)
def setDataFile(self, filename):
"""
Sets the filename of the data file.
:param str filename: Data file. Default is the Sonnet project filename, but with the extension .csv instead of .son.
"""
self.data_file = filename
def setDataFilePath(self, path):
"""
Sets the filepath of the data file.
:param str path: Path to the data file. Default is the Sonnet project path.
"""
self.data_file_path = path
if self.data_file_path[-1] != '\\':
self.data_file_path += '\\'
########################################################################
# GDS TO SONNET PROJECT FILE TRANSLATOR (gds.exe) #
########################################################################
def setTemplateFile(self, filename):
"""
Sets an existing Sonnet project file (in the current directory) as template. When converting a GDSII file, the resulting Sonnet project file will inherit the settings of the template.
:param str filename: Filename of the template Sonnet project file.
"""
self.gds_translator_options = "-i{:s}".format(filename)
def runGdsTranslator(self, silent=False):
"""
Runs Sonnet's GDSII file to Sonnet project file translator. A Sonnet project file with the same name as the GDSII file is created in the same directory.
After the translation process has run, the following functions are called:
1. :func:`readProject()`: Reads the created Sonnet project file into SonPy.
2. :func:`collapseDlayers()`: Removes empty dielectric layers.
3. :func:`cropBox()`: Crops the bounding box to the edge of the circuit.
:param bool silent: Toggle wait message.
"""
# Verify gds file exists
file_found = 0
for root, dirs, files in os.walk(self.gds_file_path):
for file in files:
# Make search case insensitive
if self.gds_file.lower() == file.lower():
file_found = 1
if (file_found == 0):
print("GDSII file {:s} cannot be located in path {:s}".format(self.gds_file, self.gds_file_path))
raise self.exception("GDSII file not found! Check that directory and filename are correct")
# Convert gds file to son file through Sonnet's gds.exe
args = ([self.executable_path + self.gds_translator_file, # command
self.gds_translator_options, # options
self.gds_file_path + self.gds_file]) # file
try:
# Run conversion process
self.gds_process = subprocess.Popen(args, stdout=subprocess.PIPE)
except:
print("Error! Cannot start process, use setSonnetInstallationPath(path) to point the class to the location of your gds.exe file")
print("Current path is {:s}".format(self.executable_path))
raise self.exception("Cannot run gds executable file, file not found")
# Wait for the process to complete
if silent == False:
print('Translating...')
self.gds_process.wait()
# Read the Sonnet file into Sonpy and run some default changes
self.readProject()
self.collapseDlayers()
self.cropBox()
########################################################################
# READ AND WRITE THE SONNET PROJECT FILE #
########################################################################
def readProject(self):
"""
Reads the Sonnet project file into SonPy. This function is run in :func:`runGdsTranslator` to ensure the created Sonnet project file is read into SonPy for further manipulation.
"""
# Initialize Sonnet project
project = Project()
self.project = project
with open(self.sonnet_file_path + self.sonnet_file, 'r') as fd:
line = fd.readline()
preheader = Preheader()
project.preheader = preheader
while line != "HEADER\n":
# Save all lines before HEADER block
preheader.lines.append(line)
line = fd.readline()
while line != "":
if line == "HEADER\n":
# Initialize HEADER block
header = Header()
project.header = header
line = fd.readline()
while line != "END HEADER\n":
# Save all lines
header.lines.append(line)
line = fd.readline()
elif line == "DIM\n":
# Initialize DIM block
dim = Dim()
project.dim = dim
line = fd.readline()
while line != "END DIM\n":
# Save all lines
dim.lines.append(line)
line = fd.readline()
elif line == "GEO\n":
# Initialize GEO block
geo = Geo()
dlayers = []
valvars = []
ports = []
geo.dlayers = dlayers
geo.valvars = valvars
project.geo = geo
line = fd.readline()
while line != "END GEO\n":
if line.split()[0] == "TMET":
# Initialize top metal
params = line.split()
tmet = Tmet()
tmet.name = params[1] # assume no spaces
tmet.patternid = int(params[2])
tmet.type = params[3]
tmet.values = []
for params in params[4:]:
tmet.values.append(float(params))
geo.tmet = tmet
line = fd.readline()
elif line.split()[0] == "BMET":
# Initialize bottom metal
params = line.split()
bmet = Bmet()
bmet.name = params[1] # assume no spaces
bmet.patternid = int(params[2])
bmet.type = params[3]
bmet.values = []
for params in params[4:]:
bmet.values.append(float(params))
geo.bmet = bmet
line = fd.readline()
elif line.split()[0] == "MET":
# Initialize metal
params = line.split()
met = Met()
met.name = params[1] # assume no spaces
met.patternid = int(params[2])
met.type = params[3]
met.values = []
for params in params[4:]:
met.values.append(float(params))
geo.met = met
line = fd.readline()
elif line.split()[0] == "BRI":
# Initialize isotropic brick material
params = line.split()
bri = Brick()
bri.name = params[1] # assume no spaces
bri.patternid = int(params[2])
bri.isIsotropic = True
bri.values = []
for params in params[3:]:
bri.values.append(float(params))
geo.bricks.append(bri)
line = fd.readline()
elif line.split()[0] == "BRA":
# Initialize anisotropic brick material
params = line.split()
bri = Brick()
bri.name = params[1] # assume no spaces
bri.patternid = int(params[2])
bri.isIsotropic = False
bri.values = []
for params in params[3:]:
bri.values.append(float(params))
geo.bricks.append(bri)
line = fd.readline()
elif line.split()[0] == "BOX":
# Initialize BOX
params = line.split()
box = Box()
box.nlev = int(params[1])
box.xwidth = float(params[2])
box.ywidth = float(params[3])
box.xcells2 = float(params[4])
box.ycells2 = float(params[5])
box.nsubs = int(params[6])
box.eeff = float(params[7])
geo.box = box
# Initialize dielectric layers
layerIndex = 0
line = fd.readline()
while line[0] == " ":
params = line.split()
dlayer = Dlayer()
dlayer.ilevel = layerIndex
dlayer.thickness = float(params[0])
dlayer.erel = float(params[1])
dlayer.mrel = float(params[2])
dlayer.eloss = float(params[3])
dlayer.mloss = float(params[4])
dlayer.esignma = float(params[5])
dlayer.nzpart = int(params[6])
dlayer.name = " ".join(params[7:]).replace('"','')
dlayers.append(dlayer)
layerIndex += 1
line = fd.readline()
elif line.split()[0] == "TECHLAY":
# Initialize technology layer and add it to dlayer
params = line.split()
tlayer = Tlayer()
tlayer.lay_type = params[1]
tlayer.lay_name = params[2]
tlayer.dxf_layer = params[3]
tlayer.gds_stream = int(params[4])
tlayer.gds_object = int(params[5])
params = fd.readline().split()
if len(params) != 13:
tlayer.type = " ".join(params)
params = fd.readline().split()
else:
tlayer.type = "MET POL"
tlayer.ilevel = int(params[0])
tlayer.nvertices = int(params[1])
tlayer.mtype = int(params[2])
tlayer.filltype = params[3]
tlayer.debugid = int(params[4])
tlayer.xmin = int(params[5])
tlayer.ymin = int(params[6])
tlayer.xmax = int(params[7])
tlayer.ymax = int(params[8])
tlayer.conmax = int(params[9])
tlayer.res1 = int(params[10])
tlayer.res2 = int(params[11])
tlayer.edgemesh = params[12]
line = fd.readline()
if line.split()[0] == "TOLEVEL":
params = line.split()
tlayer.to_level = int(params[1])
tlayer.meshingfill = params[2]
tlayer.pads = params[3]
line = fd.readline()
while line == "END\n":
line = fd.readline()
dlayers[tlayer.ilevel].tlayers.append(tlayer)
elif line.split()[0] == "VALVAR":
# Initialize variable parameter
params = line.split()
valvar = Valvar()
valvar.varname = params[1]
valvar.unittype = params[2]
valvar.value = float(params[3])
valvar.description = params[4].replace('"','')
valvars.append(valvar)
line = fd.readline()
elif line.split()[0] == "LORGN":
# Initialize location of origin
params = line.split()
lorgn = Lorgn()
lorgn.x = float(params[1])
lorgn.y = float(params[2])
lorgn.locked = params[3]
geo.lorgn = lorgn
line = fd.readline()
elif line.split()[0] == "POR1":
# Initialize port
port = Port()
port.type = line.split()[1]
port.ipolygon = int(fd.readline().split()[1])
port.ivertex = int(fd.readline().split()[0])
params = fd.readline().split()
port.portnum = int(params[0])
port.resist = float(params[1])
port.react = float(params[2])
port.induct = float(params[3])
port.capac = float(params[4])
port.xcoord = float(params[5])
port.ycoord = float(params[6])
# We can not yet assign port to dlayer because
# its location is hidden in ipolygon, so for now
# we save port in a list of ports
ports.append(port)
line = fd.readline()
elif line.split()[0] == "SMD":
# Initialize component and add it to dlayer
component = Component()
component.levelnum = int(line.split()[1])
component.label = line.split()[2].replace('"','')
component.objectid = int(fd.readline().split()[1])
component.gndref = fd.readline().split()[1]
component.twtype = fd.readline().split()[1]
sbox = fd.readline().split()
component.leftpos = float(sbox[1])
component.rightpos = float(sbox[2])
component.toppos = float(sbox[3])
component.bottompos = float(sbox[4])
component.pbshw = fd.readline().split()[1]
lpos = fd.readline().split()
component.xpos = float(lpos[1])
component.ypos = float(lpos[2])
typeideal = fd.readline().split()
component.idealtype = typeideal[2]
compval = typeideal[3]
# If compval is in quotes, it is a variable parameter
if compval[0] == '"' and compval[-1] == '"':
component.compval = compval.replace('"','')
# Otherwise it is a float value
else:
component.compval = float(compval)
smdp1 = fd.readline().split()
component.smdp1_levelnum = int(smdp1[1])
component.smdp1_x = float(smdp1[2])
component.smdp1_y = float(smdp1[3])
component.smdp1_orientation = smdp1[4]
component.smdp1_portnum = int(smdp1[5])
component.smdp1_pinnum = int(smdp1[6])
smdp2 = fd.readline().split()
component.smdp2_levelnum = int(smdp2[1])
component.smdp2_x = float(smdp2[2])
component.smdp2_y = float(smdp2[3])
component.smdp2_orientation = smdp2[4]
component.smdp2_portnum = int(smdp2[5])
component.smdp2_pinnum = int(smdp2[6])
dlayers[component.levelnum].components.append(component)
line = fd.readline()
line = fd.readline()
elif line.split()[0] == "NUM":
# Associate polygons with technology layers
npoly = int(line.split()[1])
geo.npoly = npoly
for poly in range(npoly):
polygon = Polygon()
params = fd.readline().split()
if len(params) != 13:
polygon.type = " ".join(params)
params = fd.readline().split()
else:
polygon.type = "MET POL"
polygon.ilevel = int(params[0])
polygon.nvertices = int(params[1])
polygon.mtype = int(params[2])
polygon.filltype = params[3]
polygon.debugid = int(params[4])
polygon.xmin = int(params[5])
polygon.ymin = int(params[6])
polygon.xmax = int(params[7])
polygon.ymax = int(params[8])
polygon.conmax = int(params[9])
polygon.res1 = int(params[10])
polygon.res2 = int(params[11])
polygon.edgemesh = params[12]
line = fd.readline()
if line.split()[0] == "TOLEVEL":
params = line.split()
polygon.to_level = int(params[1])
polygon.meshingfill = params[2]
polygon.pads = params[3]
line = fd.readline()
tlaynam = line.split()
polygon.lay_name = tlaynam[1]
polygon.inherit = tlaynam[2]
line = fd.readline()
while line != "END\n":
xvertex = float(line.split()[0])
yvertex = float(line.split()[1])
polygon.vertices.append([xvertex, yvertex])
line = fd.readline()
for dlayer in dlayers:
for tlayer in dlayer.tlayers:
if tlayer.lay_name == polygon.lay_name:
tlayer.polygons.append(polygon)
# Assign port to layer if the current polygon's
# debugid matches that of a port's ipolygon
for port in ports:
if polygon.debugid == port.ipolygon:
dlayers[polygon.ilevel].ports.append(port)
else:
line = fd.readline()
elif line == "CONTROL\n":
# Initialize CONTROL block
control = Control()
project.control = control
line = fd.readline()
while line != "END CONTROL\n":
if line.split()[0] in ["SIMPLE", "STD", "ABS", "OPTIMIZE", "VARSWP", "EXTFILE"]:
control.sweep = line.split()[0]
line = fd.readline()
elif line.split()[0] == "OPTIONS":
control.options = line.split()[1]
line = fd.readline()
elif line.split()[0] == "SUBSPLAM":
control.subsplam = line.split()[1] # "Y" or "N"
if line.split()[1] == "Y":
control.subsplam_subslambda = int(line.split()[2])
line = fd.readline()
elif line.split()[0] == "EDGECHECK":
control.edgecheck = line.split()[1] # "Y" or "N"
if line.split()[1] == "Y":
control.edgecheck_numlevels = int(line.split()[2])
if line.split()[-1] == "TECHLAY":
control.edgecheck_checktype = line.split()[-1]
line = fd.readline()
elif line.split()[0] == "CFMAX":
control.cfmax = line.split()[1] # "Y" or "N"
if line.split()[1] == "Y":
control.cfmax_subfreq = float(line.split()[2])
line = fd.readline()
elif line.split()[0] == "CEPSY":
control.cepsy = line.split()[1] # "Y" or "N"
if line.split()[1] == "Y":
control.cepsy_epsilon = float(line.split()[2])
line = fd.readline()
elif line.split()[0] == "FILENAME":
control.filename = line.split()[1]
line = fd.readline()
elif line.split()[0] == "SPEED":
control.speed = int(line.split()[1])
line = fd.readline()
elif line.split()[0] == "RES_ABS":
control.res_abs = line.split()[1] # "Y" or "N"
if line.split()[1] == "Y":
control.res_abs_resolution = float(line.split()[2])
line = fd.readline()
elif line.split()[0] == "CACHE_ABS":
control.cache_abs = int(line.split()[1])
line = fd.readline()
elif line.split()[0] == "TARG_ABS":
control.targ_abs = int(line.split()[1])
line = fd.readline()
elif line.split()[0] == "Q_ACC":
control.q_acc = line.split()[1] # "Y" or "N"
line = fd.readline()
elif line.split()[0] == "DET_ABS_RES":
control.det_abs_res = line.split()[1] # "Y" or "N"
line = fd.readline()
else:
line = fd.readline()
elif line == "FREQ\n":
# Initialize FREQ block
freq = Freq()
project.freq = freq
line = fd.readline()
while line != "END FREQ\n":
if line.split()[0] == "SIMPLE":
freq.sweep = line.split()[0]
freq.f1 = float(line.split()[1])
freq.f2 = float(line.split()[2])
freq.fstep = float(line.split()[3])
line = fd.readline()
elif line.split()[0] == "ABS":
freq.sweep = line.split()[0]
freq.f1 = float(line.split()[1])
freq.f2 = float(line.split()[2])
line = fd.readline()
else:
line = fd.readline()
elif line == "OPT\n":
# Initialize OPT block
opt = Opt()
project.opt = opt
line = fd.readline()
while line != "END OPT\n":
# Save all lines
opt.lines.append(line)
line = fd.readline()
elif line == "VARSWP\n":
# Initialize VARSWP block
varswp = Varswp()
psweeps = []
varswp.psweeps = psweeps
project.varswp = varswp
line = fd.readline()
while line != "END VARSWP\n":
if line.split()[0] == "SWEEP":
# Initialize parameter sweep
psweep = Psweep()
psweep.sweeptype = line.split()[0]
psweep.f1 = float(line.split()[1])
psweep.f2 = float(line.split()[2])
psweep.fstep = float(line.split()[3])
line = fd.readline()
while line.split()[0] == "VAR":
var = Var()
var.parameter = line.split()[1]
var.ytype = line.split()[2]
var.min = float(line.split()[3])
var.max = float(line.split()[4])
var.step = float(line.split()[5])
psweep.vars.append(var)
line = fd.readline()
psweeps.append(psweep)
elif line.split()[0] == "ABS_ENTRY":
# Initialize parameter sweep
psweep = Psweep()
psweep.sweeptype = line.split()[0]
psweep.f1 = float(line.split()[1])
psweep.f2 = float(line.split()[2])
line = fd.readline()
while line.split()[0] == "VAR":
var = Var()
var.parameter = line.split()[1]
var.ytype = line.split()[2]
var.min = float(line.split()[3])
var.max = float(line.split()[4])
var.step = float(line.split()[5])
psweep.vars.append(var)
line = fd.readline()
psweeps.append(psweep)
else:
line = fd.readline()
elif line == "FILEOUT\n":
# Initialize FILEOUT block
fileout = Fileout()
project.fileout = fileout
line = fd.readline()
while line != "END FILEOUT\n":
if line.split()[0] in ["TS", "TOUCH2", "DATA_BANK", "SC", "CSV", "CADENCE", "MDIF", "EBMDIF"]:
params = line.split()
fileout.filetype = params[0]
fileout.embed = params[1]
fileout.abs_inc = params[2]
fileout.filename = params[3]
fileout.comments = params[4]
fileout.sig = int(params[5])
fileout.partype = params[6]
fileout.parform = params[7]
fileout.ports = " ".join(params[8:])
line = fd.readline()
elif line.split()[0] == "FOLDER":
fileout.folder = line.split()[1]
line = fd.readline()