-
Notifications
You must be signed in to change notification settings - Fork 24
modularize emittance measurement #263
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
roussel-ryan
commented
Apr 25, 2025
- modify emittance optimization problem to use mean abs error in beamsize space to not prioritize fitting measurements where the beam size is large
- introduce wrapper and preprocessing functions for calculating emittance from machine units
- introduce wrapper and preprocessing functions for calculating emittance from machine units
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 modularizes the emittance measurement by updating the optimization metric to use the mean absolute error in beamsize space and introducing wrapper and preprocessing functions to better handle inputs in machine units.
- Adjusts the optimization error metric in the loss functions for both torch and numpy implementations.
- Introduces a new compute_emit_bmag_machine_units wrapper and preprocessing function in the data module.
- Updates the QuadScanEmittance measurement by reducing the wait_time and adding a type validator for beamsize measurements.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
File | Description |
---|---|
lcls_tools/common/measurements/emittance_measurement.py | Updated imports, wait_time modification, added field validator, and integrated compute_emit_bmag_machine_units in the measurement workflow. |
lcls_tools/common/data/emittance.py | Revised error metric in the loss functions, added preprocess_inputs, and introduced compute_emit_bmag_machine_units wrapper. |
Comments suppressed due to low confidence (2)
lcls_tools/common/data/emittance.py:116
- The loss function now computes the absolute error between the square roots of the calculated and measured values, effectively working in beamsize space instead of mean square beamsize space. Please update the associated docstring and any related documentation to reflect this change in the error metric.
total_squared_error = (torch.sqrt(amat @ sig) - torch.sqrt(beamsize_squared)).abs().sum()
lcls_tools/common/data/emittance.py:136
- The numpy loss function now computes the absolute error between the square roots of the computed and measured beam sizes. Consider updating the function documentation to ensure that the new metric is clearly described and matches the intended optimization behavior.
total_squared_error = np.sum(np.abs(np.sqrt(amat @ sig) - np.sqrt(beamsize_squared)))
@@ -190,6 +193,17 @@ def validate_rmat(cls, v, info): | |||
assert v.shape == (2, 2, 2) | |||
return v | |||
|
|||
@field_validator("beamsize_measurement", mode="after") |
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 there a reason beamsize_measurement isn't specified as ScreenBeamProfileMeasurement type on line 179? Would it still be necessary to do this here?
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.
Will change
lcls_tools/common/data/emittance.py
Outdated
@@ -112,7 +113,9 @@ def loss_torch(params): | |||
params = torch.reshape(params, [*beamsize_squared.shape[:-2], 3]) | |||
sig = torch.stack(beam_matrix_tuple(params), dim=-1).unsqueeze(-1) | |||
# sig should now be shape batchshape x 3 x 1 (column vectors) | |||
total_squared_error = (amat @ sig - beamsize_squared).abs().sum() | |||
total_squared_error = ( |
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.
renaming this would enhance readability
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.
will do