openPMD is an open meta-data schema that provides meaning and self-description for data sets in science and engineering. See the openPMD standard for details of this schema.
This library provides a reference API for openPMD data handling. Since openPMD is a schema (or markup) on top of portable, hierarchical file formats, this library implements various backends such as HDF5, ADIOS2 and JSON. Writing & reading through those backends and their associated files are supported for serial and MPI-parallel workflows.
#include <openPMD/openPMD.hpp>
#include <iostream>
// ...
auto s = openPMD::Series("samples/git-sample/data%T.h5", openPMD::Access::READ_ONLY);
for( auto const & [step, it] : s.iterations ) {
std::cout << "Iteration: " << step << "\n";
for( auto const & [name, mesh] : it.meshes ) {
std::cout << " Mesh '" << name << "' attributes:\n";
for( auto const& val : mesh.attributes() )
std::cout << " " << val << '\n';
}
for( auto const & [name, species] : it.particles ) {
std::cout << " Particle species '" << name << "' attributes:\n";
for( auto const& val : species.attributes() )
std::cout << " " << val << '\n';
}
}
import openpmd_api as io
# ...
series = io.Series("samples/git-sample/data%T.h5", io.Access.read_only)
for k_i, i in series.iterations.items():
print("Iteration: {0}".format(k_i))
for k_m, m in i.meshes.items():
print(" Mesh '{0}' attributes:".format(k_m))
for a in m.attributes:
print(" {0}".format(a))
for k_p, p in i.particles.items():
print(" Particle species '{0}' attributes:".format(k_p))
for a in p.attributes:
print(" {0}".format(a))
Curious? Our manual shows full read & write examples, both serial and MPI-parallel!
Required:
- CMake 3.15.0+
- C++17 capable compiler, e.g., g++ 7+, clang 7+, MSVC 19.15+, icpc 19+, icpx
Shipped internally in share/openPMD/thirdParty/
:
I/O backends:
while those can be built either with or without:
- MPI 2.1+, e.g. OpenMPI 1.6.5+ or MPICH2
Optional language bindings:
- Python:
- Python 3.8 - 3.12
- pybind11 2.12.0+
- numpy 1.15+
- mpi4py 2.1+ (optional, for MPI)
- pandas 1.0+ (optional, for dataframes)
- dask 2021+ (optional, for dask dataframes)
- CUDA C++ (optional, currently used only in tests)
Our community loves to help each other. Please report installation problems in case you should get stuck.
Choose one of the install methods below to get started:
# optional: +python -adios2 -hdf5 -mpi
spack install openpmd-api
spack load openpmd-api
# optional: OpenMPI support =*=mpi_openmpi*
# optional: MPICH support =*=mpi_mpich*
conda create -n openpmd -c conda-forge openpmd-api
conda activate openpmd
brew tap openpmd/openpmd
brew install openpmd-api
On very old macOS versions (<10.9) or on exotic processor architectures, this install method compiles from source against the found installations of HDF5, ADIOS2, and/or MPI (in system paths, from other package managers, or loaded via a module system, ...).
# we need pip 19 or newer
# optional: --user
python3 -m pip install -U pip
# optional: --user
python3 -m pip install openpmd-api
If MPI-support shall be enabled, we always have to recompile:
# optional: --user
python3 -m pip install -U pip packaging setuptools wheel
python3 -m pip install -U cmake
# optional: --user
openPMD_USE_MPI=ON python3 -m pip install openpmd-api --no-binary openpmd-api
For some exotic architectures and compilers, you might need to disable a compiler feature called link-time/interprocedural optimization if you encounter linking problems:
export CMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF
# optional: --user
python3 -m pip install openpmd-api --no-binary openpmd-api
Additional CMake options can be passed via individual environment variables, which need to be prefixed with openPMD_CMAKE_
.
openPMD-api can also be built and installed from source using CMake:
git clone https://github.com/openPMD/openPMD-api.git
mkdir openPMD-api-build
cd openPMD-api-build
# optional: for full tests, with unzip
../openPMD-api/share/openPMD/download_samples.sh
# for own install prefix append:
# -DCMAKE_INSTALL_PREFIX=$HOME/somepath
# for options append:
# -DopenPMD_USE_...=...
# e.g. for python support add:
# -DopenPMD_USE_PYTHON=ON -DPython_EXECUTABLE=$(which python3)
cmake ../openPMD-api
cmake --build .
# optional
ctest
# sudo might be required for system paths
cmake --build . --target install
The following options can be added to the cmake
call to control features.
CMake controls options with prefixed -D
, e.g. -DopenPMD_USE_MPI=OFF
:
CMake Option | Values | Description |
---|---|---|
openPMD_USE_MPI |
AUTO/ON/OFF | Parallel, Multi-Node I/O for clusters |
openPMD_USE_HDF5 |
AUTO/ON/OFF | HDF5 backend (.h5 files) |
openPMD_USE_ADIOS2 |
AUTO/ON/OFF | ADIOS2 backend (.bp files in BP3, BP4 or higher) |
openPMD_USE_PYTHON |
AUTO/ON/OFF | Enable Python bindings |
openPMD_USE_INVASIVE_TESTS |
ON/OFF | Enable unit tests that modify source code 1 |
openPMD_USE_VERIFY |
ON/OFF | Enable internal VERIFY (assert) macro independent of build type 2 |
openPMD_INSTALL |
ON/OFF | Add installation targets |
openPMD_INSTALL_RPATH |
ON/OFF | Add RPATHs to installed binaries |
Python_EXECUTABLE |
(newest found) | Path to Python executable |
1 e.g. changes C++ visibility keywords, breaks MSVC 2 this includes most pre-/post-condition checks, disabling without specific cause is highly discouraged
Additionally, the following libraries are shipped internally. The following options allow to switch to external installs:
CMake Option | Values | Library | Version |
---|---|---|---|
openPMD_USE_INTERNAL_CATCH |
ON/OFF | Catch2 | 2.13.10+ |
openPMD_USE_INTERNAL_PYBIND11 |
ON/OFF | pybind11 | 2.12.0+ |
openPMD_USE_INTERNAL_JSON |
ON/OFF | NLohmann-JSON | 3.9.1+ |
openPMD_USE_INTERNAL_TOML11 |
ON/OFF | toml11 | 3.7.1+ |
By default, this will build as a shared library (libopenPMD.[so|dylib|dll]
) and installs also its headers.
In order to build a static library, append -DBUILD_SHARED_LIBS=OFF
to the cmake
command.
You can only build a static or a shared library at a time.
By default, the Release
version is built.
In order to build with debug symbols, pass -DCMAKE_BUILD_TYPE=Debug
to your cmake
command.
By default, tests, examples and command line tools are built.
In order to skip building those, pass OFF
to these cmake
options:
CMake Option | Values | Description |
---|---|---|
openPMD_BUILD_TESTING |
ON/OFF | Build tests |
openPMD_BUILD_EXAMPLES |
ON/OFF | Build examples |
openPMD_BUILD_CLI_TOOLS |
ON/OFF | Build command-line tools |
openPMD_USE_CUDA_EXAMPLES |
ON/OFF | Use CUDA in examples |
The install will contain header files and libraries in the path set with -DCMAKE_INSTALL_PREFIX
.
If your project is using CMake for its build, one can conveniently use our provided openPMDConfig.cmake
package, which is installed alongside the library.
First set the following environment hint if openPMD-api was not installed in a system path:
# optional: only needed if installed outside of system paths
export CMAKE_PREFIX_PATH=$HOME/somepath:$CMAKE_PREFIX_PATH
Use the following lines in your project's CMakeLists.txt
:
# supports: COMPONENTS MPI NOMPI HDF5 ADIOS2
find_package(openPMD 0.15.0 CONFIG)
if(openPMD_FOUND)
target_link_libraries(YourTarget PRIVATE openPMD::openPMD)
endif()
Alternatively, add the openPMD-api repository source directly to your project and use it via:
add_subdirectory("path/to/source/of/openPMD-api")
target_link_libraries(YourTarget PRIVATE openPMD::openPMD)
For development workflows, you can even automatically download and build openPMD-api from within a depending CMake project.
Just replace the add_subdirectory
call with:
include(FetchContent)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(openPMD_BUILD_CLI_TOOLS OFF)
set(openPMD_BUILD_EXAMPLES OFF)
set(openPMD_BUILD_TESTING OFF)
set(openPMD_BUILD_SHARED_LIBS OFF) # precedence over BUILD_SHARED_LIBS if needed
set(openPMD_INSTALL OFF) # or instead use:
# set(openPMD_INSTALL ${BUILD_SHARED_LIBS}) # only install if used as a shared library
set(openPMD_USE_PYTHON OFF)
FetchContent_Declare(openPMD
GIT_REPOSITORY "https://github.com/openPMD/openPMD-api.git"
GIT_TAG "0.15.0")
FetchContent_MakeAvailable(openPMD)
If your (Linux/OSX) project is build by calling the compiler directly or uses a manually written Makefile
, consider using our openPMD.pc
helper file for pkg-config
, which are installed alongside the library.
First set the following environment hint if openPMD-api was not installed in a system path:
# optional: only needed if installed outside of system paths
export PKG_CONFIG_PATH=$HOME/somepath/lib/pkgconfig:$PKG_CONFIG_PATH
Additional linker and compiler flags for your project are available via:
# switch to check if openPMD-api was build as static library
# (via BUILD_SHARED_LIBS=OFF) or as shared library (default)
if [ "$(pkg-config --variable=static openPMD)" == "true" ]
then
pkg-config --libs --static openPMD
# -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lopenPMD -pthread /usr/lib/libmpi.so -pthread /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/libmpi.so /usr/lib/x86_64-linux-gnu/hdf5/openmpi/libhdf5.so /usr/lib/x86_64-linux-gnu/libsz.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libdl.so /usr/lib/x86_64-linux-gnu/libm.so -pthread /usr/lib/libmpi.so -pthread /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/libmpi.so
else
pkg-config --libs openPMD
# -L${HOME}/somepath/lib -lopenPMD
fi
pkg-config --cflags openPMD
# -I${HOME}/somepath/include
openPMD-api is developed by many people. It was initially started by the Computational Radiation Physics Group at HZDR as successor to libSplash, generalizing the successful HDF5 & ADIOS1 implementations in PIConGPU. The following people and institutions contributed to openPMD-api:
- Axel Huebl (LBNL, previously HZDR): project lead, releases, documentation, automated CI/CD, Python bindings, Dask, installation & packaging, prior reference implementations
- Franz Poeschel (CASUS): JSON & ADIOS2 backend, data staging/streaming, reworked class design
- Fabian Koller (HZDR): initial library design and implementation with HDF5 & ADIOS1 backend
- Junmin Gu (LBNL): non-collective parallel I/O fixes, ADIOS improvements, benchmarks
Maintained by the following research groups:
- Computational Radiation Physics (CRD) at CASUS/HZDR, led by Michael Bussmann
- Accelerator Modeling Program (AMP) at LBNL, led by Jean-Luc Vay
- Scientific Data Management (SDM) at LBNL, led by Kesheng (John) Wu
Further thanks go to improvements and contributions from:
- Carsten Fortmann-Grote (EU XFEL GmbH, now MPI-EvolBio): draft of our Python unit tests
- Dominik Stańczak (Warsaw University of Technology): documentation improvements
- Ray Donnelly (Anaconda, Inc.): support on conda packaging and libc++ quirks
- James Amundson (FNAL): compile fix for newer compilers
- René Widera (HZDR): design improvements for initial API design
- Erik Zenker (HZDR): design improvements for initial API design
- Sergei Bastrakov (HZDR): documentation improvements (windows)
- Rémi Lehe (LBNL): package integration testing on macOS and Linux
- Lígia Diana Amorim (LBNL): package integration testing on macOS
- Kseniia Bastrakova (HZDR): compatibility testing
- Richard Pausch (HZDR): compatibility testing, documentation improvements
- Paweł Ordyna (HZDR): report on NVCC warnings
- Dmitry Ganyushin (ORNL): Dask prototyping & ADIOS2 benchmarking
- John Kirkham (NVIDIA): Dask guidance & reviews
- Erik Schnetter (PITP): C++ API bug fixes
- Jean Luca Bez (LBNL): HDF5 performance tuning
- Bernhard Manfred Gruber (CERN): CMake fix for parallel HDF5
- Nils Schild (IPP): CMake improvements for subprojects
The openPMD-api authors acknowledge support via the following programs. Supported by the CAMPA collaboration, a project of the U.S. Department of Energy, Office of Science, Office of Advanced Scientific Computing Research and Office of High Energy Physics, Scientific Discovery through Advanced Computing (SciDAC) program. Previously supported by the Consortium for Advanced Modeling of Particles Accelerators (CAMPA), funded by the U.S. DOE Office of Science under Contract No. DE-AC02-05CH11231. Supported by the Exascale Computing Project (17-SC-20-SC), a collaborative effort of two U.S. Department of Energy organizations (Office of Science and the National Nuclear Security Administration). This project has received funding from the European Unions Horizon 2020 research and innovation programme under grant agreement No 654220. This work was partially funded by the Center of Advanced Systems Understanding (CASUS), which is financed by Germany's Federal Ministry of Education and Research (BMBF) and by the Saxon Ministry for Science, Culture and Tourism (SMWK) with tax funds on the basis of the budget approved by the Saxon State Parliament. Supported by the HElmholtz Laser Plasma Metadata Initiative (HELPMI) project (ZT-I-PF-3-066), funded by the "Initiative and Networking Fund" of the Helmholtz Association in the framework of the "Helmholtz Metadata Collaboration" project call 2022.
openPMD-api stands on the shoulders of giants and we are grateful for the following projects included as direct dependencies:
- ADIOS2 by S. Klasky, N. Podhorszki, W.F. Godoy (ORNL), team, collaborators and contributors
- Catch2 by Phil Nash, Martin Hořeňovský and contributors
- HDF5 by the HDF group and community
- json by Niels Lohmann and contributors
- toml11 by Toru Niina and contributors
- pybind11 by Wenzel Jakob (EPFL) and contributors
- all contributors to the evolution of modern C++ and early library preview developers, e.g. Michael Park (Facebook)
- the CMake build system and contributors
- packaging support by the conda-forge, PyPI and Spack communities, among others
- the openPMD-standard by Axel Huebl (HZDR, now LBNL) and contributors