Skip to content

Commit

Permalink
Add test that would have found ASTRA energy dtype bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jank324 committed Dec 1, 2023
1 parent 145e537 commit ecc70e0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_astra_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import torch

import cheetah

Expand Down Expand Up @@ -40,3 +41,21 @@ def test_astra_to_particle_beam():
assert np.allclose(beam.sigma_p.cpu().numpy(), 0.0022804534528404474)
assert np.allclose(beam.energy.cpu().numpy(), 107315902.44394557)
assert np.allclose(beam.total_charge.cpu().numpy(), 5.000000000010205e-13)


def test_astra_to_parameter_beam_dtypes():
"""Test that Astra beams are correctly loaded into particle beams."""
beam = cheetah.ParameterBeam.from_astra("tests/resources/ACHIP_EA1_2021.1351.001")

assert beam.mu_x.dtype == torch.float32
assert beam.mu_xp.dtype == torch.float32
assert beam.mu_y.dtype == torch.float32
assert beam.mu_yp.dtype == torch.float32
assert beam.sigma_x.dtype == torch.float32
assert beam.sigma_xp.dtype == torch.float32
assert beam.sigma_y.dtype == torch.float32
assert beam.sigma_yp.dtype == torch.float32
assert beam.sigma_s.dtype == torch.float32
assert beam.sigma_p.dtype == torch.float32
assert beam.energy.dtype == torch.float32
assert beam.total_charge.dtype == torch.float32

0 comments on commit ecc70e0

Please sign in to comment.