Skip to content

Commit

Permalink
Merge branch 'release/0.19.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlopaciuk committed Jan 21, 2025
2 parents e8d6705 + bc550c2 commit 1da2898
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
4 changes: 3 additions & 1 deletion tests/test_multi_bunch_gauss_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
import xpart as xp
import xtrack as xt

from xobjects.test_helpers import for_all_test_contexts
from xobjects.test_helpers import for_all_test_contexts, fix_random_seed

test_data_folder = xt._pkg_root.joinpath('../test_data').absolute()

@for_all_test_contexts
@fix_random_seed(6453645)
def test_multi_bunch_gaussian_generation(test_context):
bunch_intensity = 1e11
sigma_z = 22.5e-2 / 5
Expand Down
39 changes: 18 additions & 21 deletions tests/test_pencil_with_absolute_cut.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
import xpart as xp
import xtrack as xt
import xobjects as xo
from xobjects.test_helpers import for_all_test_contexts
from xpart.test_helpers import flaky_assertions, retry
from xobjects.test_helpers import for_all_test_contexts, fix_random_seed


@for_all_test_contexts
@retry()
@fix_random_seed(7363444)
def test_pencil_with_absolute_cut(test_context):

num_particles = 10000
Expand Down Expand Up @@ -97,26 +96,24 @@ def test_pencil_with_absolute_cut(test_context):
sigma_v = np.sqrt(betv*nemitt_v
/particles._xobject.beta0[0]/particles._xobject.gamma0[0])

with flaky_assertions():
assert(np.isclose(np.min(np.abs(v)), abs(absolute_cut), atol=1e-7))
assert(np.isclose(np.max(np.abs(v)), abs(absolute_cut) + sigma_v*pencil_dr_sigmas,
rtol=1e-3, atol=0))
assert(np.isclose(np.min(np.abs(v)), abs(absolute_cut), atol=1e-7))
assert(np.isclose(np.max(np.abs(v)), abs(absolute_cut) + sigma_v*pencil_dr_sigmas,
rtol=1e-3, atol=0))

i_tip = np.argmax(np.abs(v))
assert np.isclose(pv[i_tip]/v[i_tip], -alfv/betv, atol=5e-4)
i_tip = np.argmax(np.abs(v))
assert np.isclose(pv[i_tip]/v[i_tip], -alfv/betv, atol=5e-4)

if side == '+':
assert np.all(v >= 0)
else:
assert np.all(v <= 0)

other_plane = {'x': 'y', 'y': 'x'}[plane]
w_norm = getattr(norm_coords, other_plane+'_norm')
pw_norm = getattr(norm_coords, 'p'+other_plane+'_norm')
if side == '+':
assert np.all(v >= 0)
else:
assert np.all(v <= 0)

xo.assert_allclose(w_in_sigmas, w_norm, 1e-12)
xo.assert_allclose(pw_in_sigmas, pw_norm, 1e-12)
other_plane = {'x': 'y', 'y': 'x'}[plane]
w_norm = getattr(norm_coords, other_plane+'_norm')
pw_norm = getattr(norm_coords, 'p'+other_plane+'_norm')

assert(np.allclose(zeta, particles.zeta, atol=1e-12))
assert(np.allclose(delta, particles.delta, atol=1e-12))
xo.assert_allclose(w_in_sigmas, w_norm, 1e-12)
xo.assert_allclose(pw_in_sigmas, pw_norm, 1e-12)

xo.assert_allclose(zeta, particles.zeta, atol=1e-12)
xo.assert_allclose(delta, particles.delta, atol=1e-12)
19 changes: 7 additions & 12 deletions tests/test_single_rf_harmonic_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import xobjects as xo

import xpart as xp
from xpart.test_helpers import flaky_assertions, retry
from xobjects.test_helpers import for_all_test_contexts
from xobjects.test_helpers import fix_random_seed


@pytest.mark.parametrize('scenario', ['psb_injection', 'sps_ions', 'lhc_protons'])
@pytest.mark.parametrize('distribution', ['gaussian', 'parabolic'])
@retry(n_times=3)
@fix_random_seed(46398498)
def test_single_rf_harmonic_matcher_rms_and_profile_and_tune(
scenario, distribution):
for ctx in xo.context.get_test_contexts():
Expand Down Expand Up @@ -74,16 +74,11 @@ def test_single_rf_harmonic_matcher_rms_and_profile_and_tune(

twiss_tune = line.twiss()['qs']
theoretical_synchrotron_tune = matcher.get_synchrotron_tune()
print(twiss_tune, theoretical_synchrotron_tune)
print(twiss_tune - theoretical_synchrotron_tune,
(theoretical_synchrotron_tune - twiss_tune)
/(theoretical_synchrotron_tune))

assert np.isclose(theoretical_synchrotron_tune,
twiss_tune, rtol=3.e-3, atol=1.e-15)

with flaky_assertions():
assert np.isclose(rms_bunch_length, np.std(zeta),
rtol=2e-2, atol=1e-15)
assert np.all(np.isclose(hist, tau_distr_y,
atol=3.e-2, rtol=1.e-2))
assert np.isclose(rms_bunch_length, np.std(zeta),
rtol=2e-2, atol=1e-15)

xo.assert_allclose(hist, tau_distr_y, atol=3.e-2, rtol=1.e-2)

0 comments on commit 1da2898

Please sign in to comment.