Python library providing solvers and tools for the Semiconductor Bloch Equations (SBE).
- Added an optional PyTorch/CUDA SBE solver for faster time propagation on GPU.
- Implemented a Marchenko–Pastur / randomized‑SVD low‑rank reduction for the Coulomb operator (mp_coulomb_reduction).
- New HHG‑oriented hybrid drivers and visualization tools (absorption_gaas_hybrid*, view_HHG_spectra, view_spectra).
- Restored exchange self‑energy in hybrid drivers and improved Fortran f2py modules with OpenMP and time‑resolved export. See CHANGELOG.md (or PR description) for full details, build instructions and compatibility notes.
pySBE implements numerical tools to simulate optical responses of semiconductors via the Semiconductor Bloch Equations. The project provides:
- Reference Fortran f2py backends (optimized with OpenMP),
- A new PyTorch/CUDA solver for GPU acceleration (optional),
- Low‑rank Coulomb operator reduction (MP / randomized SVD),
- HHG‑focused drivers and a set of visualization/analysis utilities.
Below is an example absorption spectrum for bulk GaAs at T = 10 K computed with original pySBE library:
Below is an example of a Fortran–CUDA code comparison, x40 times faster than parallelized Fortran, and about 120 times faster than the single-task version:
- Time‑propagation solvers (Fortran RK4 reference, PyTorch/CUDA alternative)
- Coulomb operator handling and low‑rank approximation for large k‑grids
- Hybrid drivers that can run Fortran, CUDA, or compare both backends
- Export of time‑resolved snapshots and HHG postprocessing
- Utility scripts for plotting, energy balance, and diagnostics
The file absorption_gaas_hybrid.py represents the main effort to parallelize and modernize the original pySBE project while preserving compatibility with the reference implementation.
The remaining hybrid, CUDA, HHG, and Marchenko–Pastur (MP) related scripts are currently experimental. They are intended for research, testing, benchmarking, and evaluation of new numerical methods. Their interfaces, algorithms, and output formats may change as development continues and they should not yet be considered part of the stable pySBE workflow.
A smart launcher script is included to simplify installation and execution:
./run_everywhere_smart.shThe launcher automatically:
- checks the current Python environment;
- verifies required Python packages;
- detects PyTorch and NVIDIA CUDA support;
- checks whether the compiled Fortran modules are already available;
- asks before creating a new virtual environment;
- recompiles the Fortran backend only if necessary;
- starts the HHG simulation.
On systems where pySBE is already configured, the launcher uses the existing environment and avoids unnecessary package installation or virtual environment recreation.
-
Create a virtual environment and install Python dependencies:
- python -m venv .venv && source .venv/bin/activate
- pip install -r requirements.txt
- (Optional) Install PyTorch for your platform:
- pip install torch # choose the correct wheel for your CUDA/CPU
-
(Optional) Build Fortran f2py modules if you want the Fortran backend:
- cd src
- make compile
- This compiles the f2py extensions with OpenMP flags and moves the .so files into
sbe/.
-
Quick PyTorch smoke test (fast):
- python -c "from sbe_solver_gpu import example_minimal_run; example_minimal_run()"
- This runs a minimal example and prints device and spectrum shape.
-
Hybrid / comparison run:
- python absorption_gaas_hybrid.py
- Follow the interactive options to run Fortran, CUDA, or both and export results.
-
Visualize results:
- python view_HHG_spectra.py
- python view_spectra.py
- The PyTorch/CUDA solver is optional but requires
torchto be installed. - Fortran builds use OpenMP (gfortran + libgomp). If your environment lacks OpenMP support, skip Fortran compilation or adjust
src/makefile. - Low‑rank MP caches include grid size and parameter metadata; remove old caches if you change grid or reduction settings.
- For numerical comparisons, run small test grids Fortran vs CUDA and inspect outputs with the provided viewers.
This project is based on the original pySBE project developed by Mykhailo Klymenko and contributors.
Original repository: https://github.com/freude/pySBE
This repository significantly extends the original implementation with hybrid Fortran/CUDA execution, GPU-accelerated Semiconductor Bloch Equation solvers, High Harmonic Generation (HHG) simulation, Marchenko–Pastur low-rank Coulomb reduction, time-resolved spectrum export, visualization tools, and performance benchmarking.
- Koch S.W., Chow W.W., Semiconductor-Laser Fundamentals: Physics of the Gain Materials, Springer (1999)
- Haug H., Koch S.W., Quantum Theory of the Optical and Electronic Properties of Semiconductors, World Scientific (2009)