Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix IO.available_attributes(), remove a debug print from Stream, fix … #4021

Merged
merged 5 commits into from
Feb 9, 2024
Merged
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
10 changes: 9 additions & 1 deletion examples/hello/sstReader/sstReader-bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@
sstReader.EndStep()

print(
"Rank=", rank, "loop index =", loopStep, "stream step =", currentStep, "data =", floatArray
"Rank=",
rank,
"loop index =",
loopStep,
"stream step =",
currentStep,
"data =",
floatArray,
flush=True,
)
loopStep = loopStep + 1

Expand Down
1 change: 1 addition & 0 deletions examples/hello/sstReader/sstReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@
currentStep,
"data =",
floatArray,
flush=True,
)
2 changes: 1 addition & 1 deletion examples/hello/sstWriter/sstWriter-bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

sstWriter = sstIO.Open("helloSst", adios2.Mode.Write)
for i in range(4):
print("Rank=", rank, "loop index =", i, "data =", myArray)
print("Rank=", rank, "loop index =", i, "data =", myArray, flush=True)
sstWriter.BeginStep()
sstWriter.Put(ioArray, myArray, adios2.Mode.Sync)
myArray += increment
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/sstWriter/sstWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
sleep(1.0)

stream.write("bpFloats", myArray, [size * nx], [rank * nx], [nx])
print("Rank=", rank, "loop index =", currentStep, "data =", myArray)
print("Rank=", rank, "loop index =", currentStep, "data =", myArray, flush=True)
myArray += increment
# Warning: the data of the current step is not published until
# the next loop entry or the exit of the loop
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Documentation = "https://adios2.readthedocs.io/"
Discussions = "https://github.com/ornladios/ADIOS2/discussions"
Changelog = "https://github.com/ornladios/ADIOS2/releases"

[project.entry-points."xarray.backends"]
adios = "adios2.xarraybackend:AdiosBackendEntrypoint"

[tool.cibuildwheel]
# Trigger an install of the package, and run a basic test
test-command = "python -m unittest adios2.test.simple_read_write.TestSimpleReadWrite"
Expand Down
4 changes: 2 additions & 2 deletions python/adios2/file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import singledispatchmethod
from adios2 import Stream, IO


# pylint: disable=W0221
class FileReader(Stream):
"""High level implementation of the FileReader class for read Random access mode"""

Expand All @@ -19,7 +19,7 @@ def __init__(self, path, comm=None):
# e.g. FileReader(io: adios2.IO, path, mode)
# pylint: disable=E1121
@__init__.register(IO)
def _(self, io: IO, path, mode, comm=None):
def _(self, io: IO, path, comm=None):
super().__init__(io, path, "rra", comm)

