Skip to content

Commit

Permalink
fixup! fixup! python: rewrite Python high level API in python
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentebolea committed Dec 12, 2023
1 parent e618935 commit f96a6d7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
8 changes: 6 additions & 2 deletions python/adios2/adios.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@


class ADIOS:
def __init__(self):
self._impl = bindings.ADIOS()
def __init__(self, comm=None):
if comm:
self._impl = bindings.ADIOS(comm=comm)
else:
self._impl = bindings.ADIOS()

self._operators = {}
self._ios = {}

Expand Down
2 changes: 1 addition & 1 deletion python/adios2/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def DefineVariable(
shape=[],
start=[],
count=[],
isConstantDims=bindings.ConstantDims,
isConstantDims=False,
):
if isinstance(content, np.ndarray):
#if shape is None:
Expand Down
9 changes: 6 additions & 3 deletions python/adios2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def typeAdiosToNumPy(name):


class Stream:
def __init__(self, path, mode="r", engine_type="BPStream", config_file=None):
def __init__(self, path, mode="r", comm=None, engine_type="BPStream", config_file=None):
self._io_name = f"stream:{path}:engine_type:{engine_type}"
self._adios = ADIOS()
self._adios = ADIOS(comm=comm)
self._io = self._adios.DeclareIO(self._io_name)
self._mode = mode

Expand All @@ -42,7 +42,7 @@ def __init__(self, path, mode="r", engine_type="BPStream", config_file=None):
self.max_steps = 0

def __repr__(self):
return f"<adios.file named {self._name} and mode {self._mode}>"
return f"<adios.file named {self._io_name} and mode {self._mode}>"

def __enter__(self):
return self
Expand Down Expand Up @@ -322,3 +322,6 @@ def steps(self, num_steps=0):

self.index = 0
return self

def num_steps(self, num_steps=0):
return self._engine.Steps()
28 changes: 14 additions & 14 deletions testing/adios2/python/TestBPWriteTypesHighLevelAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
# Writer
with Stream("types_np.bp", "w", comm) as s:

for i in range(0, 5):
data.update(rank, i, size)
if rank == 0 and i == 0:
for step in s.steps(5):
data.update(rank, step.current_step(), size)
#s.write("rank", np.array(rank), shape=[adios2.LocalValueDim])
if rank == 0 and step.current_step() == 0:
s.write("tag", "Testing ADIOS2 high-level API")
s.write("gvarI8", np.array(data.I8[0]))
s.write("gvarI16", np.array(data.I16[0]))
Expand Down Expand Up @@ -70,8 +71,8 @@
s.write_attribute("attrR32Array", data.R32)
s.write_attribute("attrR64Array", data.R64)

s.write("rank", np.array(rank), [adios2.LocalValueDim])
s.write("steps", "Step:" + str(i))
#breakpoint()
s.write("steps", "Step:" + str(step.current_step() ))
s.write("varI8", data.I8, shape, start, count)
s.write("varI16", data.I16, shape, start, count)
s.write("varI32", data.I32, shape, start, count)
Expand All @@ -83,7 +84,7 @@
s.write("varR32", data.R32, shape, start, count)
s.write("varR64", data.R64, shape, start, count)

if rank == 0 and i == 0:
if rank == 0 and step.current_step() == 0:
s.write_attribute("varattrStrArray", [
"varattr1", "varattr2", "varattr3"], "steps")
s.write_attribute("varattrI8Array", data.I8, "varI8")
Expand All @@ -98,8 +99,6 @@
s.write_attribute("varattrR64Array", data.R64, "varR64")
s.write_attribute("varattrR64Value", data.R64, "varR64")

s.end_step()

comm.Barrier()

# Reader
Expand All @@ -108,9 +107,9 @@
with Stream("types_np.bp", "r", comm) as fr:

# file only
assert (fr.steps() == 5)
assert (fr.num_steps() == 5)

for fr_step in fr:
for fr_step in fr.steps():

step = fr_step.current_step()
data.update(rank, step, size)
Expand All @@ -124,7 +123,7 @@
# print("\n")

if step == 0:
inTag = fr_step.read_string("tag")
inTag = fr_step.read("tag")
inI8 = fr_step.read("gvarI8")
inI16 = fr_step.read("gvarI16")
inI32 = fr_step.read("gvarI32")
Expand All @@ -136,7 +135,7 @@
inR32 = fr_step.read("gvarR32")
inR64 = fr_step.read("gvarR64")

if inTag[0] != "Testing ADIOS2 high-level API":
if inTag != "Testing ADIOS2 high-level API":
print("InTag: " + str(inTag))
raise ValueError('tag variable read failed')

Expand Down Expand Up @@ -171,7 +170,8 @@
raise ValueError('gvarR64 read failed')

# attributes
inTag = fr_step.read_attribute_string("attrStr")
breakpoint()
inTag = fr_step.read_attribute("attrStr")
inI8 = fr_step.read_attribute("attrI8")
inI16 = fr_step.read_attribute("attrI16")
inI32 = fr_step.read_attribute("attrI32")
Expand All @@ -183,7 +183,7 @@
inR32 = fr_step.read_attribute("attrR32")
inR64 = fr_step.read_attribute("attrR64")

if inTag[0] != "Testing single string attribute":
if inTag != "Testing single string attribute":
raise ValueError('attr string read failed')

if inI8[0] != data.I8[0]:
Expand Down

0 comments on commit f96a6d7

Please sign in to comment.