PyQSPICE: A Python scripting interface for QSPICE

For those of us who are Python users, I would like to highlight a new tool called PyQSPICE. It works with QSPICE’s command-line interface to load QSPICE simulation results into memory for plotting in Python.

This is an open-source project hosted on GitHub. It is not supported by the QSPICE team.

GitHub - Qorvo/PyQSPICE: Python Interface for QSPICE

9 Likes

Hi Jeff.

For me this is very interesting information. Maybe I can get EAGLE to show an output window for QSpice instead of a PCB.

Thank you very much. Tom

Hi Jeff

My colleague told me that there is another :thinking: “PyQSPICE”.
GitHub - nunobrum/PyQSPICE: Python Library to operate with QSpice and read simulation output files
The author is the same person who wrote “PyLTspice”.
Is this the same one you mentioned?

1 Like

They are two different projects. There’s more discussion on the one I mentioned here:

I’m glad there is enough interest in the concept to drive two different developments!

2 Likes

Hi,

I’ve got an offline DM Q&A regarding this Python module and here’s summary which may help someone who gets the same questions.

Q:: Any good documentation?
A:: Sorry…not yet.

  • QuickStart has quick comments before lines.
  • The main module has an explanation in front of each method.

Q:: How to tweak a parameter, run a sim and repeat/loop?
A:: This example is running 2 sims from one next list by changing the netlist “.cir” file with Python regular expression “re” module.


Q:: Why “SJIS” encoding, in the Python module?
A:: See this discussion. The QSPICE uses “Latin-1 Supplement” and many file-encoding judgement routines (checked a couple of standalone encoding detection programs) think it “Shift JIS”, with a probability view point. Just to avoid Python error message, I use the “SJIS” encoding and I know I’m dealing with a file of “Latin-1 Supplement”.

masashi

PyQSPICE is very good and I have used it already.
How do I print the dc operating points if I am using PyQSPICE?? I do not see that function in the PyQSPICE class and was hoping if you could please help with that? It will be a good starting point to see dc operating points of all nodes (and currents)
before the PSRR circuit is simulated (or any other AC sim is triggered)

2 Likes

I run a quick trial and I see PyQSPICE can support your “.OP” needs.

I’m on the road and please wait for me next week :slight_smile:
I’ll delete this post when I update PyQSPICE for the “.OP”, by replacing my post with the detail how to handle “.OP” on PyQSPICE.


I believe I made an over commitment, it’s the Thanks-Giving week here in USA…Within Nov, I’ll try to get it updated for “.OP”.

1 Like

thank you masashi! I look forward to your uprate on how to use .op within PyQSPICE and getting a text file with outputs printed for the operating point (just like what one can see in the terminal).

Please check updated ver.2023.11.29 PyQSPICE.

  • It supports .OP result reading. To make this happens, PyQSPICE now reads “.cir” netlist and extract nodes and elements. Not all elements implemented (logic gates, AD/DA converters), voltage nodes completely sandwiched by those elements will be ignored…for now.
  • Plot setting lines are consolidated into a method and now we can make our main code clean.
    Only the code of “tests/50_OP” is clean for plotting, will update older “tests” examples step-by-step.
  • The example “tests/50_OP” is showing simple results but it is reading more info from the “.OP” run. Please try “print(df)” to see all the info this new version PyQSPICE reading.

Updated to Ver.2023.12.11,
by improving plotting codes,
by supporting examples in my coming Microwave Journal articles.

2 Likes

Can you plot signal buses that out be in the form of out[3:0]? I having been playing with the verilog functionality in qspice and not seeing a nice way to display buses in qspice. The ability to display buses in a similar way as modelsim would be nice that could interpret buses in decimal, binary or hex

Hi!

Interesting subject. As I love software programming, I want to do something here (but no promise :stuck_out_tongue: ).
May I ask couple of questions.

  • Do you want to have a waveform browser of zoom in/out, adding/deleting waveforms?
    In another word, do you want an advanced GUI waveform viewing software?
  • Or, is it OK to plot a range of waveform you can specify in your Python code?

I guess you want a waveform viewer…


By reading your post, I have these 2 things in my mind.

  1. Just to plot on Matplotlib
  2. To convert the “.qraw” output into another data format of available waveform viewer.
    ==> To all folks reading this thread: any suggestion of waveform viewer software online available at no cost, and its data format open and available? Here, mixed-signal (both analog and digital) waveform viewer.

masashi

Hi Masashi San,

i used to work using pyqtgraph.
https://www.pyqtgraph.org/

Its very quick and can handle millions of datapoint easily.

1 Like

Ideally i would think an interactive window would be preferred. If displaying vector data is not something that native Qspice app is intending to support then I believe a matplotlib approach that can interpret .qraw data in vector form would be awesome. matplotlib has interactive features in their figures. Would this level of interactive features be sufficient?

1 Like

==> @rmruthyun
Thanks. As you pointed out, after my last post, I found matplotlib offers decent flavors of interactive functions too. I think that’s enough to navigate / investigate simulation data.

By now, I think I can add a function to handle logic bus.
Just to confirm that you use “boolean” output of “bus label” like below?
This way, I can see how many bits on the port from my Python code.

image


==> @physicboy
Thanks for the link of nice library.
I’m thinking to stay with matplotlib for now until we hit a big roadblock of plotting with matplotlib.
I didn’t check it in detail but anything “Qt” must be pretty and supporting everything GUI programs need (but demanding more coding effort :stuck_out_tongue: ).

yes I have been using the boolean datatype.

Release 2024.01.03 · Qorvo/PyQSPICE (github.com)

In the course of digital bus plotting, it’s easy for me to have UTF-8 version of my netlist and I made it automated with the qsch2cir() method.

A snapshot uploaded below 70_Verilogbus. The main PyQSPICE module / methods are not updated yet but this .ipynb notebook contains flattened code.

image

  • Maybe re-compile needed on your QSPICE schematic window from the cntr.v Verilog file (though I uploaded DLL binary which is working for me).
  • I’m using ipympl module for an interactive plot area on Jupyter Lab.
    Please install it as needed.
  • Once everything’s good, you will have a plot area (below).
    Mouse hover will show cursor reading of bus value.
  • Lower grid of sine wave is nothing but for mixed signal plotting example :slight_smile:

  • Interactive procedures on matlab can do bus signal (3:0) stacking / separation…not implemented yet.
  • This mouse reading is slow…no optimization implemented yet.
  • I’m not changing bus value text font size, so a frequently changing bus plot will be messy but zooming into the plot will your label visible.
    I have fragments of codes for “range slider” to zoom in x-axes (= time) but commented out now in the ipynb (not fully working in a pretty manner).
  • I’ll wrap this bus plotting routine as new PyQSPICE method so to make it happen with less user code.