Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jank324 committed Sep 20, 2024
2 parents ad4ad1c + 3038c7b commit 149ca84
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
- Fix bug where `dtype` was not used when creating a `ParameterBeam` from Twiss parameters (see #206) (@jank324)
- Fix bug after running `Segment.inactive_elements_as_drifts` the drifts could have the wrong `dtype` (see #206) (@jank324)
- Fix an issue where splitting elements would result in splits with a different `dtype` (see #211) (@jank324)
- Pin to NumPy 1.X due to compatibility issues on Windows (see #220) (@hespe)
- Fix issue in Bmad import where collimators had no length by interpreting them as `Drift` + `Aperture` (see #249) (@jank324)
- Fix NumPy 2 compatibility issues with PyTorch on Windows (see #220, #242) (@hespe)

### 🐆 Other

Expand All @@ -45,6 +46,7 @@
- Fix the quadrupole strength units in the quadrupole docstring (see #202) (@ansantam)
- Add CI runs for macOS (arm64) and Windows (see #226) (@cr-xu, @jank324, @hespe)
- Clean up CI pipelines (see #243, #244) (@jank324)
- Fix logo display in README (see #252) (@jank324)

## [v0.6.3](https://github.com/desy-ml/cheetah/releases/tag/v0.6.3) (2024-03-28)

Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<img src="images/logo.png" align="right" width="25%"/>

![format](https://github.com/desy-ml/cheetah/actions/workflows/format.yaml/badge.svg)
![pytest](https://github.com/desy-ml/cheetah/actions/workflows/pytest.yaml/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/cheetah-accelerator/badge/?version=latest)](https://cheetah-accelerator.readthedocs.io/en/latest/?badge=latest)
Expand All @@ -10,7 +8,13 @@

# Cheetah

Cheetah is a particle tracking accelerator we built specifically to speed up the training of reinforcement learning models.
<img src="images/logo.png" align="right" width="25%"/>

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](https://doi.org/10.1103/PhysRevAccelBeams.27.054601). To learn how to use Cheetah, we refer to the example notebooks in the [Cheetah documentation](https://cheetah-accelerator.readthedocs.io/).

## Installation

Expand Down
47 changes: 34 additions & 13 deletions cheetah/converters/bmad.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,26 +216,47 @@ def convert_element(
["element_type", "l", "alias", "type", "x_limit", "y_limit"],
bmad_parsed,
)
return cheetah.Aperture(
x_max=torch.tensor(bmad_parsed.get("x_limit", np.inf)),
y_max=torch.tensor(bmad_parsed.get("y_limit", np.inf)),
shape="rectangular",
return cheetah.Segment(
elements=[
cheetah.Drift(
length=torch.tensor(bmad_parsed.get("l", 0.0)),
name=name + "_drift",
device=device,
dtype=dtype,
),
cheetah.Aperture(
x_max=torch.tensor(bmad_parsed.get("x_limit", np.inf)),
y_max=torch.tensor(bmad_parsed.get("y_limit", np.inf)),
shape="rectangular",
name=name + "_aperture",
device=device,
dtype=dtype,
),
],
name=name,
device=device,
dtype=dtype,
)
elif bmad_parsed["element_type"] == "ecollimator":
validate_understood_properties(
["element_type", "l", "alias", "type", "x_limit", "y_limit"],
bmad_parsed,
)
return cheetah.Aperture(
x_max=torch.tensor(bmad_parsed.get("x_limit", np.inf)),
y_max=torch.tensor(bmad_parsed.get("y_limit", np.inf)),
shape="elliptical",
name=name,
device=device,
dtype=dtype,
return cheetah.Segment(
elements=[
cheetah.Drift(
length=torch.tensor(bmad_parsed.get("l", 0.0)),
name=name + "_drift",
device=device,
dtype=dtype,
),
cheetah.Aperture(
x_max=torch.tensor(bmad_parsed.get("x_limit", np.inf)),
y_max=torch.tensor(bmad_parsed.get("y_limit", np.inf)),
shape="elliptical",
name=name + "_aperture",
device=device,
dtype=dtype,
),
],
)
elif bmad_parsed["element_type"] == "wiggler":
validate_understood_properties(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
long_description_content_type="text/markdown",
packages=[package for package in find_packages() if package.startswith("cheetah")],
python_requires=">=3.9",
install_requires=["matplotlib", "numpy<2.0", "scipy", "torch"],
install_requires=["matplotlib", "numpy", "scipy", "torch"],
)
7 changes: 4 additions & 3 deletions tests/test_bmad_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@ def test_bmad_tutorial():

correct = cheetah.Segment(
[
cheetah.Drift(length=torch.tensor(0.5), name="d"),
cheetah.Drift(length=torch.tensor([0.5]), name="d"),
cheetah.Dipole(
length=torch.tensor(0.5), e1=torch.tensor(0.1), name="b"
length=torch.tensor([0.5]), e1=torch.tensor([0.1]), name="b"
), # TODO: What are g and dg?
cheetah.Quadrupole(
length=torch.tensor(0.6), k1=torch.tensor(0.23), name="q"
length=torch.tensor([0.6]), k1=torch.tensor([0.23]), name="q"
),
],
name="bmad_tutorial",
)

assert converted.name == correct.name
assert converted.length == correct.length
assert [element.name for element in converted.elements] == [
element.name for element in correct.elements
]
Expand Down

0 comments on commit 149ca84

Please sign in to comment.