$npx -y skills add aklofas/kicad-happy --skill spiceRun automatic SPICE simulations on subcircuits detected from KiCad schematic analysis — validates filter frequencies, divider ratios, opamp gains, LC resonance, and crystal load capacitance. Supports ngspice, LTspice, and Xyce (auto-detected). Generates testbenches, runs batch mo
| 1 | # SPICE Simulation Skill |
| 2 | |
| 3 | Automatically generates and runs SPICE testbenches for circuit subcircuits detected by the `kicad` skill's schematic analyzer. Supports ngspice, LTspice, and Xyce (auto-detected). Validates calculated values (filter frequencies, divider ratios, opamp gains) against actual simulation results and produces a structured report. |
| 4 | |
| 5 | This skill inverts the typical simulation workflow: instead of requiring users to create simulation sources and configure analysis (which ~2.5% of KiCad users do), it generates targeted testbenches automatically from the analyzer's subcircuit detections. |
| 6 | |
| 7 | ## Related Skills |
| 8 | |
| 9 | | Skill | Purpose | |
| 10 | |-------|---------| |
| 11 | | `kicad` | Schematic/PCB analysis — produces the analyzer JSON this skill consumes | |
| 12 | | `digikey` | Parametric specs for behavioral models, datasheet downloads | |
| 13 | | `mouser` | Parametric specs (secondary source), datasheet downloads | |
| 14 | | `lcsc` | Parametric specs (no auth needed), datasheet downloads | |
| 15 | | `element14` | Parametric specs (international), datasheet downloads | |
| 16 | | `emc` | EMC pre-compliance — uses this skill's simulator infrastructure for SPICE-enhanced PDN impedance and EMI filter analysis | |
| 17 | |
| 18 | **Handoff guidance:** The `kicad` skill's `analyze_schematic.py` produces the analysis JSON with subcircuit detections in the flat `findings[]` array (filtered by `detector` field). This skill reads that JSON, generates SPICE testbenches for simulatable subcircuits, runs the detected simulator (ngspice/LTspice/Xyce), and produces a structured verification report. Always run the schematic analyzer first. During a design review, run simulation after the analyzer and before writing the final report — simulation results should appear as a verification section in the report. The `emc` skill reuses this skill's simulator backend for SPICE-enhanced PDN impedance and EMI filter insertion loss checks — when ngspice is available, the EMC skill's `--spice-enhanced` flag activates these checks automatically. |
| 19 | |
| 20 | ## Requirements |
| 21 | |
| 22 | - **A SPICE simulator** — one of the following (auto-detected, first available wins): |
| 23 | - **ngspice** — `sudo apt install ngspice` (Linux) / `brew install ngspice` (macOS) / ngspice.sourceforge.io (Windows). Most common choice. |
| 24 | - **LTspice** — free from analog.com/ltspice. Popular on Windows, works via wine on Linux. |
| 25 | - **Xyce** — from xyce.sandia.gov. Parallel SPICE for large circuits. |
| 26 | - Override with `--simulator ngspice|ltspice|xyce` or `SPICE_SIMULATOR` env var. |
| 27 | - **Python 3.10+** — stdlib only, no pip dependencies |
| 28 | - **Schematic analyzer JSON** — from `analyze_schematic.py --output` |
| 29 | |
| 30 | If no simulator is installed, skip simulation gracefully and note it in the report. Do not treat a missing simulator as an error — it's an optional enhancement. |
| 31 | |
| 32 | ## Workflow |
| 33 | |
| 34 | ### Step 1: Run the schematic analyzer |
| 35 | |
| 36 | ```bash |
| 37 | python3 <kicad-skill-path>/scripts/analyze_schematic.py design.kicad_sch --analysis-dir analysis/ |
| 38 | ``` |
| 39 | |
| 40 | ### Step 2: Run SPICE simulations |
| 41 | |
| 42 | Pass `--analysis-dir analysis/` — the script auto-resolves `schematic.json` |
| 43 | from the manifest's current run, writes `spice.json` into the same run |
| 44 | folder, and parks intermediate `.cir` / `.raw` files at |
| 45 | `<run>/spice_work/` by default. |
| 46 | |
| 47 | ```bash |
| 48 | # Recommended: auto-resolve schematic + write spice.json into the current run |
| 49 | python3 <skill-path>/scripts/simulate_subcircuits.py --analysis-dir analysis/ |
| 50 | |
| 51 | # Explicit form — positional or --schematic path |
| 52 | python3 <skill-path>/scripts/simulate_subcircuits.py analysis.json --output sim_report.json |
| 53 | |
| 54 | # Simulate specific types only |
| 55 | python3 <skill-path>/scripts/simulate_subcircuits.py --analysis-dir analysis/ --types rc_filters,voltage_dividers |
| 56 | |
| 57 | # Keep simulation files for debugging (default: <run>/spice_work/ when --analysis-dir is set, else a temp dir) |
| 58 | python3 <skill-path>/scripts/simulate_subcircuits.py --analysis-dir analysis/ --workdir ./spice_runs |
| 59 | |
| 60 | # Increase timeout for complex circuits (default: 5s per subcircuit) |
| 61 | python3 <skill-path>/scripts/simulate_subcircuits.py --analysis-dir analysis/ --timeout 10 |
| 62 | |
| 63 | # Omit file paths from output (cleaner for reports) |
| 64 | python3 <skill-path>/scripts/simulate_subci |