File: test_attributes.py

package info (click to toggle)
adios4dolfinx 0.10.0.post0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 536 kB
  • sloc: python: 4,180; sh: 24; makefile: 7
file content (44 lines) | stat: -rw-r--r-- 1,560 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from pathlib import Path

from mpi4py import MPI

import adios2
import numpy as np
import pytest
from packaging.version import parse as _v

import adios4dolfinx


@pytest.mark.skipif(
    _v(np.__version__) >= _v("2.0.0") and _v(adios2.__version__) < _v("2.10.2"),
    reason="Cannot use numpy>=2.0.0 and adios2<2.10.2",
)
@pytest.mark.parametrize("comm", [MPI.COMM_SELF, MPI.COMM_WORLD])
def test_read_write_attributes(comm, tmp_path):
    attributes1 = {
        "a": np.array([1, 2, 3], dtype=np.uint8),
        "b": np.array([4, 5], dtype=np.uint8),
    }
    attributes2 = {
        "c": np.array([6], dtype=np.uint8),
        "d": np.array([7, 8, 9, 10], dtype=np.uint8),
    }
    fname = MPI.COMM_WORLD.bcast(tmp_path, root=0)
    file = fname / Path("attributes.bp")

    adios4dolfinx.write_attributes(comm=comm, filename=file, name="group1", attributes=attributes1)
    adios4dolfinx.write_attributes(comm=comm, filename=file, name="group2", attributes=attributes2)
    MPI.COMM_WORLD.Barrier()
    loaded_attributes1 = adios4dolfinx.read_attributes(comm=comm, filename=file, name="group1")
    loaded_attributes2 = adios4dolfinx.read_attributes(comm=comm, filename=file, name="group2")

    for k, v in loaded_attributes1.items():
        assert np.allclose(v, attributes1[k])
    for k, v in attributes1.items():
        assert np.allclose(v, loaded_attributes1[k])

    for k, v in loaded_attributes2.items():
        assert np.allclose(v, attributes2[k])
    for k, v in attributes2.items():
        assert np.allclose(v, loaded_attributes2[k])