cheetah-accelerator

Fast and differentiable particle accelerator optics simulation for reinforcement learning and optimisation applications.

https://github.com/desy-ml/cheetah

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README
  • Academic publication links
    Links to: aps.org
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (17.0%) to scientific vocabulary

Keywords

accelerator-physics data-collection differentiable-simulations machine-learning python reinforcement-learning simulation
Last synced: 6 months ago · JSON representation ·

Repository

Fast and differentiable particle accelerator optics simulation for reinforcement learning and optimisation applications.

Basic Info
Statistics
  • Stars: 54
  • Watchers: 7
  • Forks: 23
  • Open Issues: 94
  • Releases: 18
Topics
accelerator-physics data-collection differentiable-simulations machine-learning python reinforcement-learning simulation
Created over 4 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog License Citation

README.md

format pytest Documentation Status codestyle License: GPL v3 PyPI Downloads Binder

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.

bash 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.

python import cheetah import torch

Lattices in Cheetah are represented by Segments. A Segment is created as follows.

python 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

python 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.

python 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

python 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.

python 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.

python outgoing_beam = segment.track(astra_beam)

You may plot a segment with reference particle traces by calling

python segment.plot_overview(incoming=astra_beam, resolution=0.05)

Overview Plot

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.

python mesh, _ = segment.to_mesh( cuteness={cheetah.HorizontalCorrector: 2.0, cheetah.VerticalCorrector: 2.0} ) mesh.show()

Animated Mesh

python 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.

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

sh pip install -e .

We suggest installing pre-commit hooks to automatically conform with the code formatting in commits:

sh 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:

DESY   KIT   LBNL   University of Chicago   SLAC   University of Liverpool   Cockcroft Institute   Hamburg University of Technology   Science and Technology Facilities Council   Argonne National Laboratory   Hamburg Open Online University  

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

Owner

  • Name: desy-ml
  • Login: desy-ml
  • Kind: organization
  • Location: Germany

Citation (CITATION.bib)

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

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 168
  • Total Committers: 5
  • Avg Commits per committer: 33.6
  • Development Distribution Score (DDS): 0.19
Top Committers
Name Email Commits
Jan Kaiser j****r@d****e 136
Jan Kaiser j****l@g****m 15
Chenran Xu c****u@k****u 11
Oliver Stein o****n@d****e 4
Chenran Xu c****u@d****e 2
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 253
  • Total pull requests: 432
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 13 days
  • Total issue authors: 24
  • Total pull request authors: 17
  • Average comments per issue: 0.64
  • Average comments per pull request: 1.84
  • Merged pull requests: 343
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 132
  • Pull requests: 264
  • Average time to close issues: 17 days
  • Average time to close pull requests: 10 days
  • Issue authors: 19
  • Pull request authors: 14
  • Average comments per issue: 0.34
  • Average comments per pull request: 1.72
  • Merged pull requests: 199
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • jank324 (116)
  • Hespe (45)
  • cr-xu (44)
  • jp-ga (10)
  • amylizzle (9)
  • RemiLehe (6)
  • roussel-ryan (3)
  • zihan-zh (3)
  • FelixTheilen (2)
  • austin-hoover (1)
  • adhamrait (1)
  • irgallard (1)
  • smartsammler (1)
  • emrecosgun314 (1)
  • ansantam (1)
Pull Request Authors
  • jank324 (196)
  • Hespe (75)
  • cr-xu (60)
  • amylizzle (21)
  • RemiLehe (15)
  • roussel-ryan (14)
  • FelixTheilen (14)
  • jp-ga (10)
  • ansantam (9)
  • chrisjcc (3)
  • ax3l (3)
  • BinduSharan (2)
  • ThorstenHellert (2)
  • zihan-zh (2)
  • adhamrait (2)
Top Labels
Issue Labels
enhancement (76) bug (71) documentation (28) question (9) good first issue (8) release (3) help wanted (1)
Pull Request Labels
enhancement (131) bug (119) documentation (49) release (3)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 816 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 17
  • Total maintainers: 2
pypi.org: cheetah-accelerator

Fast and differentiable particle accelerator optics simulation for reinforcement learning and optimisation applications.

  • Versions: 17
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 816 Last month
Rankings
Dependent packages count: 7.4%
Forks count: 17.0%
Average: 17.9%
Stargazers count: 19.4%
Dependent repos count: 22.2%
Downloads: 23.7%
Maintainers (2)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • ipykernel *
  • nbsphinx *
setup.py pypi
  • matplotlib *
test_requirements.txt pypi
  • pytest * test
  • pytest-cov * test
.github/workflows/format.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • py-actions/flake8 v2 composite
.github/workflows/pytest.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite