You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .claude/skills/spicesharp-circuit-design/SKILL.md
+80-9Lines changed: 80 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
name: spicesharp-circuit-design
3
-
description: Structured R&D problem-solving with test-driven verification for designing analog circuits using SpiceSharp and SpiceSharpParser that produces human-readable reports, netlist and tests and maintains a global backlog of active designs.
3
+
description: Structured R&D problem-solving with test-driven verification for designing analog circuits using SpiceSharp and SpiceSharpParser, including modern parser features such as .MEAS, .FOUR, .PRINT, .PLOT, .STEP, .TEMP, .MC, .NOISE, behavioral and LAPLACE sources, and local documentation/test-suite validation. Produces human-readable reports, netlists, tests, and maintains a global backlog of active designs.
4
4
user-invocable: true
5
5
---
6
6
@@ -85,6 +85,30 @@ tests/
85
85
86
86
---
87
87
88
+
## Current SpiceSharpParser Feature Surface
89
+
90
+
Use the parser's current netlist features directly instead of reimplementing post-processing in ad-hoc C# when a dot statement exists. For exact syntax, read `src/docs/index.md` first, then the specific article and matching tests under `src/SpiceSharpParser.IntegrationTests/`.
91
+
92
+
| Category | Supported features | Primary references |
| Sources/devices | R, C, L, K, D, Q, J, M, V, I, B, E/F/G/H, S/W switches, T transmission line, BVDelay, PULSE/SIN/PWL/EXP/SFFM/AM/WAVE/wavefile, VALUE/TABLE/POLY/LAPLACE | matching component articles and integration tests |
100
+
101
+
Prefer netlist-native controls for reproducibility:
102
+
- Use `.MEAS` for scalar acceptance criteria, including `TRIG/TARG`, `WHEN`, `FIND`, `MAX`, `MIN`, `AVG`, `RMS`, `PP`, `INTEG`, `DERIV`, and `PARAM`.
103
+
- Use `.FOUR` for settled-period harmonic magnitude, phase, normalized dB, and THD from transient waveforms.
104
+
- Use `.PRINT` for tabular exported data and `.PLOT` for structured XY plot data when reports need curves.
105
+
- Use `.WAVE` only when a transient waveform must be exported to a WAV file as a design artifact.
106
+
- Use `.STEP`, `.TEMP`, `.MC`, and `.DISTRIBUTION` for sweeps, corners, and statistical robustness instead of manual loops.
107
+
108
+
When `CircuitBuilder` has no dedicated helper for a current feature, use `RawLine()` with the exact netlist statement (for example `.RawLine(".FOUR 1k V(OUT)")`, `.RawLine(".STEP PARAM r LIST 1k 2k 5k")`, `.RawLine(".PLOT TRAN V(OUT) merge")`).
109
+
110
+
---
111
+
88
112
## Phases
89
113
90
114
Phases are guidelines, not a rigid waterfall. Skip or merge phases when the situation warrants it (e.g., skip Phase 2 if the user specifies the topology; merge Phases 3-4 for simple circuits).
@@ -115,7 +139,7 @@ Create xUnit test project in `tests/CircuitTests/` targeting **net8.0**:
115
139
1. Ask the user what circuit they want and its purpose
116
140
2.**WebSearch** the circuit type for standard specs, typical values, and design trade-offs
117
141
3. Elicit quantitative specs (frequency, gain, impedance, supply, bandwidth, Q, noise, timing)
5. Create `circuits/<name>/requirements.md` with spec table, operating conditions, acceptance criteria
120
144
6. Update `backlog.md`
121
145
@@ -142,13 +166,18 @@ Create xUnit test project in `tests/CircuitTests/` targeting **net8.0**:
142
166
1. Write netlist to `circuits/<name>/<name>.cir` — use `CircuitBuilder` for programmatic construction when beneficial
143
167
2.**Run `SmokeTester.QuickCheck()`** — fix any structural issues before proceeding
144
168
3. Run `NetlistLinter.Lint()` for additional validation
145
-
4. Include `.MEAS` directives for ALL specs that need automated verification
169
+
4. Include `.MEAS` directives for ALL scalar specs that need automated verification
170
+
5. Add `.FOUR` for THD/harmonic specs, `.PRINT` for tabular report data, `.PLOT` for reusable curve data, and `.WAVE` only for requested audio artifacts
146
171
147
172
**SPICE quick reference**: For syntax details (devices, waveforms, analyses, expressions), read `src/SpiceSharpParser.IntegrationTests/` examples or use WebSearch. Key rules:
148
173
- Ground is node `0`; every node needs DC path to ground (add 1GΩ if needed)
149
174
- Every semiconductor needs `.MODEL`
150
175
- AC analysis: use `VM()`/`VDB()`/`VP()`, never plain `V()`
151
-
- Prefer `.MEAS` over `.SAVE` for spec verification
176
+
- Prefer `.MEAS` over `.SAVE` for scalar spec verification; use `.SAVE`/`.PRINT`/`.PLOT` only when waveform/table/plot data is actually needed
177
+
- Use `.LET` for reusable dynamic expressions such as power or gain, `.FUNC` for reusable equations, and `.SPARAM` only when immediate scalar evaluation is required before setup/sweeps
178
+
- Use `.TEMP` for temperature corners and `.STEP PARAM temp_val` + `.OPTIONS TEMP={temp_val}` for continuous temperature sweeps
179
+
- Use `.MC` with `.DISTRIBUTION`/`.APPENDMODEL` for statistical validation once nominal and deterministic corner tests pass
180
+
- Use `.CONNECT` to intentionally short aliases or package pins; prefer clear shared node names when designing from scratch
152
181
153
182
#### LAPLACE Transfer Sources
154
183
@@ -192,17 +221,50 @@ Rules and gotchas:
192
221
-`G` and `F` current is defined from `out+` to `out-`; with a grounded load this may produce inverted output voltage.
193
222
- For details and examples, read `src/docs/articles/laplace.md`, `src/docs/articles/laplace-basics.md`, and `src/SpiceSharpParser.IntegrationTests/AnalogBehavioralModeling/LaplaceTests.cs`.
194
223
224
+
#### `.FOUR` Fourier / THD Post-Processing
225
+
226
+
Use `.FOUR` when the requirement includes THD, harmonic content, distortion cleanup, phase of harmonics, square-wave harmonic ratios, or before/after filter harmonic comparison. It is netlist-driven transient post-processing; prefer it over hand-written FFT code when the desired result is a settled periodic waveform metric.
-`.FOUR` requires `.TRAN`; it analyzes the last complete period, so run long enough for startup to settle and for at least one full final period.
246
+
- Choose the true repetition frequency. A wrong `f0` creates misleading harmonics and THD.
247
+
- Use a small max step; aim for at least 20 samples per highest harmonic period, and 50-100 samples for good magnitudes.
248
+
- Results are stored in `model.FourierAnalyses`, one result per signal per transient simulation or `.STEP` point.
249
+
- Each result has `SignalName`, `SimulationName`, `FundamentalFrequency`, `TotalHarmonicDistortionPercent`, `Success`, `ErrorMessage`, and `Harmonics`.
250
+
- Harmonic rows cover DC and harmonics 1-9 with `Magnitude`, `PhaseDegrees`, `NormalizedMagnitude`, and `NormalizedMagnitudeDecibels`; THD is computed from harmonics 2-9.
251
+
- If using `CircuitBuilder`, add `.FOUR` with `RawLine()`; there is no dedicated builder helper.
252
+
- For exact behavior and examples, read `src/docs/articles/four.md` and `src/SpiceSharpParser.IntegrationTests/DotStatements/FourTests.cs`.
253
+
195
254
### Phase 5: Simulation & Verification
196
255
197
256
**Every design MUST produce `tests/<CircuitName>Tests.cs`.**
198
257
199
258
- One test method per spec, descriptive names: `BandpassFilter_Has3dBBandwidthOf10kHz`
200
259
- Inline netlist as string constant; use `CircuitTestHelper` methods
201
-
- Use `WaveformAnalyzer` for complex analysis (FFT, THD, stability margins, rise time)
260
+
- Prefer `.MEAS` assertions for scalar specs; check `.Success` before reading `.Value`
261
+
- Assert `.FOUR` results from `model.FourierAnalyses` for harmonic/THD/phase specs
262
+
- Assert `.PRINT` data through `model.Prints` and `.PLOT` data through `model.XyPlots` when report tables or curves are part of the acceptance criteria
263
+
- Use `WaveformAnalyzer` for analysis that has no netlist-native equivalent or for C#-side cross-checks (custom FFT, extra THD checks, stability margins, rise/fall/settling metrics)
202
264
- Run `dotnet test --logger "trx"` — all must pass before Phase 6
203
265
-**10+ assertions per circuit is normal** — verify primary specs, boundary behavior, DC bias, passband/stopband, transient behavior, phase response, sanity checks
204
266
205
-
**Tolerance analysis**: After nominal passes, add tests with `.STEP`/`.MC` for ±5-10% component tolerances.
267
+
**Robustness analysis**: After nominal passes, add deterministic `.STEP` tests for tolerance/corner sweeps, `.TEMP` tests for temperature corners, and `.MC`tests with explicit `SEED=`for statistical checks. Use `.DISTRIBUTION` and `.APPENDMODEL` when device/model variation matters.
206
268
207
269
#### Hypothesis-Driven Fix Protocol
208
270
@@ -250,7 +312,8 @@ For full API details, read the source files directly — don't rely on this summ
250
312
|**NetlistLinter**|`src/SpiceSharpParser/Validation/NetlistLinter.cs`| After `ParseAndRead()`, before tests. Catches missing DC paths, missing models, duplicates. |
|**SensitivityAnalyzer**|`src/SpiceSharpParser/Analysis/SensitivityAnalyzer.cs`| Hypothesis-driven debugging: find which component affects which spec |
255
318
|**DesignSpaceExplorer**|`src/SpiceSharpParser/Analysis/DesignSpaceExplorer.cs`| Multi-parameter optimization with objectives and constraints |
256
319
|**CircuitBuilder**|`src/SpiceSharpParser/Builder/CircuitBuilder.cs`| Fluent API for programmatic netlist construction and modification |
@@ -260,9 +323,9 @@ For full API details, read the source files directly — don't rely on this summ
260
323
261
324
1.**Phase 3** → `StandardValues.NearestE24()` to snap values
262
325
2.**Phase 4** → `CircuitBuilder` to construct, `SmokeTester.QuickCheck()` to validate
@@ -468,6 +533,8 @@ var counts = inspector.GetComponentCounts();
468
533
469
534
All-static methods for analyzing simulation output waveforms. Data is passed as `List<(double, double)>` tuples collected from simulation exports.
470
535
536
+
For THD/harmonic acceptance criteria, prefer netlist `.FOUR` when possible because it selects the last complete transient period, reports phase and normalized dB, and stores structured results in `model.FourierAnalyses`. Use `WaveformAnalyzer.FFT()`/`THD()` when you need a custom C#-side spectrum or an independent cross-check.
537
+
471
538
**Time-domain methods:**
472
539
-`RiseTime(data, lowPct=0.1, highPct=0.9)` — 10%-90% rise time
473
540
-`FallTime(data, highPct=0.9, lowPct=0.1)` — 90%-10% fall time
@@ -698,6 +765,7 @@ When writing tests, consult these for patterns and inspiration:
| Zero/empty results | 3-step run pattern? (`Run` → `InvokeEvents` → `ToArray`) Exports filtered by simulation? |
713
781
| Wrong AC results | Using `VM()`/`VDB()` not `V()`? Matched-system 0dB ref = 0.5V not 1V? |
714
782
| Wrong values |`.MODEL` realistic? Node connectivity correct? Units in SI? Sim long enough? |
783
+
|`.FOUR` missing/failed |`.TRAN` present? At least one complete final period? Signal expression valid? Check `model.FourierAnalyses[*].Success/ErrorMessage`|
784
+
|`.FOUR` THD/harmonics odd | Fundamental frequency correct? Max step small enough? Final cycles settled? |
785
+
|`.STEP`/`.TEMP` result count unexpected | Measurements and Fourier results produce one result per generated simulation; inspect `SimulationName`|
Copy file name to clipboardExpand all lines: src/docs/articles/intro.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,8 @@ Using SpiceSharpParser involves three steps:
55
55
2.**Read** — translate the parse-tree model into SpiceSharp simulation objects (circuit, simulations, exports) with `SpiceSharpReader.Read()`.
56
56
3.**Simulate** — run the SpiceSharp simulations and collect results via exports and events.
57
57
58
+
For a detailed look at how SpiceSharp solves the circuit after this handoff, including modified nodal analysis, sparse matrix solving, and component stamps, see [How SpiceSharp Solves Circuits](spicesharp-architecture.md).
59
+
58
60
### The SpiceSharpModel
59
61
60
62
`SpiceSharpReader.Read()` returns a `SpiceSharpModel` containing:
0 commit comments