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
Metadata
Release files for analogsim 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| analogsim-0.1.0.tar.gz | 62.9 kB | Without provenance | Details for analogsim-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| analogsim-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for analogsim-0.1.0-py3-none-any.whl |
Total release size: 125.6 kB
Release files / analogsim-0.1.0.tar.gz
| Download URL | analogsim-0.1.0.tar.gz |
|---|---|
| Size | 62.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f244c2dc5dcebd0e3124e89d30071b9805d0c77c58c2c1669f912ab10d803de4
|
|
BLAKE2b-256 checksum How to use checksums |
d58481314bccd07d45c70bdb7af085c8bbda35793f92d113a734c7bfffe3bdd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / analogsim-0.1.0-py3-none-any.whl
| Download URL | analogsim-0.1.0-py3-none-any.whl |
|---|---|
| Size | 62.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
075bec2675b82a8c1ee4a9bb197241744e4c07e2c04aef3e8de8d9b1c84d9416
|
|
BLAKE2b-256 checksum How to use checksums |
0ee6b5a1b89d8ddfa727cf9a3cf7dd7de0a6235e9802b21bbd7eff1b4c4ea585
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for analogsim 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.