Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:
# clang-format v13
# to run manually, use .github/workflows/clang-format/clang-format.sh
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v22.1.5
rev: v22.1.8
hooks:
- id: clang-format
# By default, the clang-format hook configures:
Expand All @@ -86,7 +86,7 @@ repos:
name: pycln (python)

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.1
rev: v0.16.1

hooks:
- id: ruff-check
Expand Down
3 changes: 1 addition & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# This file is execfile()d with the current directory set to its
# containing dir.
Expand All @@ -16,8 +15,8 @@
import os
import subprocess

from recommonmark.parser import CommonMarkParser
import sphinx_rtd_theme
from recommonmark.parser import CommonMarkParser

# import sys
# sys.path.insert(0, os.path.abspath('.'))
Expand Down
4 changes: 2 additions & 2 deletions examples/10_streaming_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Read all available iterations and print electron position data.
for index, iteration in series.snapshots().items():
print("Current iteration {}".format(index))
print(f"Current iteration {index}")
electronPositions = iteration.particles["e"]["position"]
loadedChunks = []
shapes = []
Expand All @@ -42,7 +42,7 @@
for i in range(3):
dim = dimensions[i]
shape = shapes[i]
print("dim: {}".format(dim))
print(f"dim: {dim}")
chunk = loadedChunks[i]
print(chunk)

Expand Down
1 change: 1 addition & 0 deletions examples/10_streaming_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys

import numpy as np

import openpmd_api as io

# pass-through for ADIOS2 engine parameters
Expand Down
5 changes: 2 additions & 3 deletions examples/11_particle_dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys

import numpy as np

import openpmd_api as io

try:
Expand Down Expand Up @@ -124,9 +125,7 @@
E.grid_unit_SI * 1.0e6 * (idx_max * E.grid_spacing + E.grid_global_offset)
)
print(
"maximum intensity I={} at index={} z={}mu".format(
Intensity_max, idx_max, pos_max[2]
)
f"maximum intensity I={Intensity_max} at index={idx_max} z={pos_max[2]}mu"
)

s.close()
1 change: 1 addition & 0 deletions examples/12_span_write.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np

import openpmd_api as io


Expand Down
1 change: 1 addition & 0 deletions examples/13_write_dynamic_configuration.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python
import numpy as np

import openpmd_api as io

# This example demonstrates how to use JSON/TOML-based dynamic
Expand Down
5 changes: 3 additions & 2 deletions examples/15_compression.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#

import numpy as np

import openpmd_api as opmd

try:
Expand Down Expand Up @@ -68,7 +69,7 @@ def write(filename, config):
def main():

