Skip to content

Commit 7dd7fca

Browse files
authored
Determinism in initialize_from_array.py (#1326)
Fix #1325: all random number draws need to be deterministic with a fixed seed to avoid fluctuations in CI. This fixes the transverse components, before only z-pz were deterministic.
1 parent 0ec43db commit 7dd7fca

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

examples/initialize_from_array/run_from_array.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
sigr = 500e-6
2020
sigpx = 10
2121
sigpy = 10
22-
px = np.random.normal(0, sigpx, N_part)
23-
py = np.random.normal(0, sigpy, N_part)
24-
theta = 2 * np.pi * np.random.rand(N_part)
25-
r = abs(np.random.normal(beam_radius, sigr, N_part))
22+
# fixed seed for deterministic test results
23+
rng = np.random.default_rng()
24+
px = rng.normal(0, sigpx, N_part)
25+
py = rng.normal(0, sigpy, N_part)
26+
theta = 2 * np.pi * rng.random(N_part)
27+
r = np.abs(rng.normal(beam_radius, sigr, N_part))
2628
x = r * np.cos(theta)
2729
y = r * np.sin(theta)
2830
z_mean = 0
@@ -31,7 +33,7 @@
3133
pz_std = 2e2
3234
zpz_std = -0.18
3335
zpz_cov_list = [[z_std**2, zpz_std], [zpz_std, pz_std**2]]
34-
z, pz = np.random.default_rng().multivariate_normal([0, 0], zpz_cov_list, N_part).T
36+
z, pz = rng.multivariate_normal([0, 0], zpz_cov_list, N_part).T
3537
pz += pz_mean
3638

3739
sim = ImpactX()

0 commit comments

Comments
 (0)