-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_sky130.py
88 lines (82 loc) · 2.32 KB
/
load_sky130.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
from PySpice.Spice.Parser import SpiceParser
from glob import glob
import sys
import os
import asyncio
from aiocouch import CouchDB
prefix = os.environ['CONDA_PREFIX']
pdk = "sky130"
decl = f".lib {prefix}/share/pdk/sky130A/libs.tech/ngspice/sky130.lib.spice {{corner}}"
dburl = "http://admin:admin@localhost:5984"
dbname = "offline"
user = None
password = None
files = sys.argv[1:]
devices = set()
for f in files:
try:
p = SpiceParser(f)
except Exception as e:
print(e)
continue
# print([m.name for m in p.models])
devices.update([m.name for m in p.subcircuits])
pmos = []
nmos = []
diode = []
capacitor = []
resistor = []
inductor = []
npn = []
pnp = []
for d in devices:
if "pfet" in d:
pmos.append(d)
elif "nfet" in d:
nmos.append(d)
elif "diode" in d:
diode.append(d)
elif "res" in d:
resistor.append(d)
elif "cap" in d:
capacitor.append(d)
elif "ind" in d:
inductor.append(d)
elif "npn" in d:
npn.append(d)
elif "pnp" in d:
pnp.append(d)
else:
print(d)
# raise ValueError(d)
async def add_models(db, cellname, models):
docid = "models:"+cellname
cell = await db.get(docid, {})
cell["models"] = {}
cell["name"] = cellname
for m in models:
if "rf" not in m:
cell["models"][m] = {
"name": m,
"type": "spice",
"NgSpice": {
"reftempl": "X{name} {ports} {properties}" if cellname != "resistor" else "X{name} {ports} GND " + m,
"decltempl": decl,
"vectors": ["gm", "id", "vdsat"] if cellname in {'nmos', 'pmos'} else [],
"component": "M"+m
},
"categories": [pdk]
}
await cell.save()
async def main():
async with CouchDB(dburl, user=user, password=password) as couchdb:
db = await couchdb[dbname]
await add_models(db, "pmos", pmos)
await add_models(db, "nmos", nmos)
await add_models(db, "diode", diode)
await add_models(db, "capacitor", capacitor)
await add_models(db, "resistor", resistor)
await add_models(db, "inductor", inductor)
await add_models(db, "npn", npn)
await add_models(db, "pnp", pnp)
asyncio.run(main())