PyQSPICE with Hierarchical Elements

I have a Qspice simulation with .dll and other hierarchical blocks which runs perfectly without even a warning. However, when I try to run the file using the PyQSPICE, I see the warning of

Didn’t find a model for “HIERARCHICAL” – defaults assumed.
Warning: Ignoring unknown instance parameter “ELEMENT” of device COULD.

Warning: Unexpected number, “hierarchical model name”, in device COULD.

Fatal error:
This circuit does not say which node is ground.

In my code, I have

from PyQSPICE import clsQSPICE as pqs

run = pqs(“hierarchical model 1”)
run = pqs(“hierarchical model 2”)
run = pqs(“hierarchical model 3”)

run = pqs(“main simulation file”)

What to do with the symbol files?? I need some help regarding this issue. Thanks in advance!

Hey @masashi.nogawa , I encounterred similar problem as @a.farakhor described.
The simulation files (including main and subcomponents qsch file, cpp file, dll file associated) are put in same folder, and I can open the schematic/run simulation with Qspice normally.

Then I created a python script under same folder, to run it in pyqspice, the code is simply follows the examples:

from PyQSPICE import clsQSPICE as pqs
run = pqs("mainfile.qsch")
run.InitPlot()
run.qsch2cir()
run.cir2qraw()
...

where I get the same warning /error:

Didn’t find a model for “HIERARCHICAL” – defaults assumed
...
Fatal error:
This circuit does not say which node is ground.

So, follow your suggestions, I tried to directly call QSPICE64.exe to run the project but get:

c:/QSPICE/QSPICE64.exe mainfile.qsch

Fatal error: Unknown device type: '½'

The problem occured while parsing the line:
   ½COMPONENT -13000,-800 0 0

Tried QSPICE80.exe but same result. The error complained is actually the 1st component in the qsch file so seems fails at beginning of parsing the schematic file.

Interestingly, in the qspice GUI, all things goes pretty smooth.
Anything could be missed here?

Thank you for your attention.

I found I made an mistake on my post on July 11, 2024.
I can’t modify my previous post, so I deleted it.
Please find the contents of my post on July 11, 2024, below with my correction.


Hi @weifan.enteligent ,

I’m so sorry, it’s totally my bad in my previous post…I made a bad mistake.

Please try this as our first step.

> QSPICE64.exe mainfile.cir
                        ^^^

As you already run the “qsch2cir()”, I believe you have your “.cir” netlist in the same folder.


I think this post is not addressing your hierarchy challenge yet…, please share your update by running QSPICE64.exe on the netlist “.cir” file manually.


My July 11, 2024 post, corrected.



I’m trying my best from your statements, if this is not enough, hope you can share a little bit more info.


For example, let’s assume your simulation files are this way:
/folder/subfolder/mainfile.qsch
/folder/subfolder/subfile1.qsch
/folder/subfolder/subfile2.qsch
/folder/subfolder/usermodule.dll

With this hierarchy simulation setup, please invoke your Python from the folder contains “mainfile.qsch” which is “/folder/subfolder” in this example.
(And we assume your mainfile.qsch has a proper path specification to the subfiles and DLL files as you wrote QSPICE runs without problems.)

After converting “.qsch” into “.cir” file with the qsch2cir() function, inside PyQSPICE, it just run a command of

QSPICE64.exe mainfile.cir

That means it’s the same you do this in cmd.exe:

cd c:\folder\subfolder
\path-to-QSPICE-installation\QSPICE64.exe main.cir

If this doesn’t work, PyQSPICE won’t work neither and I believe you will get the same error messages you wrote.

Hope this helps…if not, please share a little bit more info.


In my latest example, I do use a DLL and it works with this flat placement.


I didn’t check, by myself, for non-flat hierarchy so please kindly share your experience if that’s the case.

@masashi.nogawa Thanks for the reply. I just gave a try, and this time I got

