Skip to content

Conversation

@swhite2401
Copy link
Contributor

This PR proposes a minor enhancement.

The properties strength and integrated strength pointing to PolynomB[DefaultOrder] and PolynomB[DefaultOrder]*Length are added. A complete octupole element with default strength propertie O is also implemented.
The Strength properties could eventually replace K, H, O to simplify the code.

Few open questions remain:

  • Element without DefaultOrder are not handled -> raise an error when trying to access Strength or IntegratedStrength, here I considered taking into account the lowest non-zero element in PolynomB but I think it is dangerous, what do you think?
  • ThinMultipoles are not handled as they do not have DefaultOrder. Concerning this point I am considering merging the 2 passmethods, ThinMultipole would then become a special case of multipole with length=0.0, this would allow to create thin element simply by setting their length to zero.
    For example:
    thinquadrupole = at.Quadrupole('QUAD', 0.0, 1.0)
    which would be a much more natural user interface.

If considered useful, this last point should be treated in a separate PR.

@swhite2401 swhite2401 requested a review from lfarv August 13, 2025 13:46
@swhite2401
Copy link
Contributor Author

swhite2401 commented Aug 14, 2025

To be noted that the notation K, H, O are not the most intuitive.
K normally stands for the strength and K1, K2, K3 would be the quadrupole, sextupole and octupole strengths...
Similarly, KL, K1L, K2L, etc... are integrated strengths
and KS, K1S, K2S, etc... are skew strengths

Changing this would probably mean breaking backward compatibility but would allow for generalization with compact code.

@swhite2401 swhite2401 marked this pull request as ready for review August 14, 2025 09:06
Comment on lines +505 to +506
def __init__(self, family_name: str, length: float, o: float = 0.0, **kwargs):
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Problem here: you change the signature of the constructor which was

Octupole(name, length, polya, poly)

which is not backward compatible. This is illustrated by the change you had to do in other files.

You could try

def __init__(self, name, length, *args, **kwargs):

    if isinstance(args[0], Iterable):
        polya, polyb = args[:2]
    else:
        polya = []
        polyb = [0.0, 0.0, 0.0, args[0]]

    kwargs.setdefault("PassMethod", "StrMPoleSymplectic4Pass")
    super().__init__(family_name, length, poly, poly, **kwargs)

to keep compatibility

@lfarv
Copy link
Contributor

lfarv commented Aug 15, 2025

To be noted that the notation K, H, O are not the most intuitive. K normally stands for the strength and K1, K2, K3 would be the quadrupole, sextupole and octupole strengths... Similarly, KL, K1L, K2L, etc... are integrated strengths and KS, K1S, K2S, etc... are skew strengths

Changing this would probably mean breaking backward compatibility but would allow for generalization with compact code.

Nothing prevents from adding new properties if it looks useful.

I would consider the ongoing PALS project which tries to set a standard for the definition of magnetic multipoles: they chose Kn1, Kn2… for normal components and Ks1, Ks2… for skew components. And Kn1L, Kn2L… for integrated strengths.

Comment on lines +238 to +239
@property
def Strength(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

The Strength property is wrong for thin multipoles: it should return Infinity. This is not very useful, so the property could be moved to the Multipole class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may argue that for thin element Strength=IntegratedStrength and it is more coherent and easier if all magnet elements have the same properties, I will keep it there and improve the docs instead

@swhite2401
Copy link
Contributor Author

To be noted that the notation K, H, O are not the most intuitive. K normally stands for the strength and K1, K2, K3 would be the quadrupole, sextupole and octupole strengths... Similarly, KL, K1L, K2L, etc... are integrated strengths and KS, K1S, K2S, etc... are skew strengths
Changing this would probably mean breaking backward compatibility but would allow for generalization with compact code.

Nothing prevents from adding new properties if it looks useful.

I would consider the ongoing PALS project which tries to set a standard for the definition of magnetic multipoles: they chose Kn1, Kn2… for normal components and Ks1, Ks2… for skew components. And Kn1L, Kn2L… for integrated strengths.

The problem is that K is now reserved for the gradient while it should be a strength... anyway we have to live with it as long as we maintain backward compatibility. To be kept in mind for future major releases I suppose

@lfarv
Copy link
Contributor

lfarv commented Aug 18, 2025

The problem is that K is now reserved for the gradient while it should be a strength

According to the PALS definition, K is the same as Kn1. Similarly, H is Kn2/2. And so on. Adding such additional properties is easy.

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.

3 participants