Skip to content

CircuitSmith is a Python library for analog circuit design that unifies small signal theory, computational analysis, and AI driven circuit generation to rapidly model and optimize MOSFET amplifiers, filters, and op amps across frequency and time domains using analytical methods, parameter sweeps, and Monte Carlo analysis.

License

Notifications You must be signed in to change notification settings

krishkc5/CircuitSmith

Repository files navigation

CircuitSmith

Analog circuit modeling library for MOSFETs and linear building blocks. Supports analytical equations, frequency response, parameter sweeps, and optimization.

Installation

uv venv
uv pip install -e .

For development:

uv pip install -e ".[dev]"
pre-commit install

Quick Start

from 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 demo

Available Blocks

  • CommonSourceAmplifier, SourceFollower, CommonGate
  • DifferentialPair, CurrentMirror
  • SimpleTwoStageOpAmp
  • RCLowPass, RLCLowPass, RLCBandPass

Examples

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.py

Parameter Studies:

python examples/source_follower_sweep.py
python examples/diffpair_cmrr.py
python examples/monte_carlo_gain.py

Transient Analysis:

python examples/transient_step_response.py
python examples/transient_amplifier_sine.py
python examples/transient_filter_noise.py

All plots save to output/.

CLI

circuitsmith demo
circuitsmith analyze common_source --gm 0.001 --ro 100000
circuitsmith sweep --param gm --values "0.001,0.002,0.004"

Analysis

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)

LLM Integration

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 JSON

Run the example:

python examples/llm_design_generation.py

Theory Model Disclaimer

CircuitSmith 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.

Testing

pytest tests/ -v
ruff check .
mypy src/circuitsmith

License

MIT

About

CircuitSmith is a Python library for analog circuit design that unifies small signal theory, computational analysis, and AI driven circuit generation to rapidly model and optimize MOSFET amplifiers, filters, and op amps across frequency and time domains using analytical methods, parameter sweeps, and Monte Carlo analysis.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages