Analog circuit modeling library for MOSFETs and linear building blocks. Supports analytical equations, frequency response, parameter sweeps, and optimization.
uv venv
uv pip install -e .For development:
uv pip install -e ".[dev]"
pre-commit installfrom circuitsmith.blocks import CommonSourceAmplifier
from circuitsmith.plotting import plot_bode
cs = CommonSourceAmplifier(
name="CS_Amp",
gm=0.001,
ro=100000,
rd=10000,
cl=1e-12,
cgd=0.1e-12
)
metrics = cs.evaluate()
print(f"Gain: {metrics.dc_gain_db:.2f} dB")
print(f"Bandwidth: {metrics.bandwidth_hz:.2e} Hz")
plot_bode(cs, save_path="output/bode.png")Run the demo:
circuitsmith demoCommonSourceAmplifier,SourceFollower,CommonGateDifferentialPair,CurrentMirrorSimpleTwoStageOpAmpRCLowPass,RLCLowPass,RLCBandPass
Ten runnable examples in examples/:
Frequency Analysis:
python examples/common_source_bode.py
python examples/cascaded_amplifier.py
python examples/two_stage_opamp_stability.py
python examples/rlc_filter_gallery.pyParameter Studies:
python examples/source_follower_sweep.py
python examples/diffpair_cmrr.py
python examples/monte_carlo_gain.pyTransient Analysis:
python examples/transient_step_response.py
python examples/transient_amplifier_sine.py
python examples/transient_filter_noise.pyAll plots save to output/.
circuitsmith demo
circuitsmith analyze common_source --gm 0.001 --ro 100000
circuitsmith sweep --param gm --values "0.001,0.002,0.004"Frequency Response:
from circuitsmith.analysis import FrequencyResponse
fr = FrequencyResponse.from_block(block, fmin=1e3, fmax=1e9)Parameter Sweeps:
from circuitsmith.analysis import sweep_parameter
result = sweep_parameter(block, "gm", [0.001, 0.002, 0.004])Monte Carlo:
from circuitsmith.analysis import monte_carlo
result = monte_carlo(block, {"gm": (0.001, 0.0001)}, n_samples=200)Transient Analysis:
from circuitsmith.analysis import transient_step, transient_sine, transient_noisy_signal
step_resp = transient_step(block, step_amplitude=0.1, duration=1e-6)
sine_resp = transient_sine(block, frequency=1e6, amplitude=0.1)
noisy_resp = transient_noisy_signal(block, signal_frequency=1e6, noise_amplitude=0.2)CircuitSmith supports AI-powered circuit design using OpenAI GPT-4o-mini.
Install:
uv pip install -e ".[llm]"Setup:
Create a .env file in the project root:
OPENAI_API_KEY=your-api-key-here
Usage:
from circuitsmith.llm import OpenAICircuitDesignAgent
agent = OpenAICircuitDesignAgent()
spec = "Design a two-stage opamp with 60dB gain"
design = agent.design_from_spec(spec)
valid, errors = agent.validate_design(design)
if valid:
print(f"Generated {len(design.blocks)} blocks")
design.to_json() # Export as JSONRun the example:
python examples/llm_design_generation.pyCircuitSmith uses simplified first-order models suitable for:
- Design exploration
- Understanding tradeoffs
- Education
Not modeled:
- Short-channel effects
- Layout parasitics
- Nonlinear distortion
- Temperature and process corners beyond Monte Carlo
Always validate with SPICE using accurate models before tapeout.
pytest tests/ -v
ruff check .
mypy src/circuitsmithMIT