Skip to content

Commit b2ad970

Browse files
committed
Version 1.0.9.
Bugfix: Use numpy float comparison in transverse_tracking.py and transverse_tracking_cython.pyx to ensure that s[-1] == C. Other float comparisons have been eliminated e.g. in the particles.py and the generators.py modules. However, some are still present in the code (e.g. in wakes.py, tbc).
1 parent cae2153 commit b2ad970

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "1.0.8"
1+
__version__ = "1.0.9"
22

particles/generators.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def __init__(self, macroparticlenumber, intensity, charge, mass,
210210
the correspondingly matched coordinate and its conjugate
211211
momentum.
212212
'''
213-
if alpha != 0:
213+
if not np.allclose(alpha, 0., atol=1e-15):
214214
raise NotImplementedError("alpha != 0 is not yet taken into" +
215215
" account")
216216
coordssig = self.coords_n_momenta_with_sigmas(coords, epsn_geo, beta)
@@ -275,7 +275,7 @@ def __init__(self, macroparticlenumber, intensity, charge, mass,
275275
epsn_geo_y = epsn_y / betagamma
276276
alpha_x, beta_x, alpha_y, beta_y = transverse_map.get_injection_optics()
277277

278-
if alpha_x != 0 or alpha_y != 0:
278+
if not np.allclose([alpha_x, alpha_y], [0., 0.], atol=1e-15):
279279
raise NotImplementedError("alpha != 0 is not yet taken into" +
280280
" account")
281281

particles/particles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, macroparticlenumber, particlenumber_per_mp, charge,
2828
self.particlenumber_per_mp = particlenumber_per_mp
2929

3030
self.charge = charge
31-
if self.charge != e:
31+
if not np.allclose(self.charge, e, atol=1e-24):
3232
raise NotImplementedError('PyHEADTAIL currently features many "e" '
3333
+ 'all over the place, these need to be '
3434
+ 'consistently replaced by '

trackers/transverse_tracking.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def __init__(self,
4747
self.dQ_x = dQ_x
4848
self.dQ_y = dQ_y
4949

50-
if (D_x_s0 != 0 or D_x_s1 != 0 or D_y_s0 != 0 or D_y_s1 != 0):
50+
if not np.allclose([D_x_s0, D_x_s1, D_y_s0, D_y_s1],
51+
[0., 0., 0., 0.], atol=1e-15):
5152
raise NotImplementedError('Non-zero values have been \n' +
5253
'specified for the dispersion coefficients D_{x,y}.\n' +
5354
'But, the effects of dispersion are not yet implemented. \n')
@@ -185,7 +186,7 @@ def __init__(self, C, s, alpha_x, beta_x, D_x, alpha_y, beta_y, D_y,
185186
knows how to generate and store its SegmentDetuner objects
186187
to 'distribute' the detuning proportionally along the
187188
accelerator circumference. """
188-
if s[0] != 0 or s[-1] != C:
189+
if not np.allclose([s[0], s[-1]], [0., C]):
189190
raise ValueError('The first element of s must be zero \n' +
190191
'and the last element must be equal to the \n' +
191192
'accelerator circumference C. \n')

trackers/transverse_tracking_cython.pyx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ class TransverseSegmentMap(object):
8282
self.dQ_x = dQ_x
8383
self.dQ_y = dQ_y
8484

85-
if (D_x_s0 != 0 or D_x_s1 != 0 or D_y_s0 != 0 or D_y_s1 != 0):
85+
if not np.allclose([D_x_s0, D_x_s1, D_y_s0, D_y_s1],
86+
[0., 0., 0., 0.], atol=1e-15):
8687
raise NotImplementedError('Non-zero values have been \n' +
8788
'specified for the dispersion coefficients D_{x,y}.\n' +
8889
'But, the effects of dispersion are not yet implemented. \n')
@@ -323,7 +324,7 @@ class TransverseMap(object):
323324
knows how to generate and store its SegmentDetuner objects
324325
to 'distribute' the detuning proportionally along the
325326
accelerator circumference. """
326-
if s[0] != 0 or s[-1] != C:
327+
if not np.allclose([s[0], s[-1]], [0., C]):
327328
raise ValueError('The first element of s must be zero \n' +
328329
'and the last element must be equal to the \n' +
329330
'accelerator circumference C. \n')

0 commit comments

Comments
 (0)