Control parameter tuning with PyQSPICE

@pythonpoweretrx

Please try this…(I’m relocating/moving now and I can’t confirm it by myself, small debugging needed :slight_smile: )


I think you have this code block already.

fname = "Your_Python_FileName"
run = pqs(fname)
run.qsch2cir()

Now, you open the netlist and edit.

# read the netlist, store each line in "lines" variable with the change
lines = ""
with open(run.path['cir'], encoding='SJIS') as f:
  for line in f:
    line = line.rstrip('\r\n')
    if ret := re.match(r'^.*curr_controller_Kp', line):
      new_val = 9.99
      lines = lines + ".param curr_controller_Kp " + str(new_val) + "\n"		
    else:
      lines = lines + line + "\n"
# override the netlist with "lines"
with open(run.path['cir'], "w", encoding='SJIS') as f:
  f.write(lines)