Skip to main content

C++ & Python API for Scientific I/O with openPMD

Project description

C++ & Python API for Scientific I/O with openPMD

Supported openPMD Standard Documentation Status Doxygen Gitter chat Supported Platforms License DOI
CodeFactor LGTM: C/C++ LGTM: Python LGTM: Total alerts Coverage Status
Linux/OSX Build Status dev Windows Build Status dev Nightly Packages Status Coverity Scan Build Status

This library provides a high-level API for writing and reading scientific data according to openPMD. It allows one to build logical file structures which drive scientific I/O libraries such as HDF5 and ADIOS through a common, intuitive interface. Where supported, openPMD-api implements both serial and MPI parallel I/O capabilities.

Usage

C++

C++11 C++11 API: Alpha

#include <openPMD/openPMD.hpp>
#include <iostream>

// ...

auto s = openPMD::Series("samples/git-sample/data%T.h5", openPMD::AccessType::READ_ONLY);

for( auto const& i : s.iterations ) {
    std::cout << "Iteration: " << i.first << "\n";

    for( auto const& m : i.second.meshes ) {
        std::cout << "  Mesh '" << m.first << "' attributes:\n";
        for( auto const& val : m.second.attributes() )
            std::cout << "    " << val << '\n';
    }

    for( auto const& p : i.second.particles ) {
        std::cout << "  Particle species '" << p.first << "' attributes:\n";
        for( auto const& val : p.second.attributes() )
            std::cout << "    " << val << '\n';
    }
}

Python

Python3 Python3 API: Alpha

import openpmd_api

# ...

series = openpmd_api.Series("samples/git-sample/data%T.h5", openPMD.Access_Type.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))

More!

Curious? Our manual shows full read & write examples, both serial and MPI-parallel!

Dependencies

Required:

  • CMake 3.11.0+
  • C++11 capable compiler, e.g. g++ 4.8+, clang 3.9+, VS 2015+

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.5 - 3.8
    • pybind 2.3.0+
    • numpy 1.15+
    • mpi4py 2.1+

Installation

Spack Package Conda Package PyPI Package From Source

Choose one of the install methods below to get started:

Spack

Spack Version Spack Status

# optional:               +python +adios1 -adios2 -hdf5 -mpi
spack install openpmd-api
spack load -r openpmd-api

Conda

Conda Version Conda Status Conda Downloads

# optional:            OpenMPI support  =*=mpi_openmpi*
# optional:              MPICH support  =*=mpi_mpich*
conda install -c conda-forge openpmd-api

PyPI

PyPI Version PyPI Format PyPI Status PyPI Downloads

Behind the scenes, this install method compiles from source against the found installations of HDF5, ADIOS1, ADIOS2, and/or MPI (in system paths, from other package managers, or loaded via a module system, ...). The current status for this install method is experimental. Please feel free to report how this works for you.

# we need pip 19 or newer
# optional:                   --user
python3 -m pip install -U pip

# optional:                        --user
python3 -m pip install openpmd-api

or with MPI support:

# optional:                                    --user
python3 -m pip install -U pip setuptools wheel
python3 -m pip install -U cmake

# optional:                                                                   --user
openPMD_USE_MPI=ON python3 -m pip install openpmd-api --no-binary openpmd-api

From Source

