Different behavior of read-write properties in Python
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) with the LPADiagnostics of the openpmd-viewer when using the openpmd-api backend. This throws an error
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:
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
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
Sorry for the delay and thank you for the detailed analysis!
So that's a write issue, dang. I'll work on it.
I found a reader issue: should support those float128 attributes in read as well: fix in #1096 and goes in the next patch release (0.14.3).
I keep this open since there should be at least one further PR, which ensures that the type that one writes round-trips.
Thanks @ax3l! And no problem, I also haven't had time to look into this again. I believe however that dt and time are not the only properties which showed this issue. I only use a subset of them, but I can run another test to see which ones where also failing.