atcollab / at

Accelerator Toolbox
Apache License 2.0
48 stars 31 forks source link

Better handling of Matlab RingParam element #741

Closed lfarv closed 4 months ago

lfarv commented 4 months ago

Matlab uses a RingParam element to store lattice-related parameters. This element does not exist in python since these informations are stored in the Lattice object. When reading a .mat or .m file, python moves its information to the Lattice and discards the element. On saving, python creates a RingParam element and prepends it to the real lattice elements.

But the keep_all keyword argument in load_lattice allows, for special cases, to put a Marker placeholder replacing the RingParam, in order to keep the same number of elements as in the Matlab lattice. When saving, a new RingParam is created and inserted before the Marker, so that after a number of load/save sequences, Markers accumulate at the beginning of the lattice. This was reported by @lnadolski in #739.

In this PR, the Marker placeholder is identified as such by a tag attribute, and is removed when saving the file. Markers don't accumulate any more.

Note however that the keep_all keyword should not be used unless really necessary: keeping a useless element in the lattice is disturbing and inefficient.

Note: most of the changes are due to formatting the file with black. This gives a derministic format enabling easier code comparison in the future. I'm starting using it when modifying a file.