Source Status

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/.travis/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_ADIOS1 AUTO/ON/OFF ADIOS1 backend (.bp files up to version BP3)
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
PYTHON_EXECUTABLE (first 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_VARIANT ON/OFF MPark.Variant 1.4.0+
openPMD_USE_INTERNAL_CATCH ON/OFF Catch2 2.6.1+
openPMD_USE_INTERNAL_PYBIND11 ON/OFF pybind11 2.3.0+
openPMD_USE_INTERNAL_JSON ON/OFF NLohmann-JSON 3.7.0+

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 -DBUILD_TESTING=OFF, -DBUILD_EXAMPLES=OFF, or -DBUILD_CLI_TOOLS=OFF to your cmake command.

Linking to your project

The install will contain header files and libraries in the path set with -DCMAKE_INSTALL_PREFIX.

CMake

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 ADIOS1 ADIOS2
find_package(openPMD 0.9.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(BUILD_TESTING OFF)
set(BUILD_EXAMPLES OFF)
set(openPMD_USE_PYTHON OFF)
FetchContent_Declare(openPMD
  GIT_REPOSITORY "https://github.com/openPMD/openPMD-api.git"
  GIT_TAG        "dev")
FetchContent_MakeAvailable(openPMD)

Manually

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

Author Contributions

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:

Further thanks go to improvements and contributions from:

Grants

The openPMD-api authors acknowledge support via the following programs. This project has received funding from the European Unions Horizon 2020 research and innovation programme under grant agreement No 654220. 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).

Transitive Contributions

openPMD-api stands on the shoulders of giants and we are grateful for the following projects included as direct dependencies:

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

openPMD-api-0.11.0a0.tar.gz (649.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

openPMD_api-0.11.0a0-cp38-cp38-manylinux2010_x86_64.whl (5.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

openPMD_api-0.11.0a0-cp37-cp37m-manylinux2010_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

openPMD_api-0.11.0a0-cp36-cp36m-manylinux2010_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

openPMD_api-0.11.0a0-cp35-cp35m-manylinux2010_x86_64.whl (5.4 MB view details)

Uploaded CPython 3.5mmanylinux: glibc 2.12+ x86-64

File details

Details for the file openPMD-api-0.11.0a0.tar.gz.

File metadata

  • Download URL: openPMD-api-0.11.0a0.tar.gz
  • Upload date:
  • Size: 649.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for openPMD-api-0.11.0a0.tar.gz
Algorithm Hash digest
SHA256 7c6ba58eee9dcf9fe8f0c0d8acf7f957e1d265bc41901ea0eb814101f050fda0
MD5 9ce4dc5145de6492faf278f935afcbba
BLAKE2b-256 ad1be8711af2fc1438a4aec7c7971815f5ad7d58c50307f6dff827c641a5635e

See more details on using hashes here.

File details

Details for the file openPMD_api-0.11.0a0-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: openPMD_api-0.11.0a0-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 5.3 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for openPMD_api-0.11.0a0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 5ccce0c4cc1bc021de19b39ac93b8023d691240af4e099c5dfd59841165af27e
MD5 2f68527b363650c6ae851e691ea555eb
BLAKE2b-256 18218e2c4e740c7fdc00950138b03322fe7d2f746906f5e00fec6fa18615da8c

See more details on using hashes here.

File details

Details for the file openPMD_api-0.11.0a0-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: openPMD_api-0.11.0a0-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for openPMD_api-0.11.0a0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2144f3c277e48a66966f38aeafcb9f5619e1a1953ffffb84361101687e947733
MD5 53d79438bde864ba12beae5b84fc801d
BLAKE2b-256 14907946a96c60f1bc9c31723e533c53cd53c705ecc105698ce360f4b6b8d0b2

See more details on using hashes here.

File details

Details for the file openPMD_api-0.11.0a0-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: openPMD_api-0.11.0a0-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for openPMD_api-0.11.0a0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 0871808973298e7d5ecd491afd23579464a5d883dafde7fce8da1d29bb2277ea
MD5 3e8e72489fb277925ae6e2727d00de20
BLAKE2b-256 ed549939e842221520963c50ccfc6bc3afb3e6c09a2d11ee999dc64b6ef6f627

See more details on using hashes here.

File details

Details for the file openPMD_api-0.11.0a0-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: openPMD_api-0.11.0a0-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for openPMD_api-0.11.0a0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 2ab29d1275f2b26d3349ced623abf4ec1f0b430405d701a8c3c6007c863f7c6c
MD5 be4dc87037c4f9329db591fb977bd522
BLAKE2b-256 6a558a781e9b22992e946f13bcf797208afaaca43556bc0c5bc3de4b82000f3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page