Skip to main content

A simulation library for basic semiconductor devices aimed at undergraduates.

Project description

SemiconductorSim

SemiconductorSim is an open-source Python library designed to simulate fundamental semiconductor devices, making complex semiconductor physics accessible to undergraduate students. Accompanied by interactive tutorials and comprehensive examples, this library serves as a valuable educational tool for students, educators, and enthusiasts in the fields of electronics and semiconductor engineering.

CI CodeQL

Python License Coverage Docs

🧭 Table of Contents

  • Installation
  • Features
  • Supported Devices
  • Quickstart
  • Examples & Docs
  • Units & Conventions
  • Interactive Notebooks
  • Development
  • Troubleshooting
  • Contributing
  • License
  • Releases

📚 Features

  • PN Junction Diode Simulation: IV, SRH recombination, temperature dependence
  • LED Simulation: IV with emission, efficiency model, temperature effects
  • Solar Cell Simulation: IV under illumination, short/open-circuit conditions
  • Tunnel, Varactor, Zener, MOS Capacitor: teaching-focused models and plots
  • Interactive Visualizations: Jupyter widgets and Plotly/Matplotlib support
  • Documentation: API references, tutorials, and example scripts

🧪 Supported Devices

  • PN Junction Diode: Ideal diode with SRH recombination and temperature effects.
  • LED: Diode IV with emission intensity; simple efficiency model.
  • Solar Cell: IV under illumination; short/open-circuit conditions.
  • Tunnel Diode: Simplified IV with correct reverse-bias behavior for teaching.
  • Varactor Diode: Junction capacitance vs. reverse bias; IV characteristic.
  • Zener Diode: Breakdown behavior with optional ML-predicted Zener voltage.
  • MOS Capacitor: C–V and I–V characteristics with depletion width model.

🔧 Installation

Install from PyPI (recommended):

pip install semiconductor-sim

From source (editable):

git clone https://github.com/kennedym-ds/semiconductor_sim.git
cd semiconductor_sim
python -m venv .venv
. .venv/Scripts/activate
pip install -U pip
pip install -r requirements.txt
pip install -e .

🚀 Quickstart

Minimal PN junction example (no plotting required):

import numpy as np
from semiconductor_sim.devices import PNJunctionDiode

diode = PNJunctionDiode(doping_p=1e17, doping_n=1e17, temperature=300)
V = np.array([0.0, 0.2, 0.4])
I, R = diode.iv_characteristic(V, n_conc=1e16, p_conc=1e16)
print("Current:", I)
print("Recombination (SRH):", R)

LED quick preview (two-value return when concentrations omitted):

import numpy as np
from semiconductor_sim.devices import LED

led = LED(doping_p=1e17, doping_n=1e17, temperature=300)
V = np.linspace(0, 2, 5)
current, emission = led.iv_characteristic(V)

📓 Examples & Docs

  • Examples: see the examples/ folder for scripts and Jupyter notebooks (interactive versions use ipywidgets/plotly).
  • API docs: browse module docstrings and examples until hosted docs are added.

📐 Units & Conventions

  • Length: cm; Area: cm²; Volume: cm³; Charge: C; Capacitance: F.
  • Doping and carrier concentrations: cm⁻³.
  • Temperature: K (default DEFAULT_T = 300 K).
  • Constants available via semiconductor_sim.utils.constants: q, k_B, epsilon_0, DEFAULT_T.
  • Return shapes: device iv_characteristic methods return arrays aligned to the input voltage_array. Where scalar recombination is computed, it is broadcast to match the voltage vector.

💡 Interactive Notebooks

  • Explore interactive notebooks in examples/ with Jupyter and ipywidgets.
  • Launch Jupyter:
python -m pip install jupyter ipywidgets
jupyter notebook examples

If running on a headless server/CI, plotting uses Matplotlib’s non-interactive backend automatically inside plotting helpers.

