Skip to main content

format pytest Documentation Status codestyle License: GPL v3 PyPI Downloads

Cheetah

Cheetah is a high-speed differentiable beam dynamics code specifically design 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

A sequence of accelerator elements (or a lattice) is called a Segment in Cheetah. You can create a Segment as follows

import torch
from cheetah import BPM, Drift, HorizontalCorrector, Segment, VerticalCorrector

segment = Segment(
    elements=[
        BPM(name="BPM1SMATCH"),
        Drift(length=torch.tensor(1.0)),
        BPM(name="BPM6SMATCH"),
        Drift(length=torch.tensor(1.0)),
        VerticalCorrector(length=torch.tensor(0.3), name="V7SMATCH"),
        Drift(length=torch.tensor(0.2)),
        HorizontalCorrector(length=torch.tensor(0.3), name="H10SMATCH"),
        Drift(length=torch.tensor(7.0)),
        HorizontalCorrector(length=torch.tensor(0.3), name="H12SMATCH"),
        Drift(length=torch.tensor(0.05)),
        BPM(name="BPM13SMATCH"),
    ]
)

Alternatively you can create a segment from an Ocelot cell by running

segment = Segment.from_ocelot(cell)

All elements can be accesses as a property of the segment via their name. The strength of a quadrupole named AREAMQZM2 for example, may be set by running

segment.AREAMQZM2.k1 = torch.tensor(4.2)

In order to track a beam through the segment, simply call the segment like so

outgoing_beam = segment.track(incoming_beam)

You can choose to track either a beam defined by its parameters (fast) or by its particles (precise). Cheetah defines two different beam classes for this purpose and beams may be created by

beam1 = ParameterBeam.from_parameters()
beam2 = ParticleBeam.from_parameters()

It is also possible to load beams from Ocelot ParticleArray or Astra particle distribution files for both types of beam

ocelot_beam = ParticleBeam.from_ocelot(parray)
astra_beam = ParticleBeam.from_astra(filepath)

You may plot a segment with reference particle traces bay calling

segment.plot_overview(incoming=beam)

Overview Plot

where the keyword argument beam is the incoming beam represented by the reference particles.

Cite Cheetah

If you use Cheetah, please cite the following two papers:

@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)

Institutions

The development of Cheetah is a joint effort by members of the following institutions:

DESY   KIT   LBNL   University of Chicago   SLAC   University of Liverpool   Cockcroft Institute   Hamburg University of Technology

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 and the Center for Bright Beams, NSF Award No. PHY-1549132. In addition, we acknowledge support from DESY (Hamburg, Germany) and KIT (Karlsruhe, Germany), members of the Helmholtz Association HGF.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cheetah_accelerator-0.7.1.tar.gz (119.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cheetah_accelerator-0.7.1-py3-none-any.whl (109.7 kB view details)

Uploaded Python 3

File details

Details for the file cheetah_accelerator-0.7.1.tar.gz.

File metadata

  • Download URL: cheetah_accelerator-0.7.1.tar.gz
  • Upload date:
  • Size: 119.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for cheetah_accelerator-0.7.1.tar.gz
Algorithm Hash digest
SHA256 1726a3041060c11d5874f23ebccb1eef0dfbc8461a22a5298872baa4b86b324f
MD5 b71af624684eb30fcca627c5a440439b
BLAKE2b-256 3f86360b59005f0951bd2ada459679caee8d509743a26eda88d409f38bb34b2b

See more details on using hashes here.

File details

Details for the file cheetah_accelerator-0.7.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cheetah_accelerator-0.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 51a044bc4ce812c14715c4510cb526178d809215e927517adae38f709d6f6aef
MD5 b400424da83aa830929a5e235fbaa4c6
BLAKE2b-256 ebde4bc2fcc69bacb2e092d3bc5bec37df883d8427ae2272e6cb3ef38b2b288d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page