Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vectorised simulations #116

Merged
merged 53 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
032ac5d
Convert beams (except for transform) to be batched
jank324 Jan 4, 2024
9f02713
Make beam transforms batch computable
jank324 Jan 5, 2024
f6c39a3
Implement tracking through drift in a batched way as an example
jank324 Jan 5, 2024
dab3f13
Fix all tests except for Cavity ones
jank324 Jan 6, 2024
a077aa2
Fix cavity tests
jank324 Jan 6, 2024
c893beb
Fix properties to be batched
jank324 Jan 6, 2024
accc009
Add some batched tests
jank324 Jan 6, 2024
5b4e39c
Add broadcasting and 100k EA test
jank324 Jan 6, 2024
94064cb
Fix examples to run with batched computations
jank324 Jan 6, 2024
4b7c15f
Fix failing NX tables test
jank324 Jan 6, 2024
df48d85
Fix batching in cavity for particle beam
jank324 Jan 6, 2024
5283bd1
Prevent NaNs in emittance computation
jank324 Jan 7, 2024
b649094
Prvent zero division in twiss parameter computations
jank324 Jan 7, 2024
5b638f9
Move emittance safety to emittance computation
jank324 Jan 7, 2024
a8c5e57
Make sure parameter beam sigmas are always strictly positive
jank324 Jan 7, 2024
892206a
Fix order of sigma safety computations
jank324 Jan 7, 2024
b097bca
Set more sensibel values for parameter beam from twiss
jank324 Jan 7, 2024
5e36218
Ensure unphysical betas don't go unnoticed
jank324 Jan 7, 2024
2a0a8e0
Merge branch 'master' into 100-batched-execution
jank324 Feb 14, 2024
25b9ead
Choose better value for the clipping
jank324 Feb 14, 2024
2ce6e31
Merge branch '100-batched-execution' of github.com:desy-ml/cheetah in…
jank324 Feb 14, 2024
2b2b882
For some elements test that parameters are broadcast correctly
jank324 Feb 14, 2024
d48bbe9
Test tracking after broadcast through EA gives same result
jank324 Feb 14, 2024
0609b45
Add `__repr__` for `CustomTransferMap`
jank324 Feb 14, 2024
d84a501
Add further tests to find bug in vectorised computations on LCLS example
jank324 Feb 14, 2024
5853043
`CustomTransferMap` elements from combination also combine name
jank324 Feb 14, 2024
4494056
Segment default name should work the same as for other elements
jank324 Feb 14, 2024
6b5ac7c
Prevent flooding of unique element names by automatic optimisations
jank324 Feb 14, 2024
0ad75ab
Minor shape fixes
jank324 Feb 14, 2024
f3ea831
Add vectorisation to speed optimisation example notebook
jank324 Mar 17, 2024
7485bfc
Update README to reflect vectorisation
jank324 Mar 17, 2024
a06be55
Merge branch 'master' into 100-batched-execution
jank324 Mar 17, 2024
a82be19
Formatting fix
jank324 Mar 17, 2024
99acb66
Half fix the broken test
jank324 Mar 17, 2024
db1c5f9
Fix merge issue in cavity transfer map
cr-xu Mar 19, 2024
1f3865b
Fix cavity batch execution
cr-xu Mar 19, 2024
958aed8
Merge branch 'master' into 100-batched-execution
jank324 Mar 27, 2024
dc4e5d7
Choose more appropriate name for test file
jank324 Mar 27, 2024
47a5497
Test that n-dimensional inputs work
jank324 Mar 28, 2024
47632b0
Attempt to fix tests that fail on GitHub but succeed locally
jank324 Mar 28, 2024
5f9984b
Merge branch 'master' into 100-batched-execution
jank324 Mar 28, 2024
c212c9e
Add changelog entry for vectorisation
jank324 Mar 28, 2024
0589ee1
Already bumb version to first v0.7 release
jank324 Mar 28, 2024
9b9abe4
Add zero length to `Element` and add new test cases, fixes #143
cr-xu Apr 5, 2024
0dbf71a
Move zero length fix entry to bug fixes
jank324 Apr 5, 2024
2a27cd7
Some vscode stuff that makes sense for others to reuse
jank324 Apr 5, 2024
6faef7d
Test that breaks lengthless element fix
jank324 Apr 5, 2024
806d191
Fix issue with lengthless fix for Screen
jank324 Apr 6, 2024
457c18a
Merge branch 'master' into 100-batched-execution
jank324 Apr 16, 2024
93e9eb6
Add notice for developers on n-dimensional properties
jank324 Apr 16, 2024
ae5b61d
Update GitHub action steps versions
jank324 Apr 16, 2024
0e36c11
Fix action upgrade to actual up-to-date actions
jank324 Apr 16, 2024
0d6ef18
Merge branch 'master' into 100-batched-execution
jank324 Apr 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
17 changes: 17 additions & 0 deletions .vscode/ltex.dictionary.en-GB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
PyPI
undoc-members
DESY
Bmad
Twiss
maxdepth
CUDA
Chenran
Eichler
Santamaria
@cr-xu
LatticeJSON
docstring
@FelixTheilen
pytest
isort
docstrings
9 changes: 9 additions & 0 deletions .vscode/ltex.disabledRules.en-GB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
OXFORD_SPELLING_Z_NOT_S
36 changes: 36 additions & 0 deletions .vscode/ltex.hiddenFalsePositives.en-GB.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qwhere the optional keyword argument \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q is the incoming beam represented by the reference particles.\\E$"}
{"rule":"OXFORD_SPELLING_Z_NOT_S","sentence":"^\\QGradient-based optimisation using Cheetah and PyTorch\\E$"}
{"rule":"OXFORD_SPELLING_Z_NOT_S","sentence":"^\\QCheetah is a differentiable beam dynamics simulation engine, making it ideally suited to gradient-based optimisation, for example for optimisation magnet settings, lattice geometries or even for system identification.\\E$"}
{"rule":"COMMA_PARENTHESIS_WHITESPACE","sentence":"^\\Q, pass the file path to \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q.\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QUtils\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qutils\n:members:\n:undoc-members:\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qconverters.nocelot\n:members:\n:undoc-members:\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QNOcelot\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QLatticeJSON\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qlatticejson\n:members:\n:undoc-members:\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QDontBmad\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qconverters.dontbmad\n:members:\n:undoc-members:\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QAstralavista\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qconverters.astralavista\n:members:\n:undoc-members:\\E$"}
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qbash\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Q:maxdepth: 2\n:caption: Examples\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qexamples/simple\nexamples/convert\nexamples/gradientbased\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qaccelerator\nastralavista\ndontbmad\nerror\nlatticejson\nnocelot\nparticles\ntrack_methods\nutils\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qbibtex\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Qbibtex\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\Q@inproceedings{stein2022accelerating,\nauthor = {Stein, Oliver and\nKaiser, Jan and\nEichler, Annika},\ntitle = {Accelerating Linear Beam Dynamics Simulations for Machine Learning Applications},\nbooktitle = {Proceedings of the 13th International Particle Accelerator Conference},\nyear = {2022},\nurl = {https://github.com/desy-ml/cheetah},\n}\\E$"}
{"rule":"COMMA_PARENTHESIS_WHITESPACE","sentence":"^\\Q@inproceedings{stein2022accelerating,\nauthor = {Stein, Oliver and\nKaiser, Jan and\nEichler, Annika},\ntitle = {Accelerating Linear Beam Dynamics Simulations for Machine Learning Applications},\nbooktitle = {Proceedings of the 13th International Particle Accelerator Conference},\nyear = {2022},\nurl = {https://github.com/desy-ml/cheetah},\n}\\E$"}
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qpip install -e .\\E$"}
{"rule":"COMMA_PARENTHESIS_WHITESPACE","sentence":"^\\Qpip install -e .\\E$"}
{"rule":"ENGLISH_WORD_REPEAT_RULE","sentence":"^\\Qpip install pre-commit\npre-commit install\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QConvert from Bmad lattices files (see #65) (@jank324)\nAdd proper transfer map for cavity (see #65) (@jank324, @cr-xu)\nTwiss parameter calculation and generate new beam from twiss parameter (see #62) (@jank324, @cr-xu)\nSaving and loading lattices from LatticeJSON (see #9) (@cr-xu)\nNested \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Qs can now be flattened (@jank324)\nOcelot converter adds support for \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q, \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q and \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q (see #78) (@jank324)\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QFix issue where multivariate_normal() crashes because cov is not positive-semidefinite.\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QFaster screen reading simulation by using torch.histogramdd()\\E$"}
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qv0.5.15 (2022-10-12)\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QAdd caching of Screen.reading to avoid expensive recomputation\\E$"}
{"rule":"LC_AFTER_PERIOD","sentence":"^\\QAdd caching of Screen.reading to avoid expensive recomputation\\E$"}
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qv0.5.13 (2022-07-26)\\E$"}
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qv0.5.14 (2022-09-28)\\E$"}
{"rule":"UPPERCASE_SENTENCE_START","sentence":"^\\Qv0.5.17 (2023-02-05)\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QImprove docstrings (@FelixTheilen)\nImplement better testing with pytest (@FelixTheilen)\nSetup formatting with \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q and \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q as well as \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q listing (@cr-xu)\nAdd type annotations (@jank324)\nSetup Sphinx documentation on readthedocs (@jank324)\\E$"}
{"rule":"MORFOLOGIK_RULE_EN_GB","sentence":"^\\QFix dependencies on readthedocs (see #54) (@jank324)\nFix error when tracking \\E(?:Dummy|Ina|Jimmy-)[0-9]+\\Q through segment on CPU (see #68) (@cr-xu)\\E$"}
17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"spellright.language": [
"en_GB"
],
"spellright.documentTypes": [
"markdown",
"latex",
"plaintext"
],
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "none",
"esbonio.sphinx.confDir": ""
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

### 🚨 Breaking Changes

- Cheetah is now vectorised. This means that you can run multiple simulations in parallel by passing a batch of beams and settings, resulting a number of interfaces being changed. For Cheetah developers this means that you now have to account for an arbitrary-dimensional tensor of most of the properties of you element, rather than a single value, vector or whatever else a property was before. (see #116) (@jank324)

### 🚀 Features

- `CustomTransferMap` elements created by combining multiple other elements will now reflect that in their `name` attribute (see #100) (@jank324)

### 🐛 Bug fixes

- Now all `Element` have a default length of `torch.zeros((1))`, fixing occasional issues with using elements without length, such as `Marker`, `BPM`, `Screen`, and `Aperture`. (see #143) (@cr-xu)

### 🐆 Other

- Update versions of some steps used by GitHub actions to handle Node.js 16 end-of-life (@jank324)

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

### 🐛 Bug fixes
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ A sequence of accelerator elements (or a lattice) is called a `Segment` in _Chee
segment = Segment(
elements=[
BPM(name="BPM1SMATCH"),
Drift(length=torch.tensor(1.0)),
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)),
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"),
]
)
Expand Down
Loading