🖼️ Plotting Helper (Headless-Safe)

To keep plots consistent and CI-friendly, device plotting functions call lightweight helpers:

  • semiconductor_sim.utils.plotting.use_headless_backend("Agg"): switch to a non-interactive backend before any figures are created.
  • semiconductor_sim.utils.plotting.apply_basic_style(): apply minimal, consistent rcParams (grid, sizes, legend).

When writing new scripts that use Matplotlib directly, you can opt-in to the same behavior:

from semiconductor_sim.utils.plotting import (
  use_headless_backend,
  apply_basic_style,
)
use_headless_backend("Agg")
apply_basic_style()

import matplotlib.pyplot as plt
# ... your plotting code ...

Notes:

  • Prefer relying on device .plot_* helpers where available.
  • Avoid calling plt.switch_backend at runtime; set backend via the helper before any figures are created.

🧑‍💻 Development

Set up a virtual environment and install dev tools:

python -m venv .venv
. .venv/Scripts/activate
pip install -U pip
pip install -r requirements.txt
pip install -e .
pip install ruff mypy pytest pre-commit
pre-commit install

Run checks:

ruff check .
ruff format --check .
mypy .
pytest -q

CI runs Ruff, Mypy, and tests across Python 3.10–3.13 on Linux/Windows/macOS with coverage thresholds. It includes dependency review, pip-audit security checks, and CodeQL scanning. Dependabot keeps GitHub Actions and pip dependencies updated. Publishing to PyPI is automated on tags v*.*.*. See CHANGELOG.md for notable changes.

🩺 Troubleshooting

  • "FigureCanvasAgg is non-interactive" warnings: safe to ignore in headless runs.
  • Missing ML model for Zener voltage: library falls back to the configured default and prints a notice. You can train your own model and place the zener_voltage_rf_model.pkl under semiconductor_sim/models/ if desired.
  • On Windows, ensure you activate the venv before running commands:
. .\.venv\Scripts\Activate.ps1

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines. Typical flow:

git checkout -b feature/my-improvement
ruff check . && mypy . && pytest -q

Open a PR; CI runs lint, types, tests, CodeQL, and dependency review.

✅ Quality Checks

Before opening a PR, run the core checks locally:

ruff check .
ruff format --check .
mypy .
pytest -q

See the detailed checklist in the PR template:

  • .github/pull_request_template.md

📄 License

This project is licensed under the MIT License — see LICENSE.

🏷️ Releases

  • Versioning: semantic (MAJOR.MINOR.PATCH).
  • Publishing: push a tag like v0.1.1 to trigger the publish workflow.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semiconductor_sim-1.0.5.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semiconductor_sim-1.0.5-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

Details for the file semiconductor_sim-1.0.5.tar.gz.

File metadata

  • Download URL: semiconductor_sim-1.0.5.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for semiconductor_sim-1.0.5.tar.gz
Algorithm Hash digest
SHA256 4cea4d832c604d9f8b5dabe6e6e0798312edf6f58239dd57058f142118069af9
MD5 4e673135cfc6cec4b7211b059f67d37b
BLAKE2b-256 148add3a0e92d5187596fe05a496e0aa267ee96bae9bea6c756a28a337dfc280

See more details on using hashes here.

Provenance

The following attestation bundles were made for semiconductor_sim-1.0.5.tar.gz:

Publisher: publish.yml on kennedym-ds/semiconductor_sim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file semiconductor_sim-1.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for semiconductor_sim-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7d1ebadb99d0339cca5ca99805089afd0a7d42902b835975608e558f5eba731d
MD5 20c15646f20bee301407cab27290d63e
BLAKE2b-256 ba0f654bdced5d0eefcce14ecb9c3678ecf7d241c35a867197b2f7c8b4983b4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for semiconductor_sim-1.0.5-py3-none-any.whl:

Publisher: publish.yml on kennedym-ds/semiconductor_sim

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page