Welcome to Cheetah’s documentation!¶
Cheetah is a high-speed, differentiable particle tracking engine designed specifically for machine learning applications in accelerator physics, such as reinforcement learning, system identification, and magnet tuning.
Resources & Links¶
Code: GitHub Repository
Community: Discord Server
Demos: Cheetah Demos (examples including system identification, magnet tuning, and reinforcement learning)
Key Features¶
Differentiable Physics: Fully integrated with PyTorch’s automatic differentiation (autograd) to allow backpropagation of gradients directly through lattice elements and parameters.
High-Speed Execution: Tailored algorithms optimised to speed up the data generation for training machine learning algorithms and gradient-based parameter optimisation loops.
Vectorised Simulations: Perform parallel parameter sweeps over beam distributions and magnet settings without slow CPU Python loops.
Native GPU/CPU Support: Seamlessly transition computations between CPU and GPU devices (CUDA or MPS) using PyTorch’s native
.to()method.3D Visualisation: Automatic 3D model rendering and mesh export of your lattice geometry for visualisation.
Installation¶
Simply install Cheetah from PyPI by running the following command.
pip install cheetah-accelerator
Quickstart¶
Define a beamline, generate a beam, and track it with PyTorch:
import torch
import cheetah
# Define a simple lattice segment
lattice = cheetah.Segment(
elements=[
cheetah.Quadrupole(length=torch.tensor(0.1), k1=torch.tensor(10.0)),
cheetah.Drift(length=torch.tensor(1.0)),
cheetah.Quadrupole(length=torch.tensor(0.1), k1=torch.tensor(-10.0)),
cheetah.Screen(name="screen"),
]
)
# Sample a particle beam from Twiss parameters
beam = cheetah.ParticleBeam.from_twiss(
beta_x=torch.tensor(3.14),
beta_y=torch.tensor(4.2),
energy=torch.tensor(100e6),
num_particles=10_000,
)
# Track through the lattice
outgoing_beam = lattice.track(beam)
Supported Elements¶
Cheetah currently supports the following accelerator elements:
Drifts:
DriftMagnets:
Quadrupole,Sextupole,Solenoid,Dipole(sector bend), andRBend(rectangular bend)Correctors:
HorizontalCorrector,VerticalCorrector,CombinedCorrectorRF Cavities:
Cavity,TransverseDeflectingCavityDiagnostics:
BPM(Beam Position Monitor),ScreenOther:
Aperture,Undulator,Marker,SpaceChargeKick,CustomTransferMap
If you need an element that is not yet supported, you can open an issue on the GitHub repository. If your element can be described by a linear transfer map, use CustomTransferMap with a predefined matrix. Otherwise, implement a custom element by subclassing Element and implementing the required methods. See Implementing Custom Elements in Cheetah for more information.
For the full element API documentation, see the Accelerator API Reference.
User Guide¶
These guides explain how to use Cheetah and provide an overview of its features, from basics to advanced topics.
Essential walkthroughs for defining lattices, choosing beam representations, and understanding coordinates.
Learn about first- and second-order transfer maps, thin/thick lens modeling, 3D space charge kicks, and virtual diagnostics.
Combine Cheetah with PyTorch automatic differentiation (autograd) for gradient-based optimisation and ML workflows.
Techniques for vectorised parameter sweeps, GPU acceleration, mixed precision, and PyTorch compilation.
Convert lattices from Bmad, Elegant, and Ocelot, or integrate with live control systems like DOOCS.
Implement custom accelerator elements by subclassing Element with transfer maps or tracking logic.
API Reference¶
For a complete overview of the Cheetah API, please refer to the following pages.
API Reference
Cite Cheetah¶
If you use Cheetah, please cite the two papers below.
If you use the 3D meshes generated by Cheetah, please respect the licensing 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 with development dependencies (requires pip>=25.1.1):
pip install --upgrade "pip>=25.1.1"
pip install -e ".[all]" --group dev
To install without optional dependencies, run:
pip install -e . --group dev
We suggest installing pre-commit hooks to automatically conform with the code formatting in commits:
pip install pre-commit
pre-commit install
Acknowledgements¶
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).