# pylint: enable=E1121
Expand Down
15 changes: 10 additions & 5 deletions python/adios2/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ def define_attribute(
e.g. variable_name + separator + name ("var/attr")
Not used if variable_name is empty
"""
return Attribute(self.impl, name, content, variable_name, separator)

# string or list of strings passed on as is
if isinstance(content, list) and len(content) > 0 and isinstance(content[0], str):
return Attribute(self.impl, name, content, variable_name, separator)
if isinstance(content, str):
return Attribute(self.impl, name, content, variable_name, separator)

# python values (single or list) needs to be passed as a numpy array
return Attribute(self.impl, name, np.asarray(content), variable_name, separator)

def inquire_attribute(self, name, variable_name="", separator="/"):
"""
Expand Down Expand Up @@ -103,10 +111,7 @@ def available_attributes(self):
value
attribute information dictionary
"""
attributes = {}
for name, attr in self.impl.AvailableAttributes():
attributes[name] = Attribute(attr, name)
return attributes
return self.impl.AvailableAttributes()
vicentebolea marked this conversation as resolved.
Show resolved Hide resolved

def remove_attribute(self, name):
"""
Expand Down
25 changes: 21 additions & 4 deletions python/adios2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,27 @@ def inquire_variable(self, name):
"""
return self._io.inquire_variable(name)

def inquire_attribute(self, name, variable_name="", separator="/"):
"""
Inquire an attribute
Parameters
name
attribute name
variable_name
if attribute is associated with a variable
separator
concatenation string between variable_name and attribute
e.g. variable_name + separator + name ("var/attr")
Not used if variable_name is empty
Returns
The attribute if it is defined, otherwise None
"""
return self._io.inquire_attribute(name, variable_name, separator)

@singledispatchmethod
def write(self, variable: Variable, content):
"""
Expand Down Expand Up @@ -311,10 +332,6 @@ def read(self, variable: Variable):

output_shape = np.array(count)
output_shape[0] *= steps
print(
f"Stream.read variable {variable.name()} dtype = {dtype} "
f"shape = {output_shape}, steps = {variable.steps()}"
)
else:
# scalar
output_shape = (variable.selection_size(),)
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/images/Dockerfile.ci-el8-intel
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN dnf install -y \
patch \
patchelf \
python39-devel \
python3-pip \
python39-pip \
tar \
tcl \
unzip \
Expand Down
13 changes: 11 additions & 2 deletions testing/adios2/bindings/python/TestBPWriteReadTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def check_array(np1, np2, hint):
Nx = 8

# list of tested attributes and variables
attr_names = ["attrString", "attrI8", "attrI16", "attrI32", "attrI64",
attr_names = ["attrString", "attrStringArray", "attrI8", "attrI16", "attrI32", "attrI64",
"attrU8", "attrU16", "attrU32", "attrU64", "attrR32", "attrR64"]
var_names = ["varStr", "varI8", "varI16", "varI32", "varI64",
"varU8", "varU16", "varU32", "varU64",
Expand Down Expand Up @@ -82,7 +82,8 @@ def check_array(np1, np2, hint):
varR64 = ioWriter.DefineVariable(
"varR64", data.R64, shape, start, count, adios2.ConstantDims)

attString = ioWriter.DefineAttribute("attrString", ["one", "two", "three"])
attString = ioWriter.DefineAttribute("attrString", "one")
attStringArray = ioWriter.DefineAttribute("attrStringArray", ["one", "two", "three"])
attI8 = ioWriter.DefineAttribute("attrI8", data.I8)
attI16 = ioWriter.DefineAttribute("attrI16", data.I16)
attI32 = ioWriter.DefineAttribute("attrI32", data.I32)
Expand Down Expand Up @@ -146,6 +147,7 @@ def check_array(np1, np2, hint):
reader = ioReader.Open("npTypes.bp", adios2.Mode.ReadRandomAccess)

attrString = ioReader.InquireAttribute("attrString")
attrStringArray = ioReader.InquireAttribute("attrStringArray")
attrI8 = ioReader.InquireAttribute("attrI8")
attrI16 = ioReader.InquireAttribute("attrI16")
attrI32 = ioReader.InquireAttribute("attrI32")
Expand All @@ -158,6 +160,7 @@ def check_array(np1, np2, hint):
attrR64 = ioReader.InquireAttribute("attrR64")

check_object(attrString, "attrString")
check_object(attrStringArray, "attrStringArray")
check_object(attrI8, "attrI8")
check_object(attrI16, "attrI16")
check_object(attrI32, "attrI32")
Expand All @@ -170,6 +173,12 @@ def check_array(np1, np2, hint):
check_object(attrR64, "attrR64")

attrStringData = attrString.DataString()
print(f"attrString = {attrStringData}", flush=True)
if attrStringData[0] != "one":
raise ValueError('attrString failed')

attrStringData = attrStringArray.DataString()
print(f"attrStringArray = {attrStringData}", flush=True)
if attrStringData[0] != "one":
raise ValueError('attrStringData[0] failed')
if attrStringData[1] != "two":
Expand Down
16 changes: 13 additions & 3 deletions testing/adios2/python/TestIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ def test_io_inquire_attribute(self):
self.assertNotEqual(ts, coords)
self.assertNotEqual(ts, x)
self.assertEqual(coords, x)
self.assertIs(io.inquire_attribute("notanattribute"), None)

def test_available_attribute(self):
def test_available_attributes(self):
adios = Adios()
io = adios.declare_io("BPWriter")
io.define_attribute("timestamp", "20231122")
io.inquire_attribute("timestamp")
self.assertIs(io.inquire_attribute("coords"), None)
io.define_attribute("stringarray", ["one", "two", "three"])
io.define_attribute("afloat", 3.14)
io.define_attribute("floatarray", [3.14, 6.28])
attrs = io.available_attributes()
print("Available attributes:")
for aname, ainfo in attrs.items():
print(f" {aname}:\t{ainfo}")
self.assertEqual(attrs["timestamp"]["Value"], '"20231122"')
self.assertEqual(attrs["stringarray"]["Value"], '{ "one", "two", "three" }')
self.assertFalse("coords" in attrs)

def test_remove_attribute(self):
adios = Adios()
Expand Down Expand Up @@ -96,6 +105,7 @@ def test_open_engine(self):
io.add_transport("File", {"Library": "POSIX"})
engine = io.open("pythontest.bp", bindings.Mode.Write)
self.assertNotEqual(engine, None)
engine.close()


if __name__ == "__main__":
Expand Down
Loading