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
30 stars 13 forks source link

Remove Ocelot dependencies #4

Closed jank324 closed 1 year ago

jank324 commented 1 year ago

🚀 Feature Request

Remove Ocelot as a dependency of Cheetah but keep functionalities like importing lattices and particle distributions.

Motivation

Cheetah currently depends on Ocelot which causes long import times as well as issues with the installation (see #3 ).

cr-xu commented 1 year ago

Following 2 dependencies of Ocelot needs to be resolved

cr-xu commented 1 year ago

@jank324 regarding the lattice conversion from ocelot, two ideas come to my mind:

  1. move the ocelot import inside utils.ocelot2cheetah function. Since conversion function needs an ocelot.Element anyway, so ocelot should be installed if one wants to use it.
  2. Rely on the element name in class __str__()

I personally prefer the first option. What's your opinion?

On the other hand, I would suggest to just create a write_lattice and read_lattice method so that one can work with only Cheetah when doing RL training, i.e. also get rid of ocelot lattice file.

jank324 commented 1 year ago

As much as I would like to get rid of all dependencies for Ocelot, I agree that option 1 is probably better.

Realistically, an Ocelot lattice requires Ocelot to be installed in order to define the lattice, so there is no need to convolute things checking the class name strings.

One thing to take into consideration, though: The nice way to do this would then be to add Ocelot as an additional dependency such that someone could install Cheetah as

pip install cheetah-accelerator[ocelot]

and all Ocelot conversions would work. But I worry that PyPI will still reject the installation because they forbid dependencies that are not on PyPI. So the better option would probably be to issue a useful warning to anyone using the Ocelot conversion functions when Ocelot isn't installed.

Loading and saving of lattice files (and beams) I think warrant a new issue. I do really like the idea, because then I can really take Ocelot out of all projects where it's not directly needed.