Skip to content

Commit e38bbc9

Browse files
authored
Merge branch 'master' into 171-vectorization-error-in-rbend
2 parents cb9b4b3 + 57d287e commit e38bbc9

File tree

3 files changed

+57
-6
lines changed

3 files changed

+57
-6
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 🚨 Breaking Changes
66

7-
- 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, #157, #170) (@jank324, @cr-xu)
7+
- 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, #157, #170, #172) (@jank324, @cr-xu)
88

99
### 🚀 Features
1010

cheetah/accelerator/cavity.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ def _track_beam(self, incoming: Beam) -> Beam:
155155
outgoing_energy.unsqueeze(-1) * beta1.unsqueeze(-1)
156156
) * (
157157
torch.cos(
158-
incoming.particles[..., 4]
158+
-1
159+
* incoming.particles[..., 4]
159160
* beta0.unsqueeze(-1)
160161
* k.unsqueeze(-1)
161162
+ phi.unsqueeze(-1)

tests/test_compare_ocelot.py

+54-4
Original file line numberDiff line numberDiff line change
@@ -701,13 +701,63 @@ def test_cavity():
701701

702702
# Compare
703703
assert np.isclose(outgoing_beam.beta_x.cpu().numpy(), derived_twiss.beta_x)
704-
assert np.isclose(
705-
outgoing_beam.alpha_x.cpu().numpy(), derived_twiss.alpha_x, rtol=2e-5
706-
)
704+
assert np.isclose(outgoing_beam.alpha_x.cpu().numpy(), derived_twiss.alpha_x)
707705
assert np.isclose(outgoing_beam.beta_y.cpu().numpy(), derived_twiss.beta_y)
706+
assert np.isclose(outgoing_beam.alpha_y.cpu().numpy(), derived_twiss.alpha_y)
708707
assert np.isclose(
709-
outgoing_beam.alpha_y.cpu().numpy(), derived_twiss.alpha_y, rtol=2e-5
708+
outgoing_beam.total_charge.cpu().numpy(), np.sum(outgoing_parray.q_array)
709+
)
710+
assert np.allclose(
711+
outgoing_beam.particles[:, :, 5].cpu().numpy(),
712+
outgoing_parray.rparticles.transpose()[:, 5],
713+
)
714+
assert np.allclose(
715+
outgoing_beam.particles[:, :, 4].cpu().numpy(),
716+
outgoing_parray.rparticles.transpose()[:, 4],
717+
)
718+
719+
720+
def test_cavity_non_zero_phase():
721+
"""Compare tracking through a cavity with a phase offset."""
722+
# Ocelot
723+
tws = ocelot.Twiss()
724+
tws.beta_x = 5.91253677
725+
tws.alpha_x = 3.55631308
726+
tws.beta_y = 5.91253677
727+
tws.alpha_y = 3.55631308
728+
tws.emit_x = 3.494768647122823e-09
729+
tws.emit_y = 3.497810737006068e-09
730+
tws.gamma_x = (1 + tws.alpha_x**2) / tws.beta_x
731+
tws.gamma_y = (1 + tws.alpha_y**2) / tws.beta_y
732+
tws.E = 6e-3
733+
734+
p_array = ocelot.generate_parray(tws=tws, charge=5e-9)
735+
736+
cell = [ocelot.Cavity(l=1.0377, v=0.01815975, freq=1.3e9, phi=30.0)]
737+
lattice = ocelot.MagneticLattice(cell)
738+
navigator = ocelot.Navigator(lattice=lattice)
739+
740+
_, outgoing_parray = ocelot.track(lattice, deepcopy(p_array), navigator)
741+
derived_twiss = ocelot.cpbd.beam.get_envelope(outgoing_parray)
742+
743+
# Cheetah
744+
incoming_beam = cheetah.ParticleBeam.from_ocelot(
745+
parray=p_array, dtype=torch.float64
746+
)
747+
cheetah_cavity = cheetah.Cavity(
748+
length=torch.tensor([1.0377]),
749+
voltage=torch.tensor([0.01815975e9]),
750+
frequency=torch.tensor([1.3e9]),
751+
phase=torch.tensor([30.0]),
752+
dtype=torch.float64,
710753
)
754+
outgoing_beam = cheetah_cavity.track(incoming_beam)
755+
756+
# Compare
757+
assert np.isclose(outgoing_beam.beta_x.cpu().numpy(), derived_twiss.beta_x)
758+
assert np.isclose(outgoing_beam.alpha_x.cpu().numpy(), derived_twiss.alpha_x)
759+
assert np.isclose(outgoing_beam.beta_y.cpu().numpy(), derived_twiss.beta_y)
760+
assert np.isclose(outgoing_beam.alpha_y.cpu().numpy(), derived_twiss.alpha_y)
711761
assert np.isclose(
712762
outgoing_beam.total_charge.cpu().numpy(), np.sum(outgoing_parray.q_array)
713763
)

0 commit comments

Comments
 (0)