Skip to content
Snippets Groups Projects

Adds Beam.init_bunch_list_mpi

Merged Alexis GAMELIN requested to merge feature-beam_bunch_list_init_mpi into develop
2 unresolved threads

MR to answer to #10 (closed)

Previously, to initialize a beam with a bunch list and mpi, it was needed to do (some expert know-how needed):

ring = demo()

filling_pattern = np.zeros((ring.h, 1), dtype=bool)

filling_pattern[0] = True
filling_pattern[2] = True
filling_pattern[10] = True
filling_pattern[11] = True

bunch_list = [Bunch(ring, mp_number=1, alive=filling_pattern[i]) for i in range(ring.h)]

# for i in range(size):
#     bunch_list[i] = Bunch(ring, mp_number=1)

idx_non_empty = np.where(filling_pattern)[0]

mybunch = Bunch(ring, mp_number=1e3, current=(rank+1)*1e-3)
mybunch.init_gaussian()

bunch_list[idx_non_empty[rank]] = mybunch

beam = Beam(ring, bunch_list=bunch_list)
beam.mpi_init()

New it's simpler with the new method:

ring = demo()

filling_pattern = np.zeros((ring.h, 1), dtype=bool)

filling_pattern[0] = True
filling_pattern[2] = True
filling_pattern[10] = True
filling_pattern[11] = True

mybunch = Bunch(ring, mp_number=1e3, current=(rank+1)*1e-3)
mybunch.init_gaussian()

beam = Beam(ring)
beam.init_bunch_list_mpi(mybunch, filling_pattern)

Contents:

  • Beam.update_filling_pattern and Beam.update_distance_between_bunches are now called directly in the init when a bunch_list is given.
  • Beam.init_bunch_list_mpi is a convenience method to initialize a beam using MPI parallelisation with a Bunch per core.
  • Add tests for Beam.init_bunch_list_mpi

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
875 Parameters
876 ----------
877 bunch : Bunch object
878 The bunch given should probably depend on the mpi.rank so that each
879 core can track a different bunch.
880 Example: beam.init_bunch_list_mpi(bunch_list[comm.rank], filling_pattern)
881 filling_pattern : array-like of bool of length ring.h
882 Filling pattern of the beam as a list or an array of bool.
883
884 """
885 filling_pattern = np.array(filling_pattern)
886
887 if len(filling_pattern) != self.ring.h:
888 raise ValueError(("The length of filling pattern is {} ".format(
889 len(filling_pattern)) +
890 "but should be {}".format(self.ring.h)))
  • Comment on lines +888 to +890
    Suggested change
    888 raise ValueError(("The length of filling pattern is {} ".format(
    889 len(filling_pattern)) +
    890 "but should be {}".format(self.ring.h)))
    888 raise ValueError(f"The length of filling pattern is {len(filling_pattern)} but should be {self.ring.h}")
  • Please register or sign in to reply
  • 879 core can track a different bunch.
    880 Example: beam.init_bunch_list_mpi(bunch_list[comm.rank], filling_pattern)
    881 filling_pattern : array-like of bool of length ring.h
    882 Filling pattern of the beam as a list or an array of bool.
    883
    884 """
    885 filling_pattern = np.array(filling_pattern)
    886
    887 if len(filling_pattern) != self.ring.h:
    888 raise ValueError(("The length of filling pattern is {} ".format(
    889 len(filling_pattern)) +
    890 "but should be {}".format(self.ring.h)))
    891
    892 if filling_pattern.dtype != np.dtype("bool"):
    893 raise TypeError("dtype {} should be bool.".format(
    894 filling_pattern.dtype))
    • Comment on lines +893 to +894
      Suggested change
      893 raise TypeError("dtype {} should be bool.".format(
      894 filling_pattern.dtype))
      893 raise TypeError(f"dtype {filling_pattern.dtype} should be bool.")
    • Please register or sign in to reply
  • Looks fine. I've suggested some f-string usage to shorten the code a bit.

  • GUBAIDULIN approved this merge request

    approved this merge request

  • Alexis GAMELIN mentioned in commit a32e6f1f

    mentioned in commit a32e6f1f

  • Please register or sign in to reply
    Loading