# We start with two examples for ADIOS2.
if "adios2" in opmd.variants and opmd.variants["adios2"]:
if opmd.variants.get("adios2"):
simple_adios2_config = {
# Backend can either be inferred from the filename ending, or
# specified explicitly. In the latter case, the filename ending can
Expand Down Expand Up @@ -189,7 +190,7 @@ def main():
# Filters are additionally distinguished by how tightly they integrate with
# HDF5. The most tightly-integrated filter is Zlib, which has its own API
# calls and hence also a special JSON/TOML configuration in openPMD:
if "hdf5" in opmd.variants and opmd.variants["hdf5"]:
if opmd.variants.get("hdf5"):
hdf5_zlib_config = {
"backend": "hdf5",
"hdf5": {
Expand Down
26 changes: 13 additions & 13 deletions examples/2_read_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@
)
print("Read a Series with openPMD standard version %s" % series.openPMD)

print("The Series contains {0} iterations:".format(len(series.snapshots())))
print(f"The Series contains {len(series.snapshots())} iterations:")
for i in series.snapshots():
print("\t {0}".format(i))
print("")
print(f"\t {i}")
print()

# with defer_iteration_parsing, open() must be called explicitly
i = series.snapshots()[100].open()
print("Iteration 100 contains {0} meshes:".format(len(i.meshes)))
print(f"Iteration 100 contains {len(i.meshes)} meshes:")
for m in i.meshes:
print("\t {0}".format(m))
print("")
print("Iteration 100 contains {0} particle species:".format(len(i.particles)))
print(f"\t {m}")
print()
print(f"Iteration 100 contains {len(i.particles)} particle species:")
for ps in i.particles:
print("\t {0}".format(ps))
print(f"\t {ps}")
print("With records:")
for r in i.particles[ps]:
print("\t {0}".format(r))
print(f"\t {r}")

# printing a scalar value
electrons = i.particles["electrons"]
charge = electrons["charge"]
series.flush()
print("And the first electron particle has a charge {}".format(charge[0]))
print("")
print(f"And the first electron particle has a charge {charge[0]}")
print()

E_x = i.meshes["E"]["x"]
shape = E_x.shape

print("Field E.x has shape {0} and datatype {1}".format(shape, E_x.dtype))
print(f"Field E.x has shape {shape} and datatype {E_x.dtype}")

chunk_data = E_x[1:3, 1:3, 1:2]
# print("Queued the loading of a single chunk from disk, "
Expand All @@ -65,7 +65,7 @@
# The iteration can be closed in order to help free up resources.
# The iteration's content will be flushed automatically.
i.close()
print("Full E/x is of shape {0} and starts with:".format(all_data.shape))
print(f"Full E/x is of shape {all_data.shape} and starts with:")
print(all_data[0, 0, :5])

# The files in 'series' are still open until the series is closed, at which
Expand Down
9 changes: 4 additions & 5 deletions examples/3_write_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import numpy as np

import openpmd_api as io

if __name__ == "__main__":
Expand All @@ -17,22 +18,20 @@
# matrix dataset to write with values 0...size*size-1
data = np.arange(size * size, dtype=np.double).reshape(3, 3)

print("Set up a 2D square array ({0}x{1}) that will be written".format(size, size))
print(f"Set up a 2D square array ({size}x{size}) that will be written")

# open file for writing
series = io.Series("../samples/3_write_serial_py.h5", io.Access.create_linear)

print("Created an empty {0} Series".format(series.iteration_encoding))
print(f"Created an empty {series.iteration_encoding} Series")

print(len(series.iterations))
rho = series.snapshots()[1].meshes["rho"]

dataset = io.Dataset(data.dtype, data.shape)

print(
"Created a Dataset of size {0}x{1} and Datatype {2}".format(
dataset.extent[0], dataset.extent[1], dataset.dtype
)
f"Created a Dataset of size {dataset.extent[0]}x{dataset.extent[1]} and Datatype {dataset.dtype}"
)

rho.reset_dataset(dataset)
Expand Down
3 changes: 2 additions & 1 deletion examples/3a_write_thetaMode_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import numpy as np

import openpmd_api as io

if __name__ == "__main__":
Expand All @@ -30,7 +31,7 @@
num_fields, N_r, N_z
)

geometry_parameters = "m={0};imag=+".format(num_modes)
geometry_parameters = f"m={num_modes};imag=+"

E = series.snapshots()[0].meshes["E"]
E.geometry = io.Geometry.thetaMode
Expand Down
1 change: 1 addition & 0 deletions examples/3b_write_resizable_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import numpy as np

import openpmd_api as io

if __name__ == "__main__":
Expand Down
13 changes: 5 additions & 8 deletions examples/4_read_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# on import: calls MPI_Init_thread()
# exit hook: calls MPI_Finalize()
from mpi4py import MPI

import openpmd_api as io

if __name__ == "__main__":
Expand All @@ -25,7 +26,7 @@
{"defer_iteration_parsing": True},
)
if 0 == comm.rank:
print("Read a series in parallel with {} MPI ranks".format(comm.size))
print(f"Read a series in parallel with {comm.size} MPI ranks")

# with defer_iteration_parsing, open() must be called explicitly
# explicit use of open() is recommended for parallel applications
Expand All @@ -51,18 +52,14 @@

for i in range(comm.size):
if i == comm.rank:
print("Rank {} - Read chunk contains:".format(i))
print(f"Rank {i} - Read chunk contains:")
for row in range(chunk_extent[0]):
for col in range(chunk_extent[1]):
print(
"\t({}|{}|1)\t{:e}".format(
row + chunk_offset[0],
col + chunk_offset[1],
chunk_data[row, col, 0],
),
f"\t({row + chunk_offset[0]}|{col + chunk_offset[1]}|1)\t{chunk_data[row, col, 0]:e}",
end="",
)
print("")
print()

