openPMD / openPMD/openPMD-api

Different behavior of read-write properties in Python

Open
#1,092 3 comments 0 reactions 0 assignees View on GitHub
bug frontend: Python3
Dominant language
C++
Stars
161
Forks
59
Avg merge
2d 22h
Merged PRs (30d)
7

Description

**Describe the bug**
The read-write properties introduced in `0.13.0`, such as `dt`, `time`, etc., seem to have a different behavior than the previous `set_dt`, `set_time`, methods. In particular, they result in a different data type of the attributes.

I noticed this problem when opening data from Wake-T (which [uses these new properties](https://github.com/AngelFP/Wake-T/commit/7328ec24f3b582e61261b4cdef7aa6c934437545)) with the `LPADiagnostics` of the `openpmd-viewer` when using the `openpmd-api` backend. This throws an error
```bash
File "analyze_simulations.py", line 25, in analyze_simulations_wt
ts = LpaDiagnostics(os.path.join(diag_dir, 'hdf5'))
File "/home/ferran/.conda/envs/fbpic_env_new/lib/python3.8/site-packages/openpmd_viewer/addons/pic/lpa_diagnostics.py", line 53, in __init__
OpenPMDTimeSeries.__init__( self, path_to_dir,
File "/home/ferran/.conda/envs/fbpic_env_new/lib/python3.8/site-packages/openpmd_viewer/openpmd_timeseries/main.py", line 73, in __init__
self.iterations = self.data_reader.list_iterations(path_to_dir)
File "/home/ferran/.conda/envs/fbpic_env_new/lib/python3.8/site-packages/openpmd_viewer/openpmd_timeseries/data_reader/data_reader.py", line 104, in list_iterations
self.series = io.Series(
RuntimeError: Unexpected Attribute datatype for 'dt'
```
apparently because the type is `float128`.

However, this type only appears when using the new read-write properties. Using the old methods results instead in a `float32`.

(As a side note, using the `LPADiagnostics` with the `h5py` backend works perfectly fine, even with `float128`.)

**To Reproduce**

Python:
```python
import numpy as np
from openpmd_api import Series, Access

opmd_series = Series('data%08T.h5', Access.create)
it = opmd_series.iterations[0]

it.set_time(np.float64(1.))
it.set_dt(np.float64(1.))
print(it.attribute_dtypes['time'])
print(it.attribute_dtypes['dt'])

it.time = np.float64(1.)
it.dt = np.float64(1.)
print(it.attribute_dtypes['time'])
print(it.attribute_dtypes['dt'])
```
output
```bash
float32
float32
float128
float128
```

**Expected behavior**
Same resulting data type in both cases.

**Software Environment**
- version of openPMD-api: 0.14.2
- installed openPMD-api via: pip
- operating system: CentOS 7.9.2009
- machine: DESY Maxwell cluster
- name and version of Python implementation: Python 3.8.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.