-
Notifications
You must be signed in to change notification settings - Fork 3
Derive MRRA via gradient descent #1911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements gradient descent optimization for deriving the mirror_reflection_random_angle parameter in Monte Carlo simulations for gamma-ray astronomy. The implementation replaces the previous iterative comparison-based approach with a more robust RMSD-based gradient descent optimization.
- Extends the existing PSF parameter optimization framework to support optimizing only
mirror_reflection_random_angle - Introduces gradient descent optimization with adaptive learning rates and configurable RMSD thresholds (default 3%)
- Adds final PSF comparison visualization showing optimized parameters and fit quality
- Replaces D80 containment-based optimization with full PSF curve RMSD minimization
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| src/simtools/ray_tracing/psf_parameter_optimisation.py | Extended PSFParameterOptimizer to support selective parameter optimization, added epsilon parameter to gradient descent methods, and added support for single mirror mode in ray tracing |
| src/simtools/ray_tracing/mirror_panel_psf.py | Refactored to use gradient descent optimization instead of iterative D80 comparison, removed old optimization logic, updated result printing to show RMSD instead of D80 |
| src/simtools/applications/derive_mirror_rnda.py | Updated command-line interface to support gradient descent parameters (threshold, learning_rate), removed old PSF measurement arguments, added cleanup option for intermediate files |
| src/simtools/visualization/plot_psf.py | Enhanced plot functions to handle optional parameter groups, added create_final_psf_comparison_plot for final optimization results |
| tests/unit_tests/ray_tracing/test_psf_parameter_optimisation.py | Added comprehensive tests for gradient descent workflow, refactored tests to use helper fixtures, added tests for single mirror and full telescope modes |
| tests/unit_tests/ray_tracing/test_mirror_panel_psf.py | Replaced old optimization tests with gradient descent tests, added tests for various mirror modes and random focal length configurations |
| tests/unit_tests/visualization/test_plot_psf.py | Added test for create_final_psf_comparison_plot function |
| docs/changes/1911.feature.md | Added changelog entry for gradient descent implementation |
|
GernotMaier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment - please implement. I approve already. Thanks!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 19 out of 19 changed files in this pull request and generated 6 comments.
Adding a label to ray tracing
GernotMaier
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! I can now understand what is happening. A couple of minor comments, nothing big so I approve.
For the plotting: is there still functionality to plot? The important point is to have all plotting related in modules of visualize, but we still want that functionality. Did I miss it?
| Directory containing output files to clean up. | ||
| """ | ||
| patterns = ["*.log", "*.lis*"] | ||
| patterns = ["*.log", "*.lis*", "*.dat"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is ok - but I feel unwell about removing files with "*"
|
|
Thanks for the many detailed reviews @GernotMaier! I have made the changes you listed, the main change was just renaming everything from d80 to psf and using |
|
Please merge - thanks for the patience! |




Use per-mirror d80 measurements to derive
mirror_reflection_random_anglevia gradient descent.Gradients are computed via central finite differences for each RNDA parameter.
Gradients are clipped to avoid instability due to very large updates.
Adaptive learning rate is used
Optimization stops when either:
Usually takes around ~10 iterations per mirror to converge.
To run use:
The per-mirror measured and simulated d80 distributions look like:
The final averaged value of the parameter is exported like this in the telescope sub-folder: mirror_reflection_random_angle-1.0.0.json
and the per-mirror optimization is exported like this:
per_mirror_rnda.json
The algorithm is parallelised, using the
--n_workersflag oros.cpu_count()by default.The parallelisation is generalised and moved to simtools.job_execution. Closes #1990.