You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to load a .mat lattice file using at.load.matfile.load_mat, multipole magnets that have both a PolynomB and a K value defined raise an error:
# Set MaxOrder while PolynomA and PolynomB are not set yetsuper(ThinMultipole, self).__setattr__('MaxOrder', maxorder)
# Adjust polynom lengths and set themlen_ab=max(self.MaxOrder+1, len_a, len_b)
self.PolynomA=lengthen(poly_a, len_ab-len_a)
self.PolynomB=lengthen(poly_b, len_ab-len_b)
super(ThinMultipole, self).__init__(family_name, **kwargs)
so that PolynomB is defined prior to the potential call to the setter.
However, I have not tested if this breaks anything else in the code.
The text was updated successfully, but these errors were encountered:
Hello @space-budgie, thank you for finding this bug and clearly identifying the cause.
Interestingly, in the example you've given, if atquadrupole had been used to create the element in Matlab instead of atmultipole then this bug wouldn't have occurred; I'm glad you didn't though as this exposes a deeper issue with how we handle K and H attributes/kwargs during element creation.
Good job with the temporary fix and for being aware that it may break other things; while, strictly speaking, it doesn't break anything else, it would result in the value of K overwriting PolynomB[1] which is the opposite of how it is currently handled and would be inconsistent with the other magnet classes.
I will prepare a complete fix that correctly handles K and H attributes during element creation for all applicable magnet types and make a pull request.
Issue
While trying to load a
.mat
lattice file usingat.load.matfile.load_mat
, multipole magnets that have both aPolynomB
and aK
value defined raise an error:This was tested for Python accelerator toolbox version 0.4.0.
Here, QFEND is defined with with the Matlab code
Potential cause
I believe that the issue lies in the function call
at/pyat/at/lattice/elements.py
Line 628 in 1e32037
where passing in
K
as part of**kwargs
causes a call toat/pyat/at/lattice/elements.py
Lines 704 to 706 in 1e32037
but
PolynomB
is only defined later inat/pyat/at/lattice/elements.py
Line 634 in 1e32037
(Temporary) fix
I managed to bypass the issue by changing the lines
at/pyat/at/lattice/elements.py
Lines 628 to 634 in 1e32037
to
so that
PolynomB
is defined prior to the potential call to the setter.However, I have not tested if this breaks anything else in the code.
The text was updated successfully, but these errors were encountered: