Wishlist: Reliable way to get a .raw file from an NGspice simulation.

Bug #1788676 reported by Steve Wood
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
KiCad
Fix Released
Unknown

Bug Description

It is critical in my opinion to be able to reliably get a .raw file from a simulation run for use in a full-featured 3rd party waveform viewer, especially since the built-in KiCAD viewer is still young and missing some essential features (waveform expressions, subplots, zoom-undo, etc.).

Using ".control ... .endc" on the schematic doesn't always produce a rawfile, and if it does, the simulation must be often run twice to get a valid .raw file.

Please see
https://forum.kicad.info/t/how-can-i-generate-a-raw-file-for-use-in-a-3rd-party-waveform-viewer/12119/23?u=steve_kicad

In particular, the message from Holger:
"In fact adding a .control section to the eeschema generated netlist may raise some caveats.

It is largely untested in this environment (shared ngspice, simulation called by bg_run in a second thread) and thus bears some risk due to the multithreading involved. It may happen that the write command starts before the simulation has finished, then writing the old data.

It might be much better that the eeschema interface handles all the issues directly and care for thread synchronization. This has to be coded into eeschema. Therefore it is necessary to notify the KiCad developers and add these issues to the wishlist."

**********************************************

Application: kicad
Version: 5.0.0-fee4fd1~66~ubuntu18.04.1, release build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-32-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.65.1
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.58.0
    Compiler: GCC 7.3.0 with C++ ABI 1011

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=OFF
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON

Revision history for this message
Nick Østergaard (nickoe) wrote :

Please remember to add version information.

tags: added: export ngspice
description: updated
Revision history for this message
Steve Wood (steve+ubuntu) wrote :

What appears to be happening is that when a simulation is started through the KiCAD GUI, the .raw file from the previous simulation gets written. Thus, a simulation must be run twice after any changes if you want to update the .raw output. I've updated my installation:

Application: kicad
Version: 5.0.1-33cea8e~67~ubuntu18.04.1, release build
Libraries:
    wxWidgets 3.0.4
    libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-36-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
    wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 2.24
    Boost: 1.65.1
    OpenCASCADE Community Edition: 6.9.1
    Curl: 7.58.0
    Compiler: GCC 7.3.0 with C++ ABI 1011

Build settings:
    USE_WX_GRAPHICS_CONTEXT=OFF
    USE_WX_OVERLAY=OFF
    KICAD_SCRIPTING=ON
    KICAD_SCRIPTING_MODULES=ON
    KICAD_SCRIPTING_WXPYTHON=OFF
    KICAD_SCRIPTING_ACTION_MENU=ON
    BUILD_GITHUB_PLUGIN=ON
    KICAD_USE_OCE=ON
    KICAD_USE_OCC=OFF
    KICAD_SPICE=ON

Changed in kicad:
status: New → Triaged
importance: Undecided → Wishlist
Revision history for this message
Holger Vogt (h+vogt) wrote :

I propose to add some code to ngspice to allow handling of the .control section after the simulation has finished. A extra thread and some synchronization with the background thread that hosts the simulation are required. As of now using a .control section is without value.

Revision history for this message
Maciej Suminski (orsonmmz) wrote :

Sounds great, thank you for the offer! Let me know if there is anything we should do on our side. If the change is not backward compatible, then I would be grateful for giving us a way to recognize whether the ngspice library used by KiCad contains the change, e.g. by bumping the shared library version.

Revision history for this message
Holger Vogt (h+vogt) wrote :

There is now a code enhancement available on the ngspice git pre-master branch to allow all ngspice .control section commands (e.g. rusage, write etc.) to be executed after the simulation has finished.
To enable this, one has to set a flag right before the command in the simulator window text box (then valid for all commands following) or in spice.rc or .spiceinit for every command with

set controlswait

This code will move to master branch after some more testing, and finally into ngspice-30.

Holger

Revision history for this message
Holger Vogt (h+vogt) wrote :

The text box in the eeschema window (e.g. for the laser driver demo) may look like this:

.tran 10p 150n
.control
set controlswait
rusage
write d:\temp\ees_out.raw all
.endc

Holger

Revision history for this message
Wayne Stambaugh (stambaughw) wrote :

@Holger, thank you for efforts in supporting KiCad. Thanks to ng-spice, we can offer spice simulation support to our users.

Cheers,

Wayne

Revision history for this message
Holger Vogt (h+vogt) wrote :

ngspice-30 is available with the above cited patch (variable 'controlswait'

Holger

tags: added: eeschema
Revision history for this message
Holger Vogt (h+vogt) wrote :

With the advent of ngspice-30 there is a ngspice solution available.

Reason for the cited behavior:
.control section commands are started in the main thread at the same time or even before simulation is started in a second thread. Thus an old or empty file is saved by the write command.

Remedy
Add:
set controlswait
to .spiceinit or as the first command in the .control section.
This holds back all commands following until the simulation has finished.

There is no need to touch eeschema code.

Revision history for this message
KiCad Janitor (kicad-janitor) wrote :

KiCad bug tracker has moved to Gitlab. This report is now available here: https://gitlab.com/kicad/code/kicad/-/issues/2221

Changed in kicad:
status: Triaged → Expired
Changed in kicad:
importance: Wishlist → Unknown
status: Expired → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.