Cheetah
Fast and differentiable particle accelerator optics simulation for reinforcement learning and optimisation applications.
Description
Cheetah
Cheetah is a high-speed differentiable beam dynamics code specifically designed to support machine learning applications for particle accelerators.
Its speed helps generate data fast, for example for extremely data-hungry reinforcement learning algorithms, while its differentiability can be used for a variety of applications, including accelerator tuning, system identification and physics-informed prior means for Bayesian optimisation. Its native integration with machine learning toolchains around PyTorch also makes Cheetah an ideal candidate for coupling of physics-based and neural network beam dynamics models that remain fast and differentiable.
To learn more about what Cheetah can do, we recommend reading our PRAB paper. To learn how to use Cheetah, we refer to the example notebooks in the Cheetah documentation. We also have a public Discord server where you can ask questions and get help.
Installation
Simply install Cheetah from PyPI by running the following command.
pip install cheetah-accelerator
How To Use
You can run the following example in Binder by clicking here or on the badge above.
In this example, we create a custom lattice and track a beam through it. We start with some imports.
import cheetah
import torch
Lattices in Cheetah are represented by Segments. A Segment is created as follows.
segment = cheetah.Segment(
elements=[
cheetah.Drift(length=torch.tensor(0.175)),
cheetah.Quadrupole(length=torch.tensor(0.122), name="AREAMQZM1"),
cheetah.Drift(length=torch.tensor(0.428)),
cheetah.Quadrupole(length=torch.tensor(0.122), name="AREAMQZM2"),
cheetah.Drift(length=torch.tensor(0.204)),
cheetah.VerticalCorrector(length=torch.tensor(0.02), name="AREAMCVM1"),
cheetah.Drift(length=torch.tensor(0.204)),
cheetah.Quadrupole(length=torch.tensor(0.122), name="AREAMQZM3"),
cheetah.Drift(length=torch.tensor(0.179)),
cheetah.HorizontalCorrector(length=torch.tensor(0.02), name="AREAMCHM1"),
cheetah.Drift(length=torch.tensor(0.45)),
cheetah.Screen(name="AREABSCR1"),
]
)
Alternatively you can load lattices from Cheetah's variant of LatticeJSON or convert them from an Ocelot cell
lattice_json_segment = cheetah.Segment.from_lattice_json("lattice_file.json")
segment = cheetah.Segment.from_ocelot(cell)
Note that many values must be passed to lattice elements as torch.Tensors. This is because Cheetah uses automatic differentiation to compute the gradient of the beam position at the end of the lattice with respect to the element strengths. This is necessary for gradient-based magnet setting optimisation.
Named lattice elements (i.e. elements that were given a name keyword argument) can be accessed by name and their parameters changed like so.
segment.AREAMQZM1.k1 = torch.tensor(8.2)
segment.AREAMQZM2.k1 = torch.tensor(-14.3)
segment.AREAMCVM1.angle = torch.tensor(9e-5)
segment.AREAMQZM3.k1 = torch.tensor(3.142)
segment.AREAMCHM1.angle = torch.tensor(-1e-4)
Cheetah has two different beam classes: ParticleBeam and ParameterBeam. The former tracks multiple individual macroparticles for high-fidelity results, while the latter tracks the parameters of a particle distribution to save on compute time and memory.
You can create a beam manually by specifying the beam parameters of a Gaussian distributed beam
parameter_beam = cheetah.ParameterBeam.from_twiss(beta_x=torch.tensor(3.14))
particle_beam = cheetah.ParticleBeam.from_twiss(
beta_x=torch.tensor(3.14), beta_y=torch.tensor(42.0), num_particles=10_000
)
or load beams from other codes and standards, including openPMD, Ocelot and Astra.
astra_beam = cheetah.ParticleBeam.from_astra(
"../../tests/resources/ACHIP_EA1_2021.1351.001"
)
In order to track a beam through the segment, simply call the segment's track method.
outgoing_beam = segment.track(astra_beam)
You may plot a segment with reference particle traces by calling
segment.plot_overview(incoming=astra_beam, resolution=0.05)

where the keyword argument incoming is the incoming beam represented by the reference particles.
You can also visualise your segment in 3D. Note that this requires that you installed Cheetah as pip install cheetah-accelerator[3d-visualization].
Use mesh.show to view the mesh and mesh.export to export it to a file.
mesh, _ = segment.to_mesh(
cuteness={cheetah.HorizontalCorrector: 2.0, cheetah.VerticalCorrector: 2.0}
)
mesh.show()