# this barrier is not necessary but structures the example output
comm.Barrier()
Expand Down
13 changes: 6 additions & 7 deletions examples/5_write_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
# https://mpi4py.readthedocs.io/en/stable/mpi4py.run.html
# on import: calls MPI_Init_thread()
# exit hook: calls MPI_Finalize()
from mpi4py import MPI
import numpy as np
from mpi4py import MPI

import openpmd_api as io

try:
Expand All @@ -33,8 +34,8 @@
local_data = np.ones(10 * 300, dtype=np.double).reshape(10, 300) * local_value
if 0 == comm.rank:
print(
"Set up a 2D array with 10x300 elements per MPI rank ({}x) "
"that will be written to disk".format(comm.size)
f"Set up a 2D array with 10x300 elements per MPI rank ({comm.size}x) "
"that will be written to disk"
)

# open file for writing
Expand All @@ -46,7 +47,7 @@
comm,
)
if 0 == comm.rank:
print("Created an empty series in parallel with {} MPI ranks".format(comm.size))
print(f"Created an empty series in parallel with {comm.size} MPI ranks")

# In parallel contexts, it's important to explicitly open iterations.
# However, we use Access mode CREATE_LINEAR, so the Series creates
Expand All @@ -65,9 +66,7 @@

if 0 == comm.rank:
print(
"Prepared a Dataset of size {} and Datatype {}".format(
dataset.extent, dataset.dtype
)
f"Prepared a Dataset of size {dataset.extent} and Datatype {dataset.dtype}"
)

mymesh.reset_dataset(dataset)
Expand Down
1 change: 1 addition & 0 deletions examples/7_extended_write_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import numpy as np

from openpmd_api import Access, Dataset, Mesh_Record_Component, Series, Unit_Dimension

SCALAR = Mesh_Record_Component.SCALAR
Expand Down
1 change: 1 addition & 0 deletions examples/9_particle_write_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path

import numpy as np

from openpmd_api import Access, Dataset, Series, Unit_Dimension

if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions new_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# This file is a maintainer tool to bump the versions inside openPMD-api's
# source directory at all places where necessary.
#
from pathlib import Path
import re
import sys
from pathlib import Path

# Maintainer Inputs ###########################################################

Expand Down Expand Up @@ -97,7 +97,7 @@
cmakelists_content = f.read()
cmakelists_content = re.sub(
r"^(project.*openPMD.*VERSION *)(.*)(\).*)$",
r"\g<1>{}\g<3>".format(VERSION_STR),
rf"\g<1>{VERSION_STR}\g<3>",
cmakelists_content,
flags=re.MULTILINE,
)
Expand Down Expand Up @@ -165,16 +165,16 @@ def generic_replace(filename, previous, after):
def replace(key, value):
global version_hpp_content
version_hpp_content = re.sub(
r"^(#define OPENPMDAPI_VERSION_{}) .*$".format(re.escape(key)),
r"\1 {}".format(value),
rf"^(#define OPENPMDAPI_VERSION_{re.escape(key)}) .*$",
rf"\1 {value}",
version_hpp_content,
flags=re.MULTILINE,
)

replace("MAJOR", MAJOR)
replace("MINOR", MINOR)
replace("PATCH", PATCH)
replace("LABEL", '"{}"'.format(SUFFIX))
replace("LABEL", f'"{SUFFIX}"')

with open(version_hpp_path, "w", encoding="utf-8") as f:
f.write(version_hpp_content)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def build_extension(self, ext):
else:
continue
if cmake_var:
extra_cmake_args.append("-D{0}={1}".format(cmake_var, v))
extra_cmake_args.append(f"-D{cmake_var}={v}")

# https://cmake.org/cmake/help/v3.0/command/if.html
if openPMD_USE_MPI.upper() in ["1", "ON", "TRUE", "YES"]:
Expand All @@ -188,7 +188,7 @@ def build_extension(self, ext):

# Get the package requirements from the requirements.txt file
with open("./requirements.txt") as f:
install_requires = [line.strip("\n") for line in f.readlines()]
install_requires = [line.strip("\n") for line in f]
if openPMD_USE_MPI == "ON":
install_requires.append("mpi4py>=2.1.0")

Expand Down
Loading
Loading