Skip to content
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

Emittance Measurement Class #198

Merged
merged 23 commits into from
Nov 13, 2024
Merged

Conversation

shamin-slac
Copy link
Contributor

  • This class provides a measure() method for computing the emittance given magnet and screen/wire settings
  • Beam size is retrieved directly from the screen/wire
  • rmats are taken from the Model (imported from meme.model) initialized for some beamline

@roussel-ryan roussel-ryan self-requested a review October 3, 2024 16:25
Copy link
Collaborator

@roussel-ryan roussel-ryan left a comment

Choose a reason for hiding this comment

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

Just writing out comments that we discussed last week. LMK if you have any questions before the end of the week

from meme.model import Model

class QuadScanEmittance(Measurement):
model_beamline: str
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of passing model_beamline, magnet_area, magnet_name, I would define a field
magnet_collection: MagnetCollection, same for the measurement_device class (which will have the area attribute inside of it). These can be public attributes that get dumped with everything else since they are pydantic objects

Copy link
Collaborator

Choose a reason for hiding this comment

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

these fields should be required

Copy link
Collaborator

Choose a reason for hiding this comment

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

We can also make it so that we can pass a string to these attributes, for that you would use the following code for example in the magnet_collection class

@field_validator("magnet_collection", mode="before")
def validate_magnet_collection(cls, value):
    if isinstance(value, str):
        value = create_magnet_collection(value)
    
    return value

lcls_tools/common/measurements/emittance_measurement.py Outdated Show resolved Hide resolved
lcls_tools/common/measurements/emittance_measurement.py Outdated Show resolved Hide resolved
lcls_tools/common/measurements/emittance_measurement.py Outdated Show resolved Hide resolved
lcls_tools/common/measurements/emittance_measurement.py Outdated Show resolved Hide resolved
@shamin-slac shamin-slac marked this pull request as ready for review November 6, 2024 22:21
Copy link
Collaborator

@roussel-ryan roussel-ryan left a comment

Choose a reason for hiding this comment

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

mostly looks good to me, added a few comments. Lets discuss those here and wait for Dylan to put together his prototype measurement notebook to see if we are missing anything obvious

gets the rmat and twiss parameters, then computes and returns the emittance and BMAG
measure_beamsize: take measurement from measurement device, store beam sizes
"""
name: str = "emittance_profile"
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe just name it emittance? emittance_profile doesn't mean much

@roussel-ryan
Copy link
Collaborator

@dylanmkennedy can you draft a prototype run notebook for diag0 using the current code in Shamin's branch to see if we are missing anything?

Copy link
Collaborator

@eloiseyang eloiseyang left a comment

Choose a reason for hiding this comment

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

Looks pretty good to me, I only made minor comments.

- Add x_rms and y_rms to output of emittance measure method
- Raise NotImplementedError for MultiDeviceEmittance measure method and compute_emit_bmag
- Shorten mock values in test_emittance_measurement
- Get rmats at 'mid' of from_device (the magnet)
- Get twiss at measurement_device (the screen)
- Use just x rmat and y rmat for compute_emit_bmag
Copy link
Member

@nneveu nneveu left a comment

Choose a reason for hiding this comment

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

I don't see anything major to prevent merging. Checks were also passed. If Ryan or Eloise also approve, one of them can close the PR.

lcls_tools/common/data/model_general_calcs.py Outdated Show resolved Hide resolved
self.beam_sizes["x_rms"] = []
if "y_rms" not in self.beam_sizes:
self.beam_sizes["y_rms"] = []
self.beam_sizes["x_rms"].append(np.mean(results["Sx"]))
Copy link
Member

Choose a reason for hiding this comment

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

where is Sx coming from? and why the mean?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sx is coming from the GaussianFit method, a separate PR can be used to change this. I've added in a n_shots key to the emittance measurement class to allow for averaging over multiple shots

Copy link
Member

Choose a reason for hiding this comment

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

Ok, will merge as is and can you please write two issues related to this:

  • address the Sx
  • We need to return error bars when averaging (or am I missing that here?)

lcls_tools/common/measurements/emittance_measurement.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@roussel-ryan roussel-ryan left a comment

Choose a reason for hiding this comment

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

need to address Nicole's comments and Qs on Slack, I can make the changes since Shamin is at accelerator school

Copy link
Member

@nneveu nneveu left a comment

Choose a reason for hiding this comment

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

I'm ok merging this as is for the opportunity to test this week. Please write up those issues, and let me know if you need anything else from me.


results = {
"emittance": emittance,
"BMAG": bmag,
Copy link
Member

Choose a reason for hiding this comment

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

does BMAG need to be capitalized?

self.beam_sizes["x_rms"] = []
if "y_rms" not in self.beam_sizes:
self.beam_sizes["y_rms"] = []
self.beam_sizes["x_rms"].append(np.mean(results["Sx"]))
Copy link
Member

Choose a reason for hiding this comment

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

Ok, will merge as is and can you please write two issues related to this:

  • address the Sx
  • We need to return error bars when averaging (or am I missing that here?)

@nneveu nneveu merged commit c9fb299 into slaclab:main Nov 13, 2024
3 checks passed
@roussel-ryan
Copy link
Collaborator

See Issues #206 #205

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.

4 participants