desy-ml / cheetah

Fast and differentiable particle accelerator optics simulation for reinforcement learning and optimisation applications.
https://cheetah-accelerator.readthedocs.io
GNU General Public License v3.0
28 stars 13 forks source link

Confusion in element definition: is_skippable vs is_active #43

Closed cr-xu closed 9 months ago

cr-xu commented 1 year ago

What is exactly the difference between is_skippable and is_active? Sometimes (like for correctors) the is_skippable is directly deduced from the is_active property, is this redundant? @jank324

jank324 commented 1 year ago

So, the idea with these two was the following:

is_active can be used to determine (and if some cases set) whether an Element is in use. That is for magnets, is_active should automatically tell you whether their strength is currently anything other than 0.0. For screens for example, is_active should tell you whether the screen is moved into the beam path. Here, you can actually set is_active to True and False to move the screen in and out, respectively.

is_skippable on the other hand is used for the computational optimisation in that it tells Cheetah whether the transfer map of the element may be combined with others, i.e. it is possible to skip calling the element's __call__ function. Non-skippable elements may be Elements that add/remove particles from the beam (e.g. apertures), need to read properties of the beam at their position (Screens or BPMs) or do something other than transfer map multiplication. I guess this last point is the most general.

Both is_active and is_skippable are sometimes equivalent, for example in the case of a Screen or a BPM. An active screen both blocks the beam and needs to read it. An active BPM needs to read the beam. Therefore, turning them off when you don't need them allows Cheetah to run faster.

jank324 commented 1 year ago

Actually for correctors they are not equivalent ... for screens they are.

jank324 commented 1 year ago

Conclusion

We should document this in the Element class for everyone to know how both properties must be implemented. Each Element subclass should also document their specific behaviour regarding both properties.