A modern 2D ray-optics simulation and component editor built with PyQt6
Optiverse is a powerful, interactive tool for designing and simulating optical systems. Create complex setups with mirrors, lenses, beamsplitters, and custom components, then visualize ray propagation in real-time with hardware-accelerated rendering.
⚠️ Alpha Version: This software is currently in alpha. Bugs are expected and features may change. Please report any issues you encounter.
- Interactive Ray Tracing: Real-time visualization of light propagation through optical systems
- Component Editor: Create custom optical components with multiple interfaces (lenses, mirrors, beamsplitters)
- Hardware-Accelerated Rendering: OpenGL-powered ray display (100x+ faster than software rendering)
- Numba JIT Optimization: 4-8x raytracing speedup on all Python versions (3.9-3.12+)
- Collaboration Mode: Real-time multi-user editing via WebSocket server
- Zemax Import: Import optical designs from Zemax (.zmx) files
- Polarization Support: Jones vector formalism for polarization-dependent optics
- Platform-Native UI: macOS trackpad gestures, native menu bars, dark mode support
# Clone the repository
git clone https://github.com/QPG-MIT/optiverse.git
cd optiverse
# Create virtual environment (recommended)
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install
pip install -e .
# Run
optiverse# 1. Clone and setup
git clone https://github.com/QPG-MIT/optiverse.git
cd optiverse
# 2. Create conda environment
conda create -n optiverse python=3.11
conda activate optiverse
# 3. Install dependencies
pip install -e .
# 4. Create macOS app bundle (optional, for native menu bar)
python tools/setup_macos_app.py
# 5. Launch
open Optiverse.app # Or: optiverse# 1. Clone the repository
git clone https://github.com/QPG-MIT/optiverse.git
cd optiverse
# 2. Create and activate virtual environment
python -m venv .venv
# Windows:
.venv\Scripts\activate
# Linux:
source .venv/bin/activate
# 3. Install
pip install -e .
# 4. Launch
optiverse
# Or directly:
python -m optiverse.app.main# Install with development tools (testing, linting, type checking)
pip install -e .[dev]Optiverse supports Python 3.9 through 3.12+ with full Numba JIT acceleration.
| Python Version | Numba JIT | Speedup | Status |
|---|---|---|---|
| 3.9 | ✅ Yes | 4-8x | ✅ Fully supported |
| 3.10 | ✅ Yes | 4-8x | ✅ Fully supported |
| 3.11 | ✅ Yes | 4-8x | ✅ Fully supported |
| 3.12+ | ✅ Yes | 4-8x | ✅ Fully supported (Numba 0.60+) |
Note: Previous versions of this documentation incorrectly stated that Python 3.12+ was not supported by Numba. As of Numba 0.60+, Python 3.12 and newer versions are fully supported with JIT compilation.
# Launch via app bundle (shows as "Optiverse" in menu bar)
open Optiverse.app
# Or via command line
optiverse# Launch via entry point
optiverse
# Or directly
python -m optiverse.app.main- Add Components: Drag optical elements from the library or use the toolbar
- Configure Properties: Double-click elements to adjust parameters
- Add Light Sources: Place sources and configure wavelength, polarization
- Trace Rays: Real-time visualization updates automatically
- Save/Load: Save your optical systems as JSON files
| Action | Windows/Linux | macOS |
|---|---|---|
| File | ||
| Open Assembly | Ctrl+O |
⌘O |
| Save | Ctrl+S |
⌘S |
| Save As | Ctrl+Shift+S |
⌘⇧S |
| Edit | ||
| Undo | Ctrl+Z |
⌘Z |
| Redo | Ctrl+Y |
⌘Y |
| Copy | Ctrl+C |
⌘C |
| Paste | Ctrl+V |
⌘V |
| Delete | Delete / Backspace |
Delete / ⌫ |
| Preferences | Ctrl+, |
⌘, |
| View | ||
| Zoom In | Ctrl++ |
⌘+ |
| Zoom Out | Ctrl+- |
⌘- |
| Fit Scene | Ctrl+0 |
⌘0 |
| Recenter View | Ctrl+Shift+0 |
⌘⇧0 |
| Tools | ||
| Retrace Rays | Space |
Space |
| Component Editor | Ctrl+E |
⌘E |
| Show Log Window | Ctrl+L |
⌘L |
| Collaboration | ||
| Connect/Host Session | Ctrl+Shift+C |
⌘⇧C |
| General | ||
| Cancel Current Tool | Esc |
Esc |
Create custom optical components:
- File → Component Editor (or use existing components from library)
- Load an image (PNG/SVG) or import from Zemax (.zmx)
- Define optical interfaces (lenses, mirrors, beamsplitters)
- Set refractive indices and geometric properties
- Save to library for reuse in main canvas
Optiverse uses OpenGL for ray rendering, providing 100x+ speedup compared to software rendering:
- 4x MSAA anti-aliasing for smooth visuals
- 60+ FPS even with thousands of rays
- Optimized for Retina/HiDPI displays
The raytracing engine uses Numba JIT compilation and multi-threading for 4-8x speedup:
- Numba JIT: Compiles hot paths to native machine code (2-3x faster)
- Multi-threading: Distributes rays across CPU cores (2-4x additional speedup)
- Auto-detection: Automatically enabled when Numba is available
- Cross-platform: Works on Windows, macOS, and Linux
Performance (typical 4-core CPU, Python 3.9-3.12):
100 rays, 20 elements: 100ms → 20-30ms (3-5x speedup)
500 rays, 20 elements: 500ms → 100-150ms (3-5x speedup)
For technical details, see docs/PARALLEL_RAYTRACING.md.
Native Trackpad Gestures:
- 🖱️ Two-finger scroll → Pan canvas
- 🤏 Pinch gesture → Zoom in/out
- ⌘ Cmd + scroll → Alternative zoom
App Bundle:
# Create native macOS app (optional)
python tools/setup_macos_app.py
open Optiverse.appPerformance Optimizations:
- Retina display rendering optimizations (60-80% faster)
- Smart viewport caching reduces lag during interactions
- Native menu bar integration via pyobjc
See docs/MAC_TRACKPAD_OPTIMIZATION.md for details.
Real-time multi-user editing via WebSocket:
Start collaboration server:
python tools/collaboration_server.py --host 0.0.0.0 --port 8765Connect from Optiverse:
- Tools → Collaboration → Connect
- Enter server address and session ID
- Changes sync in real-time across all connected users
See docs/COLLABORATION.md for setup and architecture details.
# All tests
pytest
# Specific module
pytest tests/raytracing/ -v
# With coverage
pytest --cov=src --cov-report=html# Lint
ruff check .
# Auto-fix linting errors
ruff check --fix .
ruff format .
# Type checking
mypy src/
# Format (if needed)
black src/ tests/Note: When you create a pull request, Ruff linting errors are automatically fixed by GitHub Actions and committed back to your branch. You can also run ruff check --fix . locally before pushing.
# Compile Qt UI files
python tools/compile_ui.py
# Compile Qt resource files
python tools/compile_rc.py
# Create application icons
python scripts/create_icon.py# Test macOS optimizations
python tools/test_mac_optimizations.py
# Test collaboration
python tools/test_collaboration.py
# Manual save/load testing
python tools/test_save_load_manual.pyoptiverse/
├── src/optiverse/
│ ├── app/ # Application entry point
│ ├── core/ # Physics engine (Snell's law, Fresnel, etc.)
│ ├── raytracing/ # Polymorphic ray tracing engine
│ ├── objects/ # Qt graphics items (mirrors, lenses, sources)
│ ├── ui/ # User interface (main window, dialogs, widgets)
│ ├── services/ # Singletons (storage, settings, collaboration)
│ ├── data/ # Data structures
│ ├── platform/ # OS-specific utilities
│ └── integration/ # Legacy compatibility layer
├── tests/ # Test suite (pytest)
├── docs/ # Documentation
├── tools/ # Utility scripts
├── scripts/ # Build scripts
└── examples/ # Example assemblies and demos
- colaborative work is broken
- waveplates do not always rotate the polarization correctly
- QWP seems to adjust polarisation correctly but PBS does not reflect correctly in the pbs + qwp + backreflector mirror config.
- zemax black box model
- isolator
- distance measure tool across edges
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes with tests
- Run tests and linting (
pytest,ruff check .,mypy src/) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 (enforced by Ruff)
- Use type hints (checked by mypy)
- Write docstrings for public APIs
- Add tests for new features
MIT License - see pyproject.toml for details.
- Built with PyQt6 for cross-platform GUI
- Numba for JIT-compiled physics calculations
- OpenGL for hardware-accelerated rendering
- WebSockets for real-time collaboration
📚 View the Documentation Website
Comprehensive documentation is also available in the docs/ directory:
- Documentation Index - Complete guide to all available documentation
- Getting Started - Installation and setup guides
- User Guides - Component editor, Zemax import, collaboration
- Physics & Optics - Dichroic mirrors, polarization, waveplates
- Architecture & Development - Testing, error handling, system architecture
- Performance - Parallel raytracing, optimizations
- Issues: GitHub Issues
- Documentation: Complete Documentation Index
- Examples: Check
examples/for demo assemblies