SPICE, reborn in Rust. Dune is a faithful rewrite of Berkeley's SPICE3f5 circuit simulator: the same netlists, the same defaults, the same numbers — validated circuit by circuit against ngspice — with a clean engine you can call from Python, R, JavaScript or C.
Dune is a derived work: the engine is a translation of the SPICE3f5
sources of the University of California, Berkeley, and some parts
(the BSIM3v3.3 and BSIM4 4.8.3 models, the VDMOS and VBIC models, the
KSPICE transmission lines, the extended diode, the .sp, .measure and
.four analyses, the operating-point fallback chain, the transient
noise sources and the revisions of several device routines) are derived
from ngspice release 47. See Credits and lineage and
NOTICE.
Site: milkway.github.io/dune · Examples gallery — every corpus circuit, simulated · Known differences
One engine, the same numbers from every one of them.
| Package | Install | Docs | |
|---|---|---|---|
| Python | spice3 (import spice) |
pip install spice3 |
PyPI |
| R | spice |
remotes::install_github("milkway/dune", subdir = "r") |
milkway.github.io/dune/r |
| JavaScript / WebAssembly | @strategicprojects/dune-sim |
npm install @strategicprojects/dune-sim |
npm |
| Rust | dune-core, dune-netlist, dune-raw, dune-pic |
cargo add dune-core dune-netlist |
docs.rs |
| C | dune-ffi (C ABI, include/dune.h) |
built from this repository | crates/dune-ffi |
| Command line | dune |
brew install milkway/tap/dune (macOS, Linux), or the binaries of the latest release |
crates/dune-cli |
A circuit arrives as a SPICE deck or as a schematic written in pic.
dune-core is the only place where circuits are solved; every
package is an interface to it.
Every point of every analysis is a Newton–Raphson loop: linearize the
devices, solve the linear system, test convergence at SPICE's own
tolerances. The sources of both diagrams are pic figures in
site/diagrams.
- Every SPICE3f5 device and analysis: R C L K, V/I sources, E F G H,
diode, BJT (Gummel–Poon), MOS levels 1–6, BSIM1/2, JFET, MESFET,
switches, ideal and lossy (LTRA) transmission lines,
.subckt— and.OP .DC .AC .TRAN .PZ .NOISE .DISTO .TF .SENS. - What modern decks need, from ngspice-47: BSIM3v3.3 and BSIM4
4.8.3, the VDMOS power MOSFET, the VBIC bipolar transistor, the KSPICE
lossy and coupled lines (
Y,P), the diode beyond the SPICE3 card (LEVEL=3), S-parameters (.sp),.four,.measure— and the netlist language of the open PDKs (.libsections, parameter expressions, subcircuit parameters, binning,.func,.if,temper, behavioural R/C/L,agausswith.options seed), so the gf180mcu and sky130 libraries are read as shipped. - Oracle-tested: nothing ships until every corpus circuit matches
pinned ngspice-47 goldens point by point, at SPICE's own tolerances
(
reltol/abstol/vntol). Deliberate divergences are documented incorpus/KNOWN_DIFFS.md, each behind a measured gate. - Schematics in, waveforms out: Dune reads figures written in
rpic's pic language and extracts runnable decks
(
dune pic figure.pic); the same engine powers the Simulate panel in rpic Studio, all client-side WebAssembly. - Rawfiles in SPICE3's own binary and ASCII formats, so existing viewers read them unchanged.
- A more accurate transient by default:
.tranintegrates with TR-BDF2, an L-stable method that does not ring and, on the corpus, is closer to the converged answer than the trapezoidal rule at the same step; a switch flips at the instant its control crosses the threshold, not at the first timepoint past it..options compat=spice3restores the SPICE3f5 defaults (the trapezoidal rule, switches on the grid), which is what the ngspice oracle checks.
# Python — PyPI (polars DataFrames, zero-copy numpy; module `import spice`)
pip install spice3
# JavaScript / WebAssembly — npm (runs in the browser)
npm install @strategicprojects/dune-sim
# R — tidy tibbles (CRAN submission planned)
Rscript -e 'remotes::install_github("milkway/dune", subdir = "r")'
# Rust library — crates.io (dune-netlist, dune-raw, dune-core, dune-pic)
cargo add dune-core dune-netlist
# CLI — Homebrew (macOS, Linux). homebrew-core's own `dune` is the
# OCaml build system, so the tap is part of the name
brew install milkway/tap/dune
# CLI — from source (Rust 1.88+)
git clone https://github.com/milkway/dune && cd dune && cargo build --releaseThe Rust crates are 0.x: the public API of dune-core may change
between minor versions.
import spice
run = spice.simulate("""
step into a series rlc
V1 in 0 PULSE(0 1 0 1n 1n 1 2)
R1 in n1 60
L1 n1 out 1m
C1 out 0 1n
.tran 0.1u 40u
.end
""")
run.plots[0].df() # polars DataFrame: time, v(in), v(out)…| Path | What |
|---|---|
crates/dune-core |
The engine: devices, analyses, solver |
crates/dune-netlist |
SPICE3f5-faithful netlist parser |
crates/dune-raw |
Rawfile reader/writer |
crates/dune-pic |
Netlist extraction from pic figures |
crates/dune-cli |
The dune command |
crates/dune-wasm |
WebAssembly bindings (@strategicprojects/dune-sim) |
crates/dune-ffi |
C ABI |
python/, r/ |
The spice3 (PyPI) and spice (R) packages |
corpus/ |
SPICE3f5 sources (the reference), test decks, ngspice goldens |
site/ |
The website and examples gallery |
Dune exists because of the work of others, and is derived from it:
- SPICE3f5 — © 1985–1991 The Regents of the University of
California; written at the EECS Department of UC Berkeley by Thomas
L. Quarles and many others, whose names are in the headers of the
original files. The netlist language, the device models, the
numerical methods and the analyses of Dune are translated from it.
The unmodified sources are in
corpus/spice3f5. - ngspice — the maintained successor of SPICE3f5, by the ngspice
team and contributors (Modified BSD licence). Dune is validated
against ngspice-47, and the following are derived from its sources:
BSIM3v3.3 (
spicelib/devices/bsim3) and BSIM4 4.8.3 (spicelib/devices/bsim4), the VDMOS power MOSFET (devices/vdmos, Holger Vogt and Dietmar Warning), the VBIC bipolar transistor (devices/vbic; model by Colin McAndrew, implementation by Dietmar Warning), the KSPICE lossy and coupled transmission lines (devices/txl,devices/cpl, Charles Hough), the diode extensions andLEVEL=3(devices/dio, as revised by Paolo Nenzi, Dietmar Warning and Arpad Buermen), the Fourier analysis.four(fourier.c, Wayne A. Christopher), the rewriting of behavioural R, C and L into B sources (inpcom.c), the S-parameter analysis.sp(span.c, Alessio Cacciatori), the operating-point fallback chain (cktop.c, with Alan Gillespie's gmin and source stepping, andoptran.c, Holger Vogt), BSIM1/BSIM2 noise (b1noi.c,b2noi.c, Paolo Nenzi), theTRNOISE/TRRANDOMsources,.measure(com_measure2.c), the switches as ngspice runs them, and every SPICE3f5 routine where Dune follows ngspice's revision (each one is named in the module comments and incorpus/KNOWN_DIFFS.md). - BSIM3v3.3.0 — © 2004 The Regents of the University of California; developed by the UC Berkeley BSIM Research Group (JianHui Huang, Min-Chie Jeng, Mansun Chan, Gary W. Ng, Weidong Liu, Xuemei Xi).
- BSIM4 4.8.3 — © 2025 University of California; developed by the UC Berkeley BSIM Research Group (project directors Sayeef Salahuddin and Chenming Hu; developers listed at https://www.bsim.berkeley.edu/models/bsim4/auth_bsim4/), under the Educational Community License 2.0. Only version 4.8.3 is used.
The parameter language of the netlist (.param expressions, subcircuit
parameters, .func, .if, temper, the random functions) was written
from the ngspice manual and from the observed behaviour of ngspice-47,
not from its implementation.
NOTICE lists the upstream files module by module and reproduces their copyright and licence notices; it ships with every package.
Dune is an independent project: it is not affiliated with, sponsored by or endorsed by the University of California, Berkeley, the UC Berkeley BSIM Research Group or the ngspice project. The names "SPICE", "SPICE3" and "ngspice" are used only descriptively, to identify the programs whose netlist language and behaviour Dune implements. The translation was done with the assistance of AI coding tools.
BSD-3-Clause — © 2026 André Leite; portions derived from SPICE3f5, © 1985–1991 The Regents of the University of California, and from ngspice, © 1985–2018 The Regents of the University of California and others. See LICENSE and NOTICE.
The BSIM4 model (crates/dune-core/src/bsim4, compiled with the default
bsim feature) is a translation of BSIM4 4.8.3, © 2025 University of
California, under the Educational Community License 2.0; the packages
that include it are BSD-3-Clause AND ECL-2.0. A build without the
bsim feature is plain BSD-3-Clause.
The BSIM3 model, behind the same feature, also carries the BSIM terms of use of the UC Berkeley BSIM Research Group, reproduced in NOTICE.
The third-party Rust crates the packages link are all under permissive
licences; none is copyleft. deny.toml is the accepted
list, and CI checks it on every push. The dune command and the Python
and R packages also embed the KaTeX fonts, which are under the SIL Open
Font License; see NOTICE.
Contributions are welcome. See CONTRIBUTING.md.