c:/QSPICE/QSPICE64.exe manfile.cir
Didn't find a model for "HIERARCHICAL" -- defaults assumed.
Warning: Ignoring unknown instance parameter "ELEMENT" of device COULD.
Warning: Ignoring unknown instance parameter "TRANSFORMER_1P1S" of device COULD.
Warning: Ignoring unknown instance parameter "P1A" of device COULD.
Warning: Ignoring unknown instance parameter "P1B" of device COULD.
Warning: Ignoring unknown instance parameter "S1A" of device COULD.
Warning: Ignoring unknown instance parameter "S1B" of device COULD.
Fatal error:
This circuit does not say which node is ground.

Then I was checking the .cir file generated. open the mainfile.cir, what got is

Trouble netlisting: mainfile.qsch

  Could not resolve hierarchical element transformer_1p1s P1A P1B S1A S1B

The P1A P1B S1A S1B are pins of the transformer_1p1s component. We have its .qsch and .qsim file located in the same folder.

I was thinking whether it could be due to this sub-schematic missing .cir file, so I used qsch2cir() in pyqspice to generate its .cir file in the folder too. transofrmer_1p1s.cir file looks ok. But when I go back to run the mainfile by c:/QSPICE/QSPICE64.exe manfile.cir, I got the same error shown in the beginning of this post.

Hopefully can provide some clue, while feel free to let me know what else to try. Thanks!

Regards,

Wei

Btw, I just tried to run simulation of the transformer_1p1s (sub-schematic of the main file) by calling QSPICE64.exe:

c:/QSPICE/QSPICE64.exe transformer_1p1s.cir
Fatal error:
This circuit does not say which node is ground.

and this time, the result is the same as the QPSICE gui. i.e. when I ran simulation of transformer_1p1s.qsch in QSPICE, I got the same error and not able to go.

Look at this error, it is exactly what said when running the mainfile.cir . So I suspect that, when I ran the mainfile by QPSICE64.exe, it actually stopped by this error, which is generated when processing the transformer_1f1s.cir.

Thinking of that in the QSPICE GUI, the whole simulation works well. Another thing I just noticed is, running QSPICE GUI is not generating the .cir file (at least not explicitly geneate this file as an intermediate product).

So a picture in my mind is, maybe the QSPICE GUI worked on the hierachical schematic in a specifc order/steps, like process the schematic as whole (so not worrying about the ground in a sub-schematic), and when we directly call QSPICE64.exe or using PyQspice , it’s actaully not following that order of operations? or maybe there are some option args to specify? (just my wild thinking for a possbile path)

Appreciate for your feedbacks.

Regards,

Wei

Hi @weifan.enteligent

This is an update, not conclusive yet but want to proceed this investigation with you!


I tried to make my own test schematic with 2-layer hierarchy.
HierTest.qsch (14.8 KB)
SiC.txt (587 Bytes)

And this test-case works fine at my end. Schematic is generated and saved in “C:\TMP”…you may need to edit the path, making it work at your local folder if other than c:\tmp.

Though I can’t upload the netlist, the GUI can generate a netlist from this “qsch” and it works with

> QSPICE64.exe HierTest.cir.

From your post, you have “.qsym” components…next step is to check how QSPICE handles “.qsym” from command interface.

@masashi.nogawa
Generated the .cir file use PyQspice (calling run.qsch2cir() )
then call the QSpice64 exe to run the cir file, here is what I got:

c:/QSPICE/QSPICE64.exe HierTest.cir

C:\Users\Wei Fan\Documents\QSPICE\PID\test1\HierTest.cir
Starting Gmin stepping.
Warning: Gmin stepping failed.
Starting source stepping.
Source step succeeded.

Total elapsed time: 0.215535 seconds.

it seems working well to perform the simulation and stored the data in HierTest.qdraw generated.

Let me know what to do for the next step.

@weifan.enteligent

Thanks for your additional info offline.


Please update QSPICE to the latest and try again.
It was an error of generating a netlist from a hierarchical schematic tree, and I think the latest software can generate the netlist without any error.

@masashi.nogawa Just tried it works smoothly now. Many thanks for tracking this down!