Search code examples
pythonos.systempspice

Automatically quitting ngspice after simulation


I was working on an automation project which requires me to fire a simulation in ngspice, get the data in a .txt file and quit ngspice. I have the following code to call ngspice:

import sys
import os

def invoke_ngspice():
    os.system(r"C:\Users\MyPC\Desktop\GUI\ngspice\bin\ngspice_con.exe C:\Users\MyPC\Desktop\GUI\ngspice\bin\test_circuit.circ")
    os.system(r"quit")

While calling the above function does the simulation and save part flawlessly, I am unable to quit because ngspice holds the execution. Is there anyway of quitting ngspice cleanly? I don't want to manually type in quit in ngspice command window everytime or kill it because simulation time is variable.


Solution

  • so I found the method to quit ngspice systematically using the control loop. In the test_circuit.circ file I added quit statement in the .control section and that's it!

    .control 
    set filetype=ascii
    run 
    wrdata temp_file abs(v(A_1)-v(B_1)) 
    quit
    .endc