-
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
base: main
Are you sure you want to change the base?
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!!
|
@GernotMaier could you look at this PR again please? |
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 17 out of 17 changed files in this pull request and generated 4 comments.
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.
Thanks @EshitaJoshi , lots of very good changes! As discussed already in person, we need to work a bit on the maintainability of the new code. Shorter functions are easier. Plotting should be in a separate module. Think about how the result will be used (the log is good to read, but hard to work for with the computer). Consider if we need that many database calls.
| "w" | ||
| ) as file: | ||
| These files are referenced by sim_telarray and must not be shared across | ||
| parallel worker processes (otherwise they can be truncated mid-read). |
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.
How do you make sure that they are not shared across work processes? The information is this is taken care of (e.g., by separate directories or file names) or not.
|
|
||
| # Create ray tracing for single mirror. | ||
| # Use a per-mirror label so parallel runs do not collide on output filenames. | ||
| # IMPORTANT: RayTracing and SimulatorRayTracing derive filenames from |
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 this something we should change in RayTracing and SimulatorRayTracing in a future pull request?
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.
Not that this is the "slowest" integration test we have. Is there a way to shorted the execution time?
|




Use per-mirror d80 measurements to derive
mirror_reflection_random_anglevia gradient descent.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.