A graphical user interface for the Stanford S4 library, designed to accelerate photonic crystal slab (PCS) simulation workflows for researchers.
- ποΈ Visual Simulation Builder: Configure all simulation parameters through an intuitive form interface
- π Parameter Sweeps: Define multi-parameter sweeps with automatic parallelization across CPU cores
- π Interactive Visualization: Plotly-based charts for T/R/A spectra, phase plots, and 2D field maps
- π Dark/Light Mode: Eye-friendly interface for long simulation sessions
- πΎ Save/Load Configurations: Store and recall simulation setups as JSON files
- π Local Results Storage: Export results to JSON or CSV format
- β‘ Optimized Performance: Parallel wavelength sweeps for 5-8x speedup
-
Anaconda/Miniconda with S4 installed:
conda create -n S4 python=3.10 conda activate S4 conda install -c conda-forge s4
-
Node.js (v18+) for the frontend:
- Download from: https://nodejs.org/
- Double-click
start.bat - The browser will open automatically at http://localhost:5173
To stop: Double-click stop.bat or close the terminal windows.
For quick access, create a desktop shortcut:
- Double-click
create-desktop-shortcut.bat - A shortcut named "S4 Simulation GUI" will appear on your desktop
- Double-click the shortcut anytime to launch the application
-
Start the backend:
conda activate S4 cd backend pip install -r requirements.txt python -m uvicorn main:app --host 0.0.0.0 --port 8000 -
Start the frontend (in a new terminal):
cd frontend npm install npm run dev -
Open http://localhost:5173 in your browser
UTA-S4-GUI/
βββ backend/ # FastAPI Python backend
β βββ main.py # API entry point
β βββ simulation/ # S4 wrapper and sweep engine
β β βββ models.py # Pydantic data models
β β βββ s4_runner.py # S4 simulation wrapper
β β βββ sweep.py # Parallel sweep logic
β βββ utils/ # File I/O utilities
β βββ requirements.txt # Python dependencies
βββ frontend/ # React TypeScript frontend
β βββ src/
β β βββ components/ # UI components
β β βββ pages/ # Main pages
β β βββ lib/ # API client and utilities
β βββ package.json
βββ DATA/ # Simulation output files
βββ GRAPHS/ # Generated plots
βββ configs/ # Saved simulation configurations
βββ start.bat # Windows startup script
βββ stop.bat # Windows stop script
βββ create-desktop-shortcut.bat # Creates desktop icon
βββ create-shortcut.ps1 # PowerShell shortcut generator
- Configure parameters in the Geometry, Materials, Excitation, and Wavelength tabs
- Click Run Simulation
- View results in the interactive plots below
- Export to JSON or CSV
- Configure base parameters as above
- In the Parameter Sweep section, click Add Parameter
- Set the start, end, and step values for each sweep parameter
- Click Run Sweep - simulations run in parallel across all CPU cores
- View and compare results
- Enter a name and click the save icon to store your current configuration
- Click on saved configs in the list to reload them
The backend exposes a REST API with auto-generated documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
Key endpoints:
POST /simulate- Run single simulationPOST /sweep/start- Start parameter sweep (async)GET /sweep/status/{job_id}- Check sweep progressGET /jobs- List all jobs (persistent history)GET /jobs/{job_id}- Get job detailsGET /jobs/{job_id}/results- Get results from job historyPOST /configs/save- Save configurationGET /results- List saved results
Simulation jobs are automatically saved to a local SQLite database (DATA/jobs.db), providing:
- Persistent History: View all past simulation jobs even after restarting the application
- Resume Capability: Jobs interrupted by shutdown can be identified via
GET /jobs/resumable - Result Storage: Access results from any completed job at any time
- Cleanup: Remove old jobs with
POST /jobs/cleanup?days=30
- NumBasis: Use 32 for most cases. Higher values (64, 100) are more accurate but slower.
- Wavelength Step: Use larger steps (5-10 nm) for quick previews, smaller (0.1-1 nm) for final results.
- Parameter Sweeps: The GUI parallelizes across configurations, so sweeps with many configurations benefit most.
- Make sure you've activated the S4 conda environment
- Check that port 8000 is not in use
- Look for errors in the backend terminal window
- Verify S4 is installed:
conda list | grep s4 - Try reinstalling:
conda install -c conda-forge s4
- Reduce NumBasis for testing
- Use larger wavelength steps
- Enable only the outputs you need (T/R/A or fields, not both)
- Run
stop.batto clean up any lingering processes - Or manually kill processes on ports 8000/5173:
netstat -ano | findstr :8000 taskkill /PID <pid> /F
This project was built for the UTA photonics lab. Contributions are welcome!
MIT License - See LICENSE file for details.
- Stanford S4 - RCWA simulation library
- FastAPI - Python web framework
- React - Frontend library
- Plotly - Interactive visualization