-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix batching in cavity for particle beam
- Loading branch information
Showing
3 changed files
with
64 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import torch | ||
|
||
import cheetah | ||
|
||
|
||
def test_assert_ei_greater_zero(): | ||
""" | ||
Reproduces | ||
``` | ||
1127 Ef = (energy + delta_energy) / electron_mass_eV | ||
1128 Ep = (Ef - Ei) / self.length # Derivative of the energy | ||
-> 1129 assert Ei > 0, "Initial energy must be larger than 0" | ||
1131 alpha = torch.sqrt(eta / 8) / torch.cos(phi) * torch.log(Ef / Ei) | ||
1133 r11 = torch.cos(alpha) - torch.sqrt(2 / eta) * torch.cos(phi) * torch.sin(alpha) # noqa: E501 | ||
RuntimeError: Boolean value of Tensor with more than one value is ambiguous | ||
``` | ||
""" | ||
cavity = cheetah.Cavity( | ||
length=torch.tensor([3.0441, 3.0441, 3.0441]), | ||
voltage=torch.tensor([48198468.0, 48198468.0, 48198468.0]), | ||
phase=torch.tensor([48198468.0, 48198468.0, 48198468.0]), | ||
frequency=torch.tensor([2.8560e09, 2.8560e09, 2.8560e09]), | ||
name="k26_2a", | ||
) | ||
beam = cheetah.ParticleBeam.from_parameters( | ||
num_particles=100_000, sigma_x=torch.tensor([1e-5]) | ||
).broadcast((3,)) | ||
|
||
_ = cavity.track(beam) |