Skip to content

Commit ee00764

Browse files
Copy particle to cpu before asserting in tests. Remove redundant checks.
1 parent ef4518c commit ee00764

File tree

4 files changed

+248
-254
lines changed

4 files changed

+248
-254
lines changed

tests/test_build_particles_binomial.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,40 @@
1818

1919
@for_all_test_contexts
2020
def test_build_particles_binomial(test_context):
21-
for ctx_ref in [test_context, None]:
22-
# Build a reference particle
23-
p0 = xp.Particles(mass0=xp.PROTON_MASS_EV, q0=1, p0c=7e12, x=1, y=3,
24-
delta=[10], _context=ctx_ref)
21+
# Build a reference particle
22+
p0 = xp.Particles(mass0=xp.PROTON_MASS_EV, q0=1, p0c=7e12, x=1, y=3,
23+
delta=[10], _context=test_context)
2524

2625
# Parameters for the test
27-
num_part = 1000000
28-
29-
# Load machine model (from pymask)
30-
filename = xt._pkg_root.parent.joinpath('test_data/lhc_no_bb/line_and_particle.json')
31-
with open(filename, 'r') as fid:
32-
input_data = json.load(fid)
33-
line = xt.Line.from_dict(input_data['line'])
34-
line.build_tracker(_context=test_context)
26+
num_part = 1000000
27+
28+
# Load machine model (from pymask)
29+
filename = xt._pkg_root.parent.joinpath('test_data/lhc_no_bb/line_and_particle.json')
30+
with open(filename, 'r') as fid:
31+
input_data = json.load(fid)
32+
line = xt.Line.from_dict(input_data['line'])
33+
line.build_tracker(_context=test_context)
3534

3635
# Built a set of three particles with different x coordinates
37-
zeta, delta, matcher = generate_binomial_longitudinal_coordinates(num_particles=num_part,
38-
nemitt_x=3e-6,
39-
nemitt_y=3e-6,
40-
sigma_z=0.05,
41-
particle_ref=p0,
42-
line=line,
43-
return_matcher=True
44-
)
36+
zeta, delta, matcher = generate_binomial_longitudinal_coordinates(num_particles=num_part,
37+
nemitt_x=3e-6,
38+
nemitt_y=3e-6,
39+
sigma_z=0.05,
40+
particle_ref=p0,
41+
line=line,
42+
return_matcher=True
43+
)
4544

4645
# Test if longitudinal coordinates match with Single
4746
# Generate distribution from RF matcher
48-
tau = zeta / p0.beta0[0]
49-
tau_distr_y = matcher.tau_distr_y
50-
tau_distr_x = matcher.tau_distr_x
51-
dx = tau_distr_x[1] - tau_distr_x[0]
52-
hist, edges = np.histogram(tau,
53-
range=(tau_distr_x[0]-dx/2., tau_distr_x[-1]+dx/2.),
54-
bins=len(tau_distr_x))
55-
hist = hist / sum(hist) * sum(tau_distr_y)
56-
57-
assert np.all(np.isclose(hist, tau_distr_y, atol=5.e-2, rtol=1.e-2))
47+
p0.move(_context=xo.ContextCpu())
48+
tau = zeta / p0.beta0[0]
49+
tau_distr_y = matcher.tau_distr_y
50+
tau_distr_x = matcher.tau_distr_x
51+
dx = tau_distr_x[1] - tau_distr_x[0]
52+
hist, edges = np.histogram(tau,
53+
range=(tau_distr_x[0]-dx/2., tau_distr_x[-1]+dx/2.),
54+
bins=len(tau_distr_x))
55+
hist = hist / sum(hist) * sum(tau_distr_y)
56+
57+
assert np.all(np.isclose(hist, tau_distr_y, atol=5.e-2, rtol=1.e-2))

0 commit comments

Comments
 (0)