-
Notifications
You must be signed in to change notification settings - Fork 36
IBS module for pyat #955
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: master
Are you sure you want to change the base?
IBS module for pyat #955
Conversation
|
Hello @Ritu-Bharadwaj , thank you for this work! Can you make an example script showing how to use it? I recommend that you put it in This will make it much easier to understand and provide feedback. |
swhite2401
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.
Very nice work! I added a few comments with possible simplifications.
| bunch object that is being tracked. | ||
| """ | ||
|
|
||
| d = 4 * np.std(bunch[2, :]) |
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.
Here to simplify you may just run the std command on the full bunch array and return it directly as an array after modifying the values when needed
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.
I agree with Simon that doing an std on the whole particle array may be more efficient. In addition, d=4sigma_y is the most common case. But in the case you have a bunch with horizontal emittance smaller than the vertical one, the d parameter will be d=4sigma_y. I know that in mbtrack2, it's probably also 4sigma_y, but physically it should probably be min(4sigma_x, 4*sigma_y).
|
|
||
| def initialize(bunch, ring): | ||
| """ | ||
| calculates bunch parameters at each turn. |
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.
it is better to document all input argument, there is also a format to respect such that the docstring appear correctly in the AT documentation
| ): | ||
| """ | ||
| Calculates emittances and derived parameters (a, b, q, sigma_H) based on the selected Intrabeam Scattering (IBS) model. | ||
| These computations are performed every 500 turns by default, or at user-defined intervals specified by the update_turns variable, |
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.
Same comment on documentation
| """ | ||
|
|
||
| sigma = at.sigma_matrix(beam=bunch) | ||
| eigs, _ = np.linalg.eig(sigma @ at.jmat(3)) |
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.
A function get_emittance() could be useful in general
| emitx = emits[1] | ||
| emity = emits[0] | ||
|
|
||
| if model == "PS": |
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.
You may create an Enum class to handle cases
| s_points = np.linspace(0, self.circumference, self.n_points, endpoint=False) | ||
| self.ring = self.ring.sbreak(s_points, marker_list) | ||
| refpts = self.ring.get_uint32_index("ibs*") | ||
| elemdata, avebeta, _, avedisp, avespos, tune, chrom = self.ring.disable_6d( |
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.
Same here is there a problem with 6d optics?
| ).avlinopt(dp=0.0, refpts=refpts + 1) | ||
| self.beta_x = avebeta[:, 0] | ||
| self.beta_y = avebeta[:, 1] | ||
| self.alphaX = [e.alpha[0] for e in elemdata] |
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.
why a loop here and not on the other parameters?
| bunch, n_bin, sigma_p, sigma_px, sigma_py, revolution_frequency, T_x, T_y, T_p | ||
| ): | ||
| """ | ||
| Applies IBS-induced momentum kicks to the bunch every turn, scaled by growth rates, |
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.
Documentation
| Rho = 1.0 | ||
|
|
||
| N_mp = len(bunch[0, :]) | ||
| Delta_pz = ( |
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.
Same calculation could be factorized
| ) | ||
|
|
||
| T_x, T_y, T_p = ibs.get_scatter_T( | ||
| vabq=vabq, |
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.
for this functions you may just pass a dictionary instead of all arguments separately
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.
Hi, nice work. I see that you kept most of what Salah (M1 intern at SOLEIL from last year) did and adapted it to be run with pyAT. I must say that his mbtrack2 IBS class is not written in a very straightforward way (there are many cases and many optional arguments for different functions). We will likely change it in mbtrack2 at some point. If you make some changes in that for pyAT, I will happily adopt it to mbtrack2.
| @@ -0,0 +1,293 @@ | |||
| """ | |||
| IBS module for Acclerator toolbox(AT) inspired from mbtrack2 | |||
| from Alexin Gamelin , Vadim Gubaidulin (SOLEIL) | |||
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.
| from Alexin Gamelin , Vadim Gubaidulin (SOLEIL) | |
| from Salah Eddine Feddaoui Dellalou, Alexis Gamelin , Vadim Gubaidulin (SOLEIL) |
The majority of the IBS code was written by Salah (M1 intern) last year
| @@ -0,0 +1,165 @@ | |||
| """ | |||
| IBS element for Acclerator toolbox(AT) inspired from mbtrack2 | |||
| from Alexin Gamelin , Vadim Gubaidulin (SOLEIL) | |||
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.
| from Alexin Gamelin , Vadim Gubaidulin (SOLEIL) | |
| from Alexis Gamelin , Vadim Gubaidulin, Salah Eddine Feddaoui Dellalou (SOLEIL) |
| @@ -0,0 +1,241 @@ | |||
| """ | |||
| IBS passmethod for Acclerator toolbox(AT) inspired from mbtrack2 | |||
| from Alexin Gamelin , Vadim Gubaidulin (SOLEIL) | |||
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.
| from Alexin Gamelin , Vadim Gubaidulin (SOLEIL) | |
| from Alexis Gamelin , Vadim Gubaidulin, Salah Eddine Feddaoui Dellalou (SOLEIL) |
|
|
||
| n_points (int, optional): | ||
| Number of points at which optics is computed. | ||
| Default is 10000. |
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.
Just a tip: in mbtrack2 we also have a large number of points set as a default, but in practice, the relevant parameter -- IBS growth rate converges for a much lower amount of sampled points.
| bunch object that is being tracked. | ||
| """ | ||
|
|
||
| d = 4 * np.std(bunch[2, :]) |
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.
I agree with Simon that doing an std on the whole particle array may be more efficient. In addition, d=4sigma_y is the most common case. But in the case you have a bunch with horizontal emittance smaller than the vertical one, the d parameter will be d=4sigma_y. I know that in mbtrack2, it's probably also 4sigma_y, but physically it should probably be min(4sigma_x, 4*sigma_y).
These are the files to model the Intrabeam Scattering effect written purely in python but we intend to convert the passmethod in C in future.