/spice-sim
Add or run an ngspice-backed Zener testbench with `pcb sim`.
Claude Code
$ npx -y skills add diodeinc/pcb --skill spice-sim --agent claude-code
Codex
$ npx skills add diodeinc/pcb --skill spice-sim -a codex -y
Cursor
$ npx skills add diodeinc/pcb --skill spice-sim -a cursor -y
Gemini CLI
$ npx skills add diodeinc/pcb --skill spice-sim -a gemini-cli -y
GitHub Copilot
$ npx skills add diodeinc/pcb --skill spice-sim -a github-copilot -y
OpenCode
$ npx skills add diodeinc/pcb --skill spice-sim -a opencode -y
Windsurf
$ npx skills add diodeinc/pcb --skill spice-sim -a windsurf -y
SKILL.md
spice-sim.SKILL.mdname: spice-sim
description: Add or run an ngspice-backed Zener testbench with `pcb sim`.
Spice Simulation
Use a focused testbench such as `<package>/testbench/test_<scenario>.zen` for one behavior: startup, enable, a protection threshold, or current limit. Reuse an existing bench when it covers the request. Run it with `pcb sim -v <file>.zen`; a separate dummy simulation is only useful when diagnosing setup problems.
`pcb sim` runs the `ngspice` executable in batch mode in the testbench's directory and waits for it to finish; it sets no time limit. Without `-v`, a successful run prints only that it passed.
Model and testbench
Every component that is not DNP needs a SPICE model. The stdlib generics, such as resistors, capacitors, inductors, ferrite beads, crystals, diodes, LEDs, and TVS diodes, have their own. A leaf component needs `spice_model=SpiceModel(...)`. Obtain a vendor model or, when appropriate, use a behavioral model with explicit limitations. Match `nets` to the subcircuit's declared terminal order, and pass every `PARAMS:` entry in `args`, because defaults are not applied:
Component(
name="MyPart",
symbol=Symbol(library="MyPart.kicad_sym"),
footprint=File("MyPart.kicad_mod"),
part=Part(mpn="MYPART-1", manufacturer="Vendor"),
pins={"VIN": VIN, "VOUT": VOUT, "GND": GND},
spice_model=SpiceModel(
"MyPart.lib",
"MyPart_SUBCKT",
nets=[VIN, VOUT, GND],
args={},
),
)The model text goes into the netlist, so a `.include` in the model file resolves from the testbench's directory. The `.subckt` line must list all its terminals on one line; terminals on `+` continuation lines are not counted. For a PSpice model, put `set ngbehavior=psa` in a `.spiceinit` file beside the testbench; for an LTspice model, `set ngbehavior=ltpsa`. Without it, PSpice expressions such as `VALUE={LIMIT(...)}` give wrong results without an error. Verilog-A and encrypted models do not run.
Instantiate the module under test and needed loads/passives in Zener. Put sources, waveforms, analysis, and plot commands in the raw ngspice `setup` string of a top-level `Simulation`:
load("@stdlib/properties.zen", "Simulation")
Simulation(
name="SIM",
setup="""
V_IN VIN GND DC 12
.control
tran 10u 10m
meas tran vout_final FIND v(VOUT) AT=10m
set hcopydevtype = svg
hardcopy output/startup.svg v(VIN) v(VOUT)
.endc
""",
)Adapt the source and analysis to the behavior; for example, `PULSE(...)` for enable timing or `PWL(...)` for a changing input. Operating point, DC sweep, AC, transient, and noise analyses all run.
Results
`pcb sim` reports success whenever ngspice exits normally, including when a `meas` fails, a plot is not written, or an expression divides by zero. Read the `-v` output: take values from `meas` or `echo` lines, because `print` tables lose their column separators. `hardcopy` and `wrdata` write only into an existing directory, so create `testbench/output/` first. Convert an SVG plot to PNG with `rsvg-convert` before viewing it, and inspect only the signals needed to establish the result.
Because nothing stops a long analysis, choose the `tran` stop time and step for the run time you can afford before starting it. A switching converter at nanosecond steps takes about 2 to 5 seconds per simulated millisecond.
Distinguish a model or simulator failure from an electrical finding, and state what the model and analysis actually verify.
Read more
name: spice-sim description: Add or run an ngspice-backed Zener testbench with `pcb sim`.
Spice Simulation
Use a focused testbench such as `<package>/testbench/test_<scenario>.zen` for one behavior: startup, enable, a protection threshold, or current limit. Reuse an existing bench when it covers the request. Run it with `pcb sim -v <file>.zen`; a separate dummy simulation is only useful when diagnosing setup problems.
`pcb sim` runs the `ngspice` executable in batch mode in the testbench's directory and waits for it to finish; it sets no time limit. Without `-v`, a successful run prints only that it passed.
Model and testbench
Every component that is not DNP needs a SPICE model. The stdlib generics, such as resistors, capacitors, inductors, ferrite beads, crystals, diodes, LEDs, and TVS diodes, have their own. A leaf component needs `spice_model=SpiceModel(...)`. Obtain a vendor model or, when appropriate, use a behavioral model with explicit limitations. Match `nets` to the subcircuit's declared terminal order, and pass every `PARAMS:` entry in `args`, because defaults are not applied:
Component(
name="MyPart",
symbol=Symbol(library="MyPart.kicad_sym"),
footprint=File("MyPart.kicad_mod"),
part=Part(mpn="MYPART-1", manufacturer="Vendor"),
pins={"VIN": VIN, "VOUT": VOUT, "GND": GND},
spice_model=SpiceModel(
"MyPart.lib",
"MyPart_SUBCKT",
nets=[VIN, VOUT, GND],
args={},
),
)The model text goes into the netlist, so a `.include` in the model file resolves from the testbench's directory. The `.subckt` line must list all its terminals on one line; terminals on `+` continuation lines are not counted. For a PSpice model, put `set ngbehavior=psa` in a `.spiceinit` file beside the testbench; for an LTspice model, `set ngbehavior=ltpsa`. Without it, PSpice expressions such as `VALUE={LIMIT(...)}` give wrong results without an error. Verilog-A and encrypted models do not run.
Instantiate the module under test and needed loads/passives in Zener. Put sources, waveforms, analysis, and plot commands in the raw ngspice `setup` string of a top-level `Simulation`:
load("@stdlib/properties.zen", "Simulation")
Simulation(
name="SIM",
setup="""
V_IN VIN GND DC 12
.control
tran 10u 10m
meas tran vout_final FIND v(VOUT) AT=10m
set hcopydevtype = svg
hardcopy output/startup.svg v(VIN) v(VOUT)
.endc
""",
)Adapt the source and analysis to the behavior; for example, `PULSE(...)` for enable timing or `PWL(...)` for a changing input. Operating point, DC sweep, AC, transient, and noise analyses all run.
Results
`pcb sim` reports success whenever ngspice exits normally, including when a `meas` fails, a plot is not written, or an expression divides by zero. Read the `-v` output: take values from `meas` or `echo` lines, because `print` tables lose their column separators. `hardcopy` and `wrdata` write only into an existing directory, so create `testbench/output/` first. Convert an SVG plot to PNG with `rsvg-convert` before viewing it, and inspect only the signals needed to establish the result.
Because nothing stops a long analysis, choose the `tran` stop time and step for the run time you can afford before starting it. A switching converter at nanosecond steps takes about 2 to 5 seconds per simulated millisecond.
Distinguish a model or simulator failure from an electrical finding, and state what the model and analysis actually verify.
pcb is a command-line tool for circuit board projects written in Zener. Zener is a Starlark-based language for describing PCB schematics; pcb builds those designs, manages dependencies, and generates KiCad layout files.
Other skills on pcb.
More skills from other plugins.
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or…
ask-matt
Ask which skill or flow fits your situation. A router over the skills in this repo.
Questions about spice-sim.
- Which coding agents can use spice-sim?
- spice-sim installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.

