-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathlibrary.py
109 lines (101 loc) · 3.12 KB
/
library.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
import json
from .model import Model
from .subcircuit import SubCircuit
from .types import List, Union, set_context
class Library(List[Union[Model, SubCircuit]]):
def __init__(self, loadbuiltins=False, pdk_models=None):
super().__init__()
models = None
if pdk_models:
models = pdk_models()
elif loadbuiltins:
models = self.default_models()
if models:
with set_context(self):
for m in models:
self.append(m)
def find(self, name):
return next((x for x in self if x.name == name.upper()), None)
def append(self, item):
assert not self.find(item.name), f'Duplicate model/subcircuit name {item.name} New: {item}, Existing: {self.find(item.name)}'
self.__root__.append(item)
def default_models(self):
models = list()
models.append(
Model(
name='NMOS',
pins=['D', 'G', 'S', 'B'],
parameters={
'W': 0,
'L': 0,
'NFIN': 1,
'NF': 2,
'M': 1,
'PARALLEL': 1, # Internal attribute used for parallel and stacked devices
'STACK': 1},
prefix=''
)
)
models.append(
Model(
name='PMOS',
pins=['D', 'G', 'S', 'B'],
parameters={
'W': 0,
'L': 0,
'NFIN': 1,
'NF': 2,
'M': 1,
'PARALLEL': 1, # Internal attribute used for parallel and stacked devices
'STACK': 1},
prefix=''
)
)
models.append(
Model(
name='CAP',
pins=['PLUS', 'MINUS'],
parameters={
'VALUE': 0,
'PARALLEL': 1,
'STACK': 1
},
prefix='C'
)
)
models.append(
Model(
name='RES',
pins=['PLUS', 'MINUS'],
parameters={
'VALUE': 0,
'PARALLEL': 1,
'STACK': 1
},
prefix='R'
)
)
models.append(
Model(
name='IND',
pins=['PLUS', 'MINUS'],
parameters={
'VALUE': 0,
'PARALLEL': 1,
'STACK': 1
},
prefix='L'
)
)
return models
def read_lib_json(json_file_path):
with open(json_file_path, "r") as f:
data = json.load(f)
library = Library(loadbuiltins=False)
with set_context(library):
for x in data:
if 'generator' in x:
library.append(SubCircuit(**{k: v for k, v in x.items() if v}))
else:
library.append(Model(**{k: v for k, v in x.items() if v and not k=='base'}))
return library