Circuit-Synth SPICE Simulation Setup Guideο
This guide walks you through setting up SPICE simulation capabilities in circuit-synth using PySpice and ngspice.
Overviewο
Circuit-synth now supports SPICE simulation integration, allowing you to:
Convert circuit-synth designs to SPICE netlists
Run DC, AC, and transient analysis
Validate circuit behavior before PCB fabrication
Optimize component values through simulation
Prerequisitesο
1. Install ngspice (SPICE Simulator Engine)ο
macOS (using Homebrew):
brew install ngspice
Ubuntu/Debian:
sudo apt-get update
sudo apt-get install ngspice ngspice-doc
Windows:
Download ngspice from: http://ngspice.sourceforge.net/download.html
Install to
C:\ngspiceor similar locationAdd to PATH environment variable
2. Install Circuit-Synth (PySpice included by default)ο
Using pip:
pip install circuit-synth
Using uv:
uv add circuit-synth
Development installation:
uv pip install -e .
Verificationο
Test ngspice Installationο
# Check ngspice is installed
ngspice --version
# Find ngspice library location (macOS)
find /opt/homebrew /usr/local -name "*ngspice*" 2>/dev/null | grep lib
# Find ngspice library location (Linux)
find /usr -name "*ngspice*" 2>/dev/null | grep lib
Test PySpice Installationο
import PySpice
from PySpice.Unit import *
from PySpice.Spice.Netlist import Circuit
print(f"β
PySpice {PySpice.__version__} installed successfully")
Test Circuit-Synth Simulationο
from circuit_synth import Circuit, Component, Net, circuit
@circuit
def test_circuit():
r1 = Component("Device:R", ref="R", value="1k")
vin = Net('VIN')
gnd = Net('GND')
r1[1] += vin
r1[2] += gnd
# Create and test simulator
c = test_circuit()
try:
sim = c.simulator()
print("β
Circuit-synth simulation ready!")
except Exception as e:
print(f"β Simulation setup issue: {e}")
Platform-Specific Configurationο
macOS Configurationο
Circuit-synth automatically detects homebrew ngspice installations at:
/opt/homebrew/lib/libngspice.dylib(Apple Silicon)/usr/local/lib/libngspice.dylib(Intel Mac)
Linux Configurationο
If PySpice canβt find ngspice, set the library path manually:
from PySpice.Spice.NgSpice.Shared import NgSpiceShared
NgSpiceShared.LIBRARY_PATH = '/usr/lib/x86_64-linux-gnu/libngspice.so'
Windows Configurationο
Set the ngspice path in your code:
from PySpice.Spice.NgSpice.Shared import NgSpiceShared
NgSpiceShared.LIBRARY_PATH = r'C:\ngspice\bin_dll\ngspice.dll'
Troubleshootingο
Common Issuesο
βcannot load library βlibngspiceββ
Verify ngspice is installed:
which ngspiceCheck library exists:
ls /opt/homebrew/lib/libngspice*Set LIBRARY_PATH manually (see platform sections above)
βUnsupported Ngspice versionβ
This is a warning, not an error - simulation still works
PySpice may not recognize newer ngspice versions
βWarning: canβt find the initialization file spinitβ
This is normal - ngspice will use defaults
Optional: Create spinit file for custom ngspice configuration
Circuit conversion errors
Ensure all components have valid SPICE models
Check that nets are properly connected
Verify component values are SPICE-compatible (e.g., β10kβ not β10Kβ)
Getting Helpο
Check the examples:
examples/simulation/PySpice documentation: https://pyspice.fabrice-salvaire.fr/
ngspice manual: http://ngspice.sourceforge.net/docs.html
Circuit-synth issues: Create an issue on GitHub
Performance Notesο
First simulation: May take 2-3 seconds to initialize ngspice
Subsequent simulations: ~100ms for simple circuits
Complex circuits: Scale with number of nodes and components
Memory usage: Moderate (~10-50MB per simulation)
Security Considerationsο
PySpice loads native libraries - ensure clean ngspice installation
Simulation files are temporary and cleaned up automatically
Next Stepsο
Once setup is complete:
Try the basic examples in
examples/simulation/Use the
/simulateslash command with ClaudeExplore the
Circuit.simulator()APIBuild your own simulation workflows
Happy simulating! πβ‘