Skip to content

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

Merged
merged 4 commits into from
May 23, 2025
Merged

modularize emittance measurement #263

merged 4 commits into from
May 23, 2025

Conversation

roussel-ryan
Copy link
Collaborator

  • 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
@roussel-ryan roussel-ryan requested review from Copilot and nneveu April 25, 2025 21:18
Copy link

@Copilot Copilot AI left a 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)))

@shamin-slac shamin-slac requested a review from pluflou May 22, 2025 22:42
@@ -190,6 +193,17 @@ def validate_rmat(cls, v, info):
assert v.shape == (2, 2, 2)
return v

@field_validator("beamsize_measurement", mode="after")
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will change

@@ -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 = (
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@roussel-ryan roussel-ryan merged commit 5b29ca7 into main May 23, 2025
12 checks passed
@roussel-ryan roussel-ryan deleted the modularize_emittance branch May 23, 2025 19:36
@roussel-ryan roussel-ryan mentioned this pull request May 23, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants