Skip to content

NgSpice/Shared.py: Make ngspice warning detection more robust - #6

Open
e-dworkin wants to merge 1 commit into
infinitymdm:masterfrom
e-dworkin:master
Open

NgSpice/Shared.py: Make ngspice warning detection more robust#6
e-dworkin wants to merge 1 commit into
infinitymdm:masterfrom
e-dworkin:master

Conversation

@e-dworkin

@e-dworkin e-dworkin commented Jul 24, 2026

Copy link
Copy Markdown

This single-line PR changes the way that PySpice/Spice/NgSpice/Shared.py:_send_char detects warnings versus errors. The current system detects warnings by content.startswith('Warning:'). This is an issue or any warning message that does not start with the exact string 'Warning:'. The fix is to make this more robust by checking 'Warning: in content`.

This was causing an issue with larger, stiffer netlists that required dynamic gmin stepping in order to converge. Ngspice can simulate these just fine with dynamic gmin stepping, but in doing so generates a line such as: Trying gmin = [...] Warning: Further gmin increment. This is a benign warning, but is detected as a fatal error since 'Warning:' appears in the middle of the string rather than at the beginning. Thus, PySpice then discards the simulation since it believes it has errored.

Here is a sample netlist that was causing this failure and requiring dynamic gmin stepping, using FreePDK45 and ngspice 41. It was characterized through CharLib:

*** Model include file — FreePDK45 (open-source) ***
* BSIM4 (level=54) Predictive Technology Models, nom corner.


* ---- Raw PTM device models (drawn L = 50 nm) ----
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/NMOS_VTG.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/PMOS_VTG.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/NMOS_VTL.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/PMOS_VTL.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/NMOS_VTH.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/PMOS_VTH.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/NMOS_THKOX.inc"
.include "/ALL_PDK/FreePDK45/ncsu_basekit/models/hspice/tran_models/models_nom/PMOS_THKOX.inc"

* ---- Parameterized 4-terminal wrappers (drain gate source bulk) ----
.subckt nmos_vtg d g s b w=0.1u l=0.05u nf=1
M0 d g s b NMOS_VTG w=w l=l m=nf
.ends nmos_vtg
.subckt pmos_vtg d g s b w=0.1u l=0.05u nf=1
M0 d g s b PMOS_VTG w=w l=l m=nf
.ends pmos_vtg
.subckt nmos_vtl d g s b w=0.1u l=0.05u nf=1
M0 d g s b NMOS_VTL w=w l=l m=nf
.ends nmos_vtl
.subckt pmos_vtl d g s b w=0.1u l=0.05u nf=1
M0 d g s b PMOS_VTL w=w l=l m=nf
.ends pmos_vtl
.subckt nmos_vth d g s b w=0.1u l=0.05u nf=1
M0 d g s b NMOS_VTH w=w l=l m=nf
.ends nmos_vth
.subckt pmos_vth d g s b w=0.1u l=0.05u nf=1
M0 d g s b PMOS_VTH w=w l=l m=nf
.ends pmos_vth
.subckt nmos_thkox d g s b w=0.1u l=0.05u nf=1
M0 d g s b NMOS_THKOX w=w l=l m=nf
.ends nmos_thkox
.subckt pmos_thkox d g s b w=0.1u l=0.05u nf=1
M0 d g s b PMOS_THKOX w=w l=l m=nf
.ends pmos_thkox


* TX unit driver + channel RC + N-lane wrapper — generated by CLIPGen