mesh.export(file_obj="my_first_cheetah_mesh.glb", file_type="glb")
For more demos and examples check out the Examples section in the Cheetah documentation and the cheetah-demos repository.
Cite Cheetah
If you use Cheetah, please cite the two papers below.
If you use 3D meshes generated by Cheetah, please respect the licencing terms of the 3D Assets for Particle Accelerators repository.
@article{kaiser2024cheetah,
title = {Bridging the gap between machine learning and particle accelerator physics with high-speed, differentiable simulations},
author = {Kaiser, Jan and Xu, Chenran and Eichler, Annika and Santamaria Garcia, Andrea},
year = 2024,
month = {May},
journal = {Phys. Rev. Accel. Beams},
publisher = {American Physical Society},
volume = 27,
pages = {054601},
doi = {10.1103/PhysRevAccelBeams.27.054601},
url = {https://link.aps.org/doi/10.1103/PhysRevAccelBeams.27.054601},
issue = 5,
numpages = 17
}
@inproceedings{stein2022accelerating,
title = {Accelerating Linear Beam Dynamics Simulations for Machine Learning Applications},
author = {Stein, Oliver and Kaiser, Jan and Eichler, Annika},
year = 2022,
booktitle = {Proceedings of the 13th International Particle Accelerator Conference}
}
For Developers
Activate your virtual environment. (Optional)
Install the cheetah package as editable
pip install -e .
We suggest installing pre-commit hooks to automatically conform with the code formatting in commits:
pip install pre-commit
pre-commit install
Acknowledgements
Author Contributions
The following people have contributed to the development of Cheetah:
- Jan Kaiser (@jank324)
- Chenran Xu (@cr-xu)
- Annika Eichler (@AnEichler)
- Andrea Santamaria Garcia (@ansantam)
- Christian Hespe (@Hespe)
- Oliver Stein (@OliStein523)
- Grégoire Charleux (@greglenerd)
- Remi Lehe (@RemiLehe)
- Axel Huebl (@ax3l)
- Juan Pablo Gonzalez-Aguilera (@jp-ga)
- Ryan Roussel (@roussel-ryan)
- Auralee Edelen (@lee-edelen)
- Zihan Zhu (@zihan-zh)
- Christian Contreras-Campana (@chrisjcc)
- Sucheth Shenoy (@SuchethShenoy)
- Amelia Pollard (@amylizzle)
- Julian Gethmann (@smartsammler)
Institutions
The development of Cheetah is a joint effort by members of the following institutions:
Funding
The work to develop Cheetah has in part been funded by the IVF project InternLabs-0011 (HIR3X) and the Initiative and Networking Fund by the Helmholtz Association (Autonomous Accelerator, ZT-I-PF-5-6). Further, we gratefully acknowledge funding by the EuXFEL R&D project "RP-513: Learning Based Methods". This work is also supported by the U.S. Department of Energy, Office of Science under Contract No. DE-AC02-76SF00515, the Center for Bright Beams, NSF Award No. PHY-1549132, and the U.S. DOE Office of Science-Basic Energy Sciences, under Contract No. DE-AC02-06CH11357. In addition, we acknowledge support from DESY (Hamburg, Germany) and KIT (Karlsruhe, Germany), members of the Helmholtz Association HGF as well as from the Hamburg Open Online University (HOOU) and the Science and Technology Facilities Council (UK).
Participating organisations
Reference papers
Mentions
- 1.Author(s): Liam A. Pocher, Irving Haber, Brian L. Beaudoin, Thomas M. Antonsen, Patrick G. O’SheaPublished in Nuclear Instruments and Methods in Physics Research Section A: Accelerators, Spectrometers, Detectors and Associated Equipment by Elsevier BV in 2026, page: 17106010.1016/j.nima.2025.171060
- 2.Author(s): Tobias Boltz, Jose L. Martinez, Connie Xu, Kathryn R. L. Baker, Zihan Zhu, Jenny Morgan, Ryan Roussel, Daniel Ratner, Brahim Mustapha, Auralee L. EdelenPublished in Scientific Reports by Springer Science and Business Media LLC in 202510.1038/s41598-025-95297-z
- 3.Author(s): Adnan Ghribi, Kevin Cassou, Barbara Dalena, Annika Eichler, Hayg Guler, Andrew K. Mistry, Adrian Oeftiger, Thomas Shea, Gianluca Valentino, Carsten P. WelschPublished in Europhysics News by EDP Sciences in 2025, page: 15-1910.1051/epn/2025106
- 4.Author(s): Ilya Agapov, Annika Eichler, Frank MayetPublished in Synchrotron Radiation News by Informa UK Limited in 2025, page: 18-2110.1080/08940886.2025.2539054
- 5.Author(s): Till Korten, Vladimir Rybnikov, Peter Steinbach, Najmeh MirianPublished in Physical Review Accelerators and Beams by American Physical Society (APS) in 202510.1103/physrevaccelbeams.28.030703
- 6.Author(s): Jan Kaiser, Anne Lauscher, Annika EichlerPublished in Science Advances by American Association for the Advancement of Science (AAAS) in 202510.1126/sciadv.adr4173
- 7.Author(s): A. Ibrahim, D. Derkach, A. Petrenko, F. Ratnikov, M. KaledinPublished in Physics of Particles and Nuclei by Pleiades Publishing Ltd in 2025, page: 1476-148110.1134/s1063779625700716
- 8.Author(s): Antonio Manjavacas, Juan Gómez-Romero, Damien Ernst, Manuel A. Vázquez-Barroso, Francisco Martín-FuertesPublished in SoftwareX by Elsevier BV in 2025, page: 10214810.1016/j.softx.2025.102148
- 9.Author(s): Christian Hespe, Jan Kaiser, Jannis Lübsen, Frank Mayet, Matthias Scholz, Annika EichlerPublished in at - Automatisierungstechnik by Walter de Gruyter GmbH in 2025, page: 429-44010.1515/auto-2024-0170
- 10.Author(s): Jinyu Wan, Helena Alamprese, Christian Ratcliff, Ji Qiang, Yue HaoPublished in Computer Physics Communications by Elsevier BV in 2025, page: 10949710.1016/j.cpc.2024.109497
- 11.Author(s): Austin Hoover, Jonathan C. WongPublished in Physical Review Research by American Physical Society (APS) in 202410.1103/physrevresearch.6.033163
- 12.Author(s): Ryan Roussel, Auralee L. Edelen, Tobias Boltz, Dylan Kennedy, Zhe Zhang, Fuhao Ji, Xiaobiao Huang, Daniel Ratner, Andrea Santamaria Garcia, Chenran Xu, Jan Kaiser, Angel Ferran Pousa, Annika Eichler, Jannis O. Lübsen, Natalie M. Isenberg, Yuan Gao, Nikita Kuklev, Jose Martinez, Brahim Mustapha, Verena Kain, Christopher Mayes, Weijian Lin, Simone Maria Liuzzo, Jason St. John, Matthew J. V. Streeter, Remi Lehe, Willie NeiswangerPublished in Physical Review Accelerators and Beams by American Physical Society (APS) in 202410.1103/physrevaccelbeams.27.084801
- 13.Author(s): Jan Kaiser, Chenran Xu, Annika Eichler, Andrea Santamaria Garcia, Oliver Stein, Erik Bründermann, Willi Kuropka, Hannes Dinter, Frank Mayet, Thomas Vinatier, Florian Burkart, Holger SchlarbPublished in Scientific Reports by Springer Science and Business Media LLC in 202410.1038/s41598-024-66263-y
- 14.Author(s): Ryan Roussel, Juan Pablo Gonzalez-Aguilera, Eric Wisniewski, Alexander Ody, Wanming Liu, John Power, Young-Kee Kim, Auralee EdelenPublished in Physical Review Accelerators and Beams by American Physical Society (APS) in 202410.1103/physrevaccelbeams.27.094601
- 1.Author(s): Jan Kaiser, Chenran Xu, Andrea Santamaria Garcia, Juan Pablo Gonzalez AguileraPublished in 5th ICFA Beam Dynamics Mini-Workshop on Machine Learning for Particle Accelerators by MaLAPA Collaboration in 2025
- 2.Author(s): Jan KaiserPublished in Fourth MODE Workshop on Differentiable Programming for Experiment Design in 2024
- 3.Author(s): Jan Kaiser, Chenran Xu, Annika Eichler, Andrea Santamaria GarciaPublished in 4th ICFA Beam Dynamics Mini-Workshop on Machine Learning Applications for Particle Accelerators in 2024
- 4.Author(s): Jan KaiserPublished in 10. Annual MT Meeting in 2024
- 1.Author(s): Kishansingh Rajput, Malachi Schram, Auralee Edelen, Jonathan Colen, Armen Kasparian, Ryan Roussel, Adam Carpenter, He Zhang, Jay BenneschPublished in 202510.1088/2632-2153/adc221
- 2.Author(s): Simona Bettoni, Jonas Kallestrup, Güney Erin Tekin, Michael Böge, Romana BoigerPublished in 202510.1107/s1600577525002334
- 3.Author(s): Wei Bao, Ying Li, shuo xu, Xiaohan Lu, Nan Li, Jiao YiPublished in 202510.1088/1402-4896/ade639
- 4.Author(s): Fan Yang, Xuan Liu, Pengbo Wang, Xinheng LiPublished in 202510.1016/j.enganabound.2025.106562
- 5.Author(s): None AnonymousPublished in 202510.1103/bhpv-bcqk
- 6.Author(s): Francisco HuhnPublished in 202510.1103/cbds-lst1
- 7.Author(s): Asif Iqbal, John Verboncoeur, Peng ZhangPublished by Elsevier BV in 202510.2139/ssrn.5363812
- 8.Author(s): Ryan Roussel, Auralee L. Edelen, Tobias Boltz, Dylan Kennedy, Zhe Zhang, Fuhao Ji, Xiaobiao Huang, Daniel Ratner, Andrea Santamaria Garcia, Chenran Xu, Jan Kaiser, Angel Ferran Pousa, Annika Eichler, Jannis O. Lubsen, Natalie M. Isenberg, Yuan Gao, Nikita Kuklev, Jose Martinez, Brahim Mustapha, Verena KainPublished by arXiv in 202310.48550/arxiv.2312.05667