Skip to content

Commit b783aa1

Browse files
committed
aperture: fixing bug with aperture on GPU...
... when running the slice monitor on the GPU, the aperture would shorten the arrays (via beam.x = beam.x[:n_alive]) in case of lost particles (n_alive > 0) in a way which is incompatible with storing the slice statistics. This only occurs on the GPU (where beam.x would be a GPUArray, while n_alive has been transformed into a numpy.array because pm.sum contains a .get() for summing on the GPU). The fix is to make n_alive a simple integer instead of a numpy.array... The usual error message in python2 when only using pm.sum for n_alive: TypeError: slice indices must be integers or None or have an __index__ method (therefore wrapping it with a np.int32) Thanks Eirini for spotting this.
1 parent bfb793e commit b783aa1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

PyHEADTAIL/aperture/aperture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import numpy as np
2020

2121
def make_int32(array):
22-
# return np.array(array, dtype=np.int32)
2322
return array.astype(np.int32)
2423

2524

@@ -89,8 +88,9 @@ def relocate_lost_particles(beam, alive):
8988

9089
beam.reorder(perm)
9190

92-
n_alive = make_int32(pm.sum(alive))
93-
return n_alive
91+
# on CPU: (even if pm.device == 'GPU', as pm.sum returns np.ndarray)
92+
n_alive = pm.sum(alive)
93+
return np.int32(n_alive)
9494

9595

9696
class RectangularApertureX(Aperture):

0 commit comments

Comments
 (0)