Package to read SWIFT simulation snapshots in MPI.
Project description
An MPI read routine for Swift simulation snapshots
pyread_swift is an MPI read routine for swiftsim snapshots, very similar in style to John Helly's read_eagle code to read EAGLE snapshots.
The package can read swiftsim snapshots 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.
Installation
Requirements
OpenMPIor other MPI librarypython>=3.10virgodc
Recommended modules when working on COSMA7:
module load gnu_comp/14.1.0 openmpi/5.0.3 parallel_hdf5/1.14.4 fftw/3.3.10
module load python/3.12.4
Given the need for a parallel HDF5 installation, it is recommended you install pyread_swift within a virtual/conda environment. However you can ofcourse also install directly into your base Python environment if you prefer.
First make sure your pip is up-to-date:
python3 -m pip install --upgrade pip
Method 1) Installation from PyPi
The easiest method is to install from PyPI
python3 -m pip install pyread-swift
Method 2) Installation from source
Or, you can install directly from source.
First clone the repo, then you can install the pyread_swift package by typing the following in
the root git directory:
git clone https://github.com/stuartmcalpine/pyread_swift.git
cd pyread_swift
python3 -m pip install .
which will install pyread_swift and any dependencies.
MPI installation for collective reading
If you are using pyread_swift to 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 have hdf5 installed with parallel compatibility (see here for details).
Then, uninstall any versions of h5py and reinstall from source:
python3 -m pip uninstall h5py
MPICC=mpicc CC=mpicc HDF5_MPI="ON" python3 -m pip install --no-binary=h5py h5py
If pip struggles to find your HDF5 libraries 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 (see here for more details).
For our COSMA7 setup, that would be:
HDF5_DIR="/cosma/local/parallel-hdf5//gnu_14.1.0_ompi_5.0.3/1.14.4/"
Usage
pyread_swift is build around a primary read wrapper, called SwiftSnapshot. The snapshot particles are loaded into, stored, and manipulated by this object.
Reading follows these four steps (see also the examples below):
-
Initialize a
SwiftSnapshotobject pointing to the location of the HDF5 file. -
Select the spatial region you want to extract the particles from using the
select_region()routine. -
Split the selection over the MPI ranks using the
split_selection()routine. -
Read a selected property of the particles using the
read_dataset()routine.
Input parameters to SwiftSnapshot
| Input | Description | Default option |
|---|---|---|
| fname | Full 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) | None |
| verbose= | True for more a more verbose output | False |
| mpi_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 once | 64 |
Example usage (No MPI case)
from pyread_swift import SwiftSnapshot
# 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 matter
region = [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)
from mpi4py import MPI
from pyread_swift import SwiftSnapshot
# 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 matter
region = [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")
Combining snapshot parts
pyread_swift provides a CLI tool to combine multiple snapshot file parts into a single file (designed for DMO simulations):
mpirun -np 4 pyread_swift combine /path/to/snapshot_0000 /path/to/combined_snapshot.hdf5
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyread_swift-1.2.1.tar.gz.
File metadata
- Download URL: pyread_swift-1.2.1.tar.gz
- Upload date:
- Size: 30.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5f8309ac0d3bd3358c345aa1ed3b3d0c7cda57a6af760ebd59cd3dd03e4fc9b
|
|
| MD5 |
0e2048da17bd5481a0793e2c1d9cde6f
|
|
| BLAKE2b-256 |
180a83fd478c9eab2f2b054e5de18abeff47d8e6cf7f74da1bac2d8b802cfe68
|
Provenance
The following attestation bundles were made for pyread_swift-1.2.1.tar.gz:
Publisher:
publish.yml on stuartmcalpine/pyread_swift
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyread_swift-1.2.1.tar.gz -
Subject digest:
d5f8309ac0d3bd3358c345aa1ed3b3d0c7cda57a6af760ebd59cd3dd03e4fc9b - Sigstore transparency entry: 941682301
- Sigstore integration time:
-
Permalink:
stuartmcalpine/pyread_swift@750c29e766381d9cdfa43a9293ffd25fd6f5fef9 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/stuartmcalpine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@750c29e766381d9cdfa43a9293ffd25fd6f5fef9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pyread_swift-1.2.1-py3-none-any.whl.
File metadata
- Download URL: pyread_swift-1.2.1-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0ffec4f566be22b29c5c9d7cb897ae2b2f823accf9f7052ac5b3264ff4e761e
|
|
| MD5 |
0ecbab007ed1ead2133c4a37a5c9b846
|
|
| BLAKE2b-256 |
57c3cfb121132eedbd5d6f5fe2e192de57d190cbd1d22a3c62d54e75b06be1cc
|
Provenance
The following attestation bundles were made for pyread_swift-1.2.1-py3-none-any.whl:
Publisher:
publish.yml on stuartmcalpine/pyread_swift
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyread_swift-1.2.1-py3-none-any.whl -
Subject digest:
b0ffec4f566be22b29c5c9d7cb897ae2b2f823accf9f7052ac5b3264ff4e761e - Sigstore transparency entry: 941682327
- Sigstore integration time:
-
Permalink:
stuartmcalpine/pyread_swift@750c29e766381d9cdfa43a9293ffd25fd6f5fef9 -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/stuartmcalpine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@750c29e766381d9cdfa43a9293ffd25fd6f5fef9 -
Trigger Event:
release
-
Statement type: