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

9 loading and saving from lattices #56

Closed cr-xu closed 1 year ago

cr-xu commented 1 year ago

Implemented save and load via JSON format (according to the LatticeJSON convention: https://github.com/nobeam/latticejson)

Added a rough test of the functions.

cr-xu commented 1 year ago

For a more comprehensive test, we need to check if the loaded lattice is identical to the original one. That would require implementing a __eq__ method for all the lattice elements. @jank324 What's your opinion on this?

jank324 commented 1 year ago

Ah ... very nice! I like the idea. I wonder if there is any reason why we shouldn't just use the @dataclass decorator on (almost) all elements and get __eq__ for free. 🤔