Simulation

spicefault.simulation.backend

Simulator abstraction: configuration, result with an explicit status, and backends.

A backend runs one netlist and always returns a SimulationResult. A simulation that fails is a result with a status, not an exception, so that failures stay in the experimental record.

SimulationConfig dataclass

What to simulate and how.

analyses are ngspice analysis commands ("op", "ac dec 20 1 1e5", "tran 1u 10m"), run in order; the vectors in outputs are saved after each one, giving one plot per analysis. Any other command in the list, such as "alter @vin[acmag]=1", is run in its place and saves nothing. Leave analyses empty for a netlist that brings its own .control block writing to out.raw.

analysis_specs()

Commands, vectors to save after them and optional ngspice plot selectors.

plots()

The analysis command behind each expected plot, in order.

SimulationResult dataclass

Outcome of one simulation: a status, and one plot per analysis if it succeeded.

plot(which=0)

Plot by position, or the first whose name starts with which (case-insensitive).

NgspiceBackend

ngspice as an external process, one per simulation.

Simulator

The numerical engine of an experiment, chosen by name or given as a backend.

build_deck(netlist, config)

The netlist with a control block that runs the analyses of config.

spicefault.simulation.ngspice

Thin ngspice wrapper: run a deck in batch mode and read its binary raw file.

Plot dataclass

One analysis result. Vector names are lower case, e.g. v(out), frequency.

parse_raw(path)

Parse an ngspice binary raw file, which may hold several appended plots.

execute(netlist, timeout=120.0, spiceinit=None, raw_name=RAW_NAME)

Run a deck; return (plots, or None if no raw file was written; ngspice's messages).

Raises subprocess.TimeoutExpired after timeout seconds and SimulationError if ngspice is not installed.

run_deck(netlist, timeout=120.0, spiceinit=None, raw_name=RAW_NAME)

Run a deck whose control block writes to raw_name; return the plots in order.

spiceinit holds start-up commands (e.g. a compatibility mode for vendor models), which ngspice only accepts from an initialisation file. Failures raise SimulationError; NgspiceBackend reports them as a status instead.