First Simulation
This walkthrough takes you from zero to a plotted frequency response using five tool calls. We will create an RC low-pass filter from a built-in template, simulate it, extract the output waveform, measure the bandwidth, and generate a plot.
-
Create a circuit from a template
The
create_from_templatetool generates a ready-to-simulate netlist from one of the built-in circuit templates.create_from_template("rc_lowpass")This writes an RC low-pass filter netlist to
/tmp/rc_lowpass.cirwith default component values (R=1k, C=100n) and an AC analysis directive.// Response{"netlist_path": "/tmp/rc_lowpass.cir","template": "rc_lowpass","parameters": { "R1": "1k", "C1": "100n" },"description": "RC low-pass filter, fc ~ 1.59 kHz"} -
Run the simulation
Pass the netlist to
simulate_netlist. LTspice runs via Wine in batch mode and produces a binary.rawfile with the results.simulate_netlist("/tmp/rc_lowpass.cir")// Response{"raw_file": "/tmp/rc_lowpass.raw","log_file": "/tmp/rc_lowpass.log","simulation_type": "AC Analysis","variables": ["frequency", "V(out)", "V(in)", "I(R1)"],"points": 801,"elapsed_seconds": 0.42} -
Extract the output waveform
Use
get_waveformto pull signal data out of the.rawfile. For AC analysis, this returns complex-valued data (magnitude and phase at each frequency point).get_waveform("/tmp/rc_lowpass.raw", ["V(out)"])// Response (truncated){"variables": {"frequency": [1.0, 1.26, 1.58, "...801 points..."],"V(out)": {"magnitude": [1.0, 0.9999, 0.9998, "..."],"phase_deg": [-0.036, -0.045, -0.057, "..."]}},"simulation_type": "AC Analysis","num_points": 801} -
Measure the bandwidth
The
measure_bandwidthtool finds the -3dB cutoff frequency from the AC analysis results.measure_bandwidth("/tmp/rc_lowpass.raw", "V(out)")// Response{"f_3dB_hz": 1591.5,"dc_gain_dB": 0.0,"gain_at_cutoff_dB": -3.01,"signal": "V(out)"}The measured cutoff of 1591.5 Hz matches the theoretical value of 1/(2 * pi * R * C) = 1/(2 * pi * 1000 * 100e-9) = 1592 Hz.
-
Plot the results
Generate an SVG plot of the frequency response with
plot_waveform.plot_waveform("/tmp/rc_lowpass.raw", "V(out)")// Response{"svg_path": "/tmp/rc_lowpass_V(out).svg","plot_type": "bode","signals": ["V(out)"],"format": "SVG"}The SVG contains a Bode plot with magnitude and phase traces --- suitable for embedding in reports or viewing in a browser.
What just happened
Section titled “What just happened”In five tool calls, you:
- Generated a complete SPICE netlist from a template
- Ran an AC analysis through LTspice (via Wine, in batch mode, with no GUI)
- Extracted complex-valued frequency-domain data from the binary
.rawfile - Measured the -3dB bandwidth automatically
- Produced a publication-ready Bode plot
All of this happened without writing a single line of SPICE, opening a GUI, or parsing binary files manually.
Next steps
Section titled “Next steps”Try modifying the circuit. You can change component values with the template parameters:
create_from_template("rc_lowpass", parameters={"R1": "10k", "C1": "10n"})This shifts the cutoff frequency to ~1.59 kHz (same frequency, different impedance) --- or pick entirely different values to explore the design space. See the tool reference for the full list of available operations.