Skip to content

Installation

Requirements

  • Python 3.11 or higher
  • pip (Python package manager)

Basic Installation

# Clone the repository
git clone https://github.com/Ayush12358/ElectoralSim.git
cd ElectoralSim

# Install in editable mode
pip install -e .

Optional Dependencies

Visualization

For charts, plots, and the Streamlit dashboard:

pip install -e ".[viz]"
This installs: matplotlib, plotly, streamlit

GPU Acceleration

For CUDA-accelerated simulations with large voter populations:

pip install -e ".[gpu]"
This installs: cupy

Note: GPU support requires NVIDIA CUDA toolkit. See CuPy installation guide.

Development

For running tests and contributing:

pip install -e ".[dev]"
This installs: pytest, pytest-cov

All Dependencies

pip install -e ".[dev,viz,gpu]"

Verification

Test your installation:

from electoral_sim import ElectionModel

model = ElectionModel(n_voters=1000, seed=42)
results = model.run_election()
print(f"Installation successful! Turnout: {results['turnout']:.1%}")

Troubleshooting

ImportError: No module named 'mesa'

pip install mesa>=3.0.0

Numba warnings

Numba JIT compilation warnings on first run are normal. They disappear after the first execution.

GPU not detected

Ensure CUDA is installed and cupy can access your GPU:

import cupy as cp
print(cp.cuda.runtime.getDeviceCount())  # Should return >= 1