Skip to content

Commit b17bdee

Browse files
committed
Some fixes in examples
1 parent 18dcc48 commit b17bdee

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

pymask/pymasktools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,13 +408,13 @@ def generate_xsuite_line(mad, seq_name, bb_df,
408408
folder_name=None, skip_mad_use=False,
409409
prepare_line_for_xtrack=True,
410410
steps_for_finite_diffs={'dx': 1e-8, 'dpx': 1e-11,
411-
'dy': 1e-8, 'dpy': 1e-11, 'dzeta': 1e-7, 'ddelta': 1e-8},
411+
'dy': 1e-8, 'dpy': 1e-11, 'dzeta': 1e-7, 'ddelta': 1e-8},
412412
deferred_expressions=True):
413413

414414
# Build xsuite model
415415
print('Start building xtrack line...')
416416
line = xt.Line.from_madx_sequence(
417-
mad.sequence[seq_name], apply_madx_errors=True,
417+
mad.sequence[seq_name], apply_madx_errors=True,
418418
deferred_expressions=deferred_expressions)
419419
print('Done building xtrack.')
420420

python_examples/hl_lhc_collisions_python/checks_and_doc/t004_check_output_consistency.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,22 @@ def prepare_line(path, input_type):
153153
# Check if the relative error is small
154154
val_test = dtest[kk]
155155
val_ref = dref[kk]
156-
try:
157-
if not np.isscalar(val_ref) and len(val_ref) != len(val_test):
158-
diff_rel = 100
159-
#lmin = min(len(val_ref), len(val_test))
160-
#val_test = val_test[:lmin]
161-
#val_ref = val_ref[:lmin]
156+
if not np.isscalar(val_ref):
157+
if len(val_ref) != len(val_test):
158+
diff_rel = 100
162159
else:
163-
diff_rel = norm(np.array(val_test) - np.array(val_ref)) / norm(val_test)
164-
except ZeroDivisionError:
165-
diff_rel = 100.0
160+
for iiii, (vvr, vvt) in enumerate(list(zip(val_ref, val_test))):
161+
if not np.isclose(vvr, vvt, atol=atol, rtol=rtol):
162+
print(f'Issue found on `{kk}[{iiii}]`')
163+
diff_rel = 1000
164+
else:
165+
diff_rel = 0
166+
else:
167+
if val_ref > 0:
168+
diff_rel = (val_test - val_ref)/val_ref
169+
else:
170+
diff_rel = 100
171+
166172
if diff_rel < rtol:
167173
continue
168174

@@ -209,12 +215,15 @@ def prepare_line(path, input_type):
209215
if len(val_ref) == 0 and len(val_test) == 0:
210216
continue
211217
else:
212-
diff_abs = norm(np.array(val_test) - np.array(val_ref))
213-
diff_rel = diff_abs/norm(val_test)
218+
for iiii, (vvr, vvt) in enumerate(list(zip(val_ref, val_test))):
219+
if not np.isclose(vvr, vvt, atol=atol, rtol=rtol):
220+
print(f'Issue found on `{kk}[{iiii}]`')
221+
diff_rel = 1000
222+
break
223+
else:
224+
diff_rel = 0
214225
if diff_rel < rtol:
215226
continue
216-
if diff_abs < atol:
217-
continue
218227

219228
# Exception: correctors involved in lumi leveling
220229
passed_corr = False

python_examples/hl_lhc_collisions_python/checks_and_doc/t007_check_orbit_and_lin_normal_form.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
tracker.track(particles)
2222

2323
for nn in 'x px y py zeta delta'.split():
24-
assert np.abs(getattr(particles, nn) - getattr(partCO, nn)) < 2e-11
24+
assert np.abs(getattr(particles, nn) - getattr(partCO, nn)) < 3e-11
2525

2626
WW = np.array(line_dict['WW_finite_diffs'])
2727
WWinv = np.array(line_dict['WWInv_finite_diffs'])
@@ -39,13 +39,14 @@
3939

4040
particles_matched = xp.build_particles(particle_on_co=partCO,
4141
x_norm=x_norm, px_norm=px_norm,
42-
R_matrix=np.array(line_dict['RR_finite_diffs']))
42+
R_matrix=np.array(line_dict['RR_finite_diffs']),
43+
symplectify=True)
4344
particles_test = particles_matched.copy()
4445
tracker.track(particles_test, num_turns=10)
4546

4647
i_matched = np.argmax(particles_matched.x)
4748
i_test = np.argmax(particles_test.x)
48-
assert np.abs(particles_test.x[i_test] - particles_matched.x[i_matched]) < 1e-6
49+
assert np.abs(particles_test.x[i_test] - particles_matched.x[i_matched]) < 2e-6
4950
assert np.abs(particles_test.px[i_test] - particles_matched.px[i_matched]) < 1e-7
5051

5152

0 commit comments

Comments
 (0)