Package: pyread-swift
An MPI read routine for Swift simulation snapshotspyread_swiftis an MPI read routine forswiftsimsnapshots, very similar in style to John Helly'sread_eaglecode to read EAGLE snapshots.The package can readswiftsimsnapshots both in "collective" (i.e., multiple MPI ranks read from a single file simultaneously) and "distributed" (i.e., each MPI reads an individual snapshot file part in isolation) modes.InstallationRequirementsOpenMPIor other MPI librarypython>=3.8Recommended modules when working on COSMA7:moduleloadgnu_comp/11.1.0openmpi/4.1.4parallel_hdf5/1.12.0python/3.9.1-C7Given the need for a parallel HDF5 installation, it is recommended you installpyread_swiftwithin a virtual/conda environment. However you can ofcourse also install directly into your base Python environment if you prefer.First make sure yourpipis up-to-date:python3-mpipinstall--upgradepipMethod 1) Installation from PyPiThe easiest method is to install fromPyPIpython3-mpipinstallpyread-swiftMethod 2) Installation from sourceOr, you can install directly from source.First clone the repo, then you can install thepyread_swiftpackage by typing the following in
the root git directory:gitclonehttps://github.com/stuartmcalpine/pyread_swift.gitcdpyread_swift
python3-mpipinstall.which will installpyread_swiftand any dependencies.MPI installation for collective readingIf you are usingpyread_swiftto load large snapshots over MPI collectively
(i.e., multiple cores read in parallel from the same file), a bit of additional
setup is required.Make sure you havehdf5installed withparallelcompatibility (see here for details).Then, uninstall any versions ofh5pyand reinstall from source:python3-mpipuninstallh5pyMPICC=mpiccCC=mpiccHDF5_MPI="ON"python3-mpipinstall--no-binary=h5pyh5pyIfpipstruggles to find yourHDF5libraries automatically, e.g.,error: libhdf5.so: cannot open shared object file: No such file or directory. You may have to specify the path to the HDF5 installation manually, i.e.,HDF5_DIR=/path/to/hdf5/lib(seeherefor more details).For our COSMA7 setup, that would be:HDF5_DIR="/cosma/local/parallel-hdf5//gnu_11.1.0_ompi_4.1.4/1.12.0/"Usagepyread_swiftis build around a primary read wrapper, calledSwiftSnapshot. The snapshot particles are loaded into, stored, and manipulated by this object.Reading follows these four steps (see also the examples below):Initialize aSwiftSnapshotobject pointing to the location of the HDF5 file.Select the spatial region you want to extract the particles from using theselect_region()routine.Split the selection over the MPI ranks using thesplit_selection()routine.Read a selected property of the particles using theread_dataset()routine.Input parameters to SwiftSnapshotInputDescriptionDefault optionfnameFull path to HDF5 snapshot file. If the snapshot is split over multiple files, this can just be one of the file parts-comm=MPI4PY communicator (if reading in MPI)Noneverbose=True for more a more verbose outputFalsempi_read_format=How to read the snapshot in MPI mode ("collective" or "distributed")"collective": Do a collective read of each file, i.e., all ranks read a single file at one. Recommended for single, or few large snapshot file(s). Requires parallel-hdf5 to be installed."distributed": Each rank reads its own file part. Recommended for multiple smaller files."collective"max_concur_io=When reading in MPI, how many HDF5 files can be open at once64Example usage (No MPI case)frompyread_swiftimportSwiftSnapshot# Set up pyread_swift object pointing at HDF5 snapshot file (or a file part).snapshot="/path/to/snap/part.0.hdf5"swift=SwiftSnapshot(snapshot)# Select region to load from.parttype=1# Dark matterregion=[0,100,0,100,0,100]# [xlo,xhi,ylo,yhi,zlo,zhi]swift.select_region(parttype,*region)# Divide selection between ranks (needs to be invoked even for non-mpi case).swift.split_selection()# Read data.ids=swift.read_dataset(parttype,"ParticleIDs")Example usage (MPI case)frommpi4pyimportMPIfrompyread_swiftimportSwiftSnapshot# MPI communicator.comm=MPI.COMM_WORLD# Set up read_swift object pointing at HDF5 snapshot file (or a file part).snapshot="/path/to/snap/part.0.hdf5"swift=SwiftSnapshot(snapshot,comm=comm)# Select region to load from.parttype=1# Dark matterregion=[0,100,0,100,0,100]# [xlo,xhi,ylo,yhi,zlo,zhi]swift.select_region(parttype,*region)# Divide selection between ranks.swift.split_selection()# Read data.ids=swift.read_dataset(parttype,"ParticleIDs")