init commit

This commit is contained in:
2026-10-21 12:53:12 -04:00
commit cbf23ccd5f
7 changed files with 1463 additions and 0 deletions
+144
View File
@@ -0,0 +1,144 @@
"""Generate a Victory DoE golden deck from a DeckBuild deck (Hacker Fab PMOS decks).
Usage: python3 make_doe.py <deck.in> <out.in> [2D|3D]
Applies the Victory DoE golden-deck rules (VDoE manual ch. 12, 14, 15, 17):
* if/if.end blocks on $dim / $save_vis resolved -> every variable SET once
* no SET before the first GO (12.5.1): switch SETs and SET name removed,
$'name' replaced by the literal base name
* variables used in more than one module moved to a #global_var block
right after the first GO (12.2) -- every "go ..." line starts a module
* every SET except the DOE knobs tagged #vpm_fix (14.3)
* LOG outfile -> @cnode_<file> (unique per split); extract init infile ->
@pnode_<file> (the go internal module reads its parent's logs) (12.5.2, 15)
* victoryvisual lines removed (disabled during VDoE runs, 17.1)
* 3D: thread counts -P 1 (process, mesh) / -P 2 (device)
"""
import re, sys, collections
src, dst = sys.argv[1], sys.argv[2]
dim = sys.argv[3] if len(sys.argv) > 3 else '2D'
KNOBS = {'RhoSub', 'Tsod', 'Csod_B', 'SDTime', 'SDTemp', 'GateOv', 'Tal2o3', 'Qf',
# poly-gate deck knobs (ignored if absent)
'PolyTime', 'PolyTemp', 'Tgox'}
text = open(src).read()
m = re.search(r'^SET name="([^"]+)"', text, re.M)
BASE = m.group(1)
lines = text.splitlines()
# ---------- 1. resolve if/if.end ---------------------------------------------
truth = {r'\$dim="2D"': dim == '2D', r'\$dim="3D"': dim == '3D',
r'\$save_vis=1': False,
r'\$poly_dopant="phosphorus"': True, r'\$poly_dopant="boron"': False,
r'\$SOD_on_gate=0': True}
def evaluate(cond):
for pat, val in truth.items():
if re.fullmatch(pat, cond.strip()):
return val
raise SystemExit(f'unknown condition: {cond}')
out, stack = [], []
for l in lines:
mm = re.match(r'^if cond=\((.*)\)\s*$', l)
if mm:
stack.append(evaluate(mm.group(1))); continue
if re.match(r'^if\.end\s*$', l):
stack.pop(); continue
if all(stack):
out.append(l)
assert not stack, 'unbalanced if/if.end'
# ---------- 2. drop switches / SET name; literal names -------------------------
drop = {'dim', 'save_vis', 'name', 'poly_dopant', 'SOD_on_gate'}
res, skip = [], False
for l in out:
mm = re.match(r'^SET (\w+)', l)
if mm:
skip = mm.group(1) in drop
if skip:
continue
elif skip and re.match(r'^\s{20,}#', l):
continue
else:
skip = False
res.append(l.replace("$'name'", BASE))
lines = [l for l in res if not l.startswith('victoryvisual')
and not l.startswith('#### PLOTS')]
text = '\n'.join(lines) + '\n'
# ---------- 3. file references ------------------------------------------------
n_log = len(re.findall(r'LOG outfile=' + re.escape(BASE), text))
text = re.sub(r'LOG outfile=' + re.escape(BASE), 'LOG outfile=@cnode_' + BASE, text)
n_ext = len(re.findall(r'extract init infile="' + re.escape(BASE), text))
text = re.sub(r'extract init infile="' + re.escape(BASE), 'extract init infile="@pnode_' + BASE, text)
text = re.sub(r'LAYOUT="[^"]*Pmos\.gds"', 'LAYOUT="Pmos.gds"', text)
if dim == '3D':
text = (text.replace('GO victoryprocess simflags="-P 4"', 'GO victoryprocess simflags="-P 1"')
.replace('GO victorymesh simflags="-P 4"', 'GO victorymesh simflags="-P 1"')
.replace('GO victorydevice simflag="-P 4"', 'GO victorydevice simflag="-P 2"'))
# ---------- 4. global variables ---------------------------------------------------
lines = text.splitlines()
is_go = lambda l: re.match(r'^\s*go\s', l, re.I)
go_idx = [i for i, l in enumerate(lines) if is_go(l)]
mod_of = lambda i: sum(1 for g in go_idx if g <= i)
set_line = {}
for i, l in enumerate(lines):
mm = re.match(r'^\s*set\s+(\w+)\s*=', l, re.I)
if mm:
assert mm.group(1) not in set_line, f'duplicate SET {mm.group(1)}'
set_line[mm.group(1)] = i
need = set()
for i, l in enumerate(lines):
s = l.lstrip()
if s.startswith('#'):
continue
code = l if s.lower().startswith('extract') else l.split('#')[0]
for v in re.findall(r'\$(\w+)', code):
if v in set_line and mod_of(set_line[v]) != mod_of(i):
need.add(v)
changed = True
while changed:
changed = False
for v in list(need):
for d in re.findall(r'\$(\w+)', lines[set_line[v]].split('#')[0]):
if d in set_line and d not in need:
need.add(d); changed = True
glob = sorted(need, key=lambda v: set_line[v])
glob_lines = [lines[set_line[v]] for v in glob]
for v in glob:
lines[set_line[v]] = None
lines = [l for l in lines if l is not None]
first_go = next(i for i, l in enumerate(lines) if is_go(l))
lines[first_go + 1:first_go + 1] = (['#global_var',
'# Variables shared between modules (VDoE manual sec. 12.2)']
+ glob_lines + ['#global_var'])
# ---------- 5. #vpm_fix on everything except the DOE knobs ----------------------
for i, l in enumerate(lines):
mm = re.match(r'^\s*set\s+(\w+)\s*=', l, re.I)
if mm and mm.group(1) not in KNOBS and '#vpm_fix' not in l:
lines[i] = l.rstrip() + ' #vpm_fix'
present = [v for v in re.findall(r'^\s*set\s+(\w+)', '\n'.join(lines), re.M | re.I) if v in KNOBS]
hdr = [f'# ===== VICTORY DoE GOLDEN DECK ({dim}) -- generated from {src} =====',
'# Do not edit by hand: edit the DeckBuild deck and regenerate with make_doe.py.',
'# Put Pmos.gds in the project drop zone as a supplemental file.',
'# Split variables (all others are #vpm_fix): ' + ', '.join(present) + '.']
if dim == '3D':
hdr += ['# 3D: run process/mesh nodes ONE at a time (each is near the ~2.1 GB',
'# session limit). Device modules are lighter and may run in parallel.']
final = hdr + [''] + lines
open(dst, 'w').write('\n'.join(final) + '\n')
# ---------- checks ------------------------------------------------------------------
t = '\n'.join(final)
c = collections.Counter(x.lower() for x in re.findall(r'^\s*set\s+(\w+)', t, re.M | re.I))
fg = next(i for i, l in enumerate(final) if is_go(l))
print('modules:', [l.strip() for l in final if is_go(l)])
print('duplicate SETs:', [k for k, v in c.items() if v > 1])
print('if blocks left:', len(re.findall(r'^if cond', t, re.M)))
print("$'name' left:", t.count("$'name'"))
print('SET before first GO:', [l for l in final[:fg] if re.match(r'^\s*set\s', l, re.I)])
print(f'LOG -> @cnode_: {n_log} extract init -> @pnode_: {n_ext}')
print('globals:', glob)
print('split variables:', present)