From 8309d1cd890eae964e24928265614ce94192533b Mon Sep 17 00:00:00 2001 From: Vaino Kauppila Date: Sun, 11 Oct 2026 12:56:22 +0300 Subject: Initial commit: kisim — run KiCad schematics in ngspice from Python MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Single-file framework: kicad-cli netlist export, netlist edits, ngspice batch runs, results as numpy arrays by schematic name; test-case and corner-sweep helpers. Plus micromamba env (kicad_work), README, gitignore. --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 README.md (limited to 'README.md') diff --git a/README.md b/README.md new file mode 100644 index 0000000..da5996c --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +# kisim — run KiCad schematics in ngspice from Python + +`kisim.py` is a single-file simulation framework with no project knowledge. It: + +1. exports a `.kicad_sch` to a SPICE netlist with `kicad-cli`, +2. edits the netlist (instance parameters, source waveforms, regex substitutions), +3. runs `ngspice -b`, and +4. hands the results back as numpy arrays addressed by the schematic's own net + and device names — e.g. `r.v("+28V")`, `r.i("V1")`, `r.p("Q2")`, `r.at("i(v1)", 0.1)`. + +It also carries test-case and worst-case helpers (`Case`, `run_cases`, +`corners`, `tol`, `Wave`, `stim`, `worst`) and caches runs keyed on the +generated netlist. + +**The module docstring in `kisim.py` is the full API reference.** + +## Environment + +Everything runs in the `kicad_work` micromamba environment: + +```sh +micromamba create -n kicad_work -f environment.yml +micromamba activate kicad_work +micromamba run -n kicad_work python my_sim.py +``` + +Required on the system (not in the env): + +- `kicad-cli` — schematic → SPICE netlist export (KiCad ≥ 7; developed on 10.0.6) +- `ngspice` — the simulator (developed on ngspice-47) + +## Usage + +From a script in a project folder one level under this one: + +```python +import sys +from pathlib import Path +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from kisim import KiSim + +sim = KiSim("my_sim.kicad_sch", tran="10u 400m") +r = sim.run() # -> results/run.cir + run.raw (cached) +print(r.v("+28V")[-1], r.i("V1").max()) +r.plot(["+28V", "i(V1)", "Q2:power"]) +``` + +`save=[...]`, `power=[...]` and `currents=` control what gets probed — worth +using for big vendor models, where thousands of internal nodes make huge, slow +raw files. + +## Notes + +- `results/*.raw` and regenerated `results/*.cir` files are gitignored; they + are rebuilt by running the sims. +- Initially developed for the ASPECT+ payload board sims (2026). -- cgit v1.3