analogsim / analoglib
An open-source Python library for simulating Analog In-Memory Computing (IMC) and neural network inference on resistive crossbar architectures (ReRAM, PCM, Flash).
⚡ Key Features
- 🧠 PyTorch & NumPy Importers: Convert PyTorch
nn.Moduleor NumPy weight matrices directly into physical crossbar arrays. - 📐 Analog Intermediate Representation (AIR): Decouples high-level model definitions from low-level physical crossbar backends.
- 🧱 Tiled Crossbar Architecture (
TiledCrossbar): Automatically partitions arbitrary matrix sizes across a 2D grid of physical crossbar tiles with global $w_{\text{max}}$ scale preservation. - ⚡ Physical Hardware Non-Idealities (
analoglib.effects):- Parasitic IR Drop: Wordline/bitline wire resistance simulation ($r_{\text{wire}}$ per cell).
- Thermal Scaling: Arrhenius temperature-dependent conductance shift $G(T) = G_0 \exp(-E_a / k_B T)$.
- Retention Drift: Power-law temporal decay $G(t) = G_0 (t/t_0)^{-\nu}$.
- 📊 Hardware Profiler & Analytics (
AnalogProfiler): Estimates array power (W), read energy (J), ADC/DAC energy overhead, area ($\mu\text{m}^2$), latency (s), and throughput efficiency ($\text{TOPS/W}$). - 🔌 Circuit Exporter: Export loaded models into ngspice and LTspice netlists for circuit simulation.
- 📦 Encrypted
.analogBinary Format: Secure serialization using AES-256-GCM + MsgPack. - 🛠️ CLI Utility: Command-line tool
analog/analogsimfor info, simulation, profiling, and SPICE export.
📦 Installation
Install from PyPI
pip install analogsim
Install with Optional Dependencies (PyTorch, Matplotlib)
pip install "analogsim[all]"
Install from Source
git clone https://github.com/Aditya-Raj-Parashar/analoglib.git
cd analoglib
pip install -e .
🚀 Quick Start
1. PyTorch to Analog Simulation Pipeline
import torch.nn as nn
import analogsim as al
import numpy as np
# 1. Define your PyTorch model
torch_model = nn.Sequential(
nn.Linear(784, 128),
nn.ReLU(),
nn.Linear(128, 10),
)
# 2. Convert PyTorch model to AnalogModel via AIR
model = al.AnalogModel.from_torch(torch_model)
# 3. Compile targeting physical ReRAM crossbars + ADC/DAC + Hardware Effects
model.compile(
device=al.ReRAM(g_min=1e-6, g_max=100e-6, num_states=256, read_noise_sigma=0.01),
adc_bits=8,
dac_bits=8,
r_wire=1.0, # Parasitic IR drop wire resistance
E_a=0.1, # Thermal Arrhenius scaling
nu=0.05, # Retention drift exponent
)
# 4. Simulate inference in hardware mode
x_input = np.random.uniform(0, 1, 784)
result = model.simulate(x_input, mode="hardware")
# 5. Generate Hardware Performance & Accuracy Report
result.report()
2. Direct Crossbar Operations
import analogsim as al
import numpy as np
# Define physical ReRAM device
reram = al.ReRAM(g_min=1e-6, g_max=100e-6, num_states=256)
# Create a differential crossbar (128 rows x 64 columns)
xbar = al.Crossbar(128, 64, device=reram, differential=True)
# Load weights (mapped automatically to G+ and G- conductances)
W = np.random.uniform(-1.0, 1.0, (128, 64))
xbar.load_weights(W, quantize=True)
# Perform VMM
V_in = np.random.uniform(0.0, 1.0, 128)
I_out = xbar.vmm(V_in, mode=al.SimulationMode.HARDWARE)
🛠️ CLI Usage
analogsim comes with a command-line tool analog (or analogsim):
# View model metadata & layer details
analog info model.analog
# Run hardware simulation
analog simulate model.analog --mode hardware
# Profile power, latency, area, and TOPS/W
analog profile model.analog
# Export SPICE netlist for ngspice
analog export-spice model.analog --out circuit.cir --dialect ngspice
📜 Publishing to PyPI
To build and publish analogsim to PyPI:
# 1. Install build tools
pip install build twine
# 2. Build source distribution and wheel
python -m build
# 3. Upload to PyPI
python -m twine upload dist/*
📄 License
MIT License © 2026 Aditya Raj Parashar
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
analogsim-0.1.0.tar.gz
(62.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
analogsim-0.1.0-py3-none-any.whl
(62.7 kB
view details)
File details
Details for the file analogsim-0.1.0.tar.gz.
File metadata
- Download URL: analogsim-0.1.0.tar.gz
- Upload date:
- Size: 62.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f244c2dc5dcebd0e3124e89d30071b9805d0c77c58c2c1669f912ab10d803de4
|
|
| MD5 |
c9003daa09aade4f55fe68a4576b7f3b
|
|
| BLAKE2b-256 |
d58481314bccd07d45c70bdb7af085c8bbda35793f92d113a734c7bfffe3bdd8
|
File details
Details for the file analogsim-0.1.0-py3-none-any.whl.
File metadata
- Download URL: analogsim-0.1.0-py3-none-any.whl
- Upload date:
- Size: 62.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
075bec2675b82a8c1ee4a9bb197241744e4c07e2c04aef3e8de8d9b1c84d9416
|
|
| MD5 |
faad7b11373ea001336c97df0480a114
|
|
| BLAKE2b-256 |
0ee6b5a1b89d8ddfa727cf9a3cf7dd7de0a6235e9802b21bbd7eff1b4c4ea585
|