This PR introduces a major overhaul of xrd_simulator to support powder diffraction simulation with GPU-accelerated rendering via PyTorch. The refactor enables realistic simulation of polycrystalline samples across all grain size regimes—from nanocrystals to large single crystals—with physically accurate peak broadening models.
- Complete migration from NumPy to PyTorch for all core computations
- Automatic CPU/GPU device selection via new
xrd_simulator.cudamodule - Memory-efficient batch processing for millions of grains
New rendering system with three physically-motivated methods:
| Method | Grain Size | Description |
|---|---|---|
nano |
< 0.1³ µm³ | Airy disk patterns with Scherrer broadening for nanocrystals |
micro |
0.1³ - pixel³ µm³ | Fast Gaussian profiles for powder patterns |
macro |
> pixel³ µm³ | 3D volume projection showing crystal morphology |
auto |
All sizes | Automatic method selection based on grain volume |
- Lorentz factor: Proper intensity corrections for diffraction geometry
- Polarization factor: X-ray polarization effects
- Structure factors: Crystallographic intensity modulation
- New
scattering_factors.pymodule with Scherrer formula implementation
- Batch rendering of 1M+ grains in seconds on GPU
- Intelligent memory management with automatic batching
- Removed NumPy dependency from hot paths
ScatteringUnitclass removed (functionality merged intoPolycrystalandDetector)- Rendering method names changed:
centroid→micro,profiles→nano,volumes→macro - Minimum Python version: 3.10
- PyTorch 2.5+ required
- ✅ 82/82 tests passing
- New end-to-end tests for powder diffraction with pyFAI peak finding
- New crystallite size broadening validation tests
- CUDA device configuration tests
- 100 files modified (+10,139 / -5,764 lines)
- Core modules refactored:
detector.py,polycrystal.py,motion.py,mesh.py,laue.py - New modules:
cuda.py,scattering_factors.py - Documentation rebuilt with Sphinx
torch>=2.5.0
numpy>=1.24.0
scipy>=1.11.0
pandas>=2.0.0
- Vectorization merge and initial refactoring
- PyTorch backend implementation through
_diffract - Torch/NumPy equivalence achieved for full simulation pipeline
- Multi-frame rendering support
- Powder diffraction mode with PSF convolution
- Lorentz, polarization, and structure factor corrections
- Memory-efficient batch processing
- Removed NumPy from computations
- Volume projection for macro grains
- Gaussian interpolation for micro grains
- Airy disk patterns for nano grains
- Auto mode with grain-size-based method selection
- Vectorized
RigidBodyMotionfor batch operations - End-to-end powder diffraction tests
- CUDA device configuration module
- Scherrer formula implementation
- Documentation and docstring updates
- CI/CD workflow updates for Python 3.13
- Repository cleanup
- Sphinx documentation rebuild
Ready for review and merge into main.