.subckt tx IN VDD VSS RX_IN
xnm1 out1 IN VSS VSS nmos_vtg w=0.4u l=0.05u nf=1
xpm1 out1 IN VDD VDD pmos_vtg w=0.6u l=0.05u nf=1
xnm2 out2 out1 VSS VSS nmos_vtg w=0.64025u l=0.05u nf=2
xpm2 out2 out1 VDD VDD pmos_vtg w=0.9604u l=0.05u nf=2
xnm3 out3 out2 VSS VSS nmos_vtg w=0.8198399999999999u l=0.05u nf=5
xpm3 out3 out2 VDD VDD pmos_vtg w=0.8784u l=0.05u nf=7
xnm4 out4 out3 VSS VSS nmos_vtg w=0.9373357142857143u l=0.05u nf=14
xpm4 out4 out3 VDD VDD pmos_vtg w=0.9842000000000001u l=0.05u nf=20
xnm5 out5 out4 VSS VSS nmos_vtg w=0.9769534883720931u l=0.05u nf=43
xpm5 out5 out4 VDD VDD pmos_vtg w=0.9845875u l=0.05u nf=64
xnm6 out6 out5 VSS VSS nmos_vtg w=0.9961614814814814u l=0.05u nf=135
xpm6 out6 out5 VDD VDD pmos_vtg w=0.9986272277227723u l=0.05u nf=202
xnm7 out7 out6 VSS VSS nmos_vtg w=0.9988654292343389u l=0.05u nf=431
xpm7 out7 out6 VDD VDD pmos_vtg w=0.9996385448916408u l=0.05u nf=646
xnm8 eq_in out7 VSS VSS nmos_vtg w=0.9994031907179115u l=0.05u nf=1379
xpm8 eq_in out7 VDD VDD pmos_vtg w=0.999644825918762u l=0.05u nf=2068
Req eq_in TXPAD 70.3819
Ceq TXPAD VSS 1313.4356f
Cpad_chip TXPAD VSS 276.2448f
Rbump TXPAD n_bump 0.004060
Cbump n_bump VSS 3.7358f
Ctr_near n_bump VSS 616.6667f
Rtr1 n_bump n_tr1 6.933333
Ctr1 n_tr1 VSS 1233.3333f
Rtr2 n_tr1 n_tr2 6.933333
Ctr2 n_tr2 VSS 1233.3333f
Rtr3 n_tr2 n_tr3 6.933333
Ctr_far n_tr3 VSS 616.6667f
Rpad_ipos n_tr3 n_ipad 0.005313
Cpad_ipos n_ipad VSS 220.9958f
Rrx_bump n_ipad n_rxbump 0.004060
Crx_bump n_rxbump VSS 3.7358f
Rrx_pad n_rxbump RX_IN 0.005313
Crx_pad RX_IN VSS 276.2448f
Crx_esd RX_IN VSS 18.0900f
.ends tx

.subckt txip IN_0 IN_1 IN_2 IN_3 IN_4 IN_5 IN_6 IN_7 PAD_0 PAD_1 PAD_2 PAD_3 PAD_4 PAD_5 PAD_6 PAD_7 VDD VSS
xtx0 IN_0 VDD VSS PAD_0 tx
xtx1 IN_1 VDD VSS PAD_1 tx
xtx2 IN_2 VDD VSS PAD_2 tx
xtx3 IN_3 VDD VSS PAD_3 tx
xtx4 IN_4 VDD VSS PAD_4 tx
xtx5 IN_5 VDD VSS PAD_5 tx
xtx6 IN_6 VDD VSS PAD_6 tx
xtx7 IN_7 VDD VSS PAD_7 tx
.ends txip

Summary by CodeRabbit

  • Bug Fixes
    • Improved warning detection so simulator messages containing “Warning:” are consistently classified and displayed as warnings.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dff020cc-c77f-442c-bcb9-7db3b9a35984

📥 Commits

Reviewing files that changed from the base of the PR and between da81c4d and 97883d9.

📒 Files selected for processing (1)
  • PySpice/Spice/NgSpice/Shared.py

📝 Walkthrough

Walkthrough

NgSpice stderr classification now recognizes "Warning:" anywhere in message content instead of only at the beginning.

Changes

Warning classification

Layer / File(s) Summary
Broaden stderr warning detection
PySpice/Spice/NgSpice/Shared.py
NgSpiceShared._send_char classifies content containing "Warning:" as a warning.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Poem

A rabbit spots a warning glow,
No matter where the words may show.
Through stderr’s trail, the markers leap,
Into the warning basket deep.
Hop, hop—classification’s clear!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: more robust ngspice warning detection in Shared.py.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant