diff --git a/python/adios2/adios.py b/python/adios2/adios.py index 2e7ad7aab2..94b07f61f2 100644 --- a/python/adios2/adios.py +++ b/python/adios2/adios.py @@ -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 = {} diff --git a/python/adios2/io.py b/python/adios2/io.py index 7bf3cf345a..f777203beb 100644 --- a/python/adios2/io.py +++ b/python/adios2/io.py @@ -51,7 +51,7 @@ def DefineVariable( shape=[], start=[], count=[], - isConstantDims=bindings.ConstantDims, + isConstantDims=False, ): if isinstance(content, np.ndarray): #if shape is None: diff --git a/python/adios2/stream.py b/python/adios2/stream.py index 66a3bbe9d1..53f83b57a2 100644 --- a/python/adios2/stream.py +++ b/python/adios2/stream.py @@ -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 @@ -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"" + return f"" def __enter__(self): return self @@ -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() diff --git a/testing/adios2/python/TestBPWriteTypesHighLevelAPI.py b/testing/adios2/python/TestBPWriteTypesHighLevelAPI.py index 7ee9788f83..2a083eb66c 100644 --- a/testing/adios2/python/TestBPWriteTypesHighLevelAPI.py +++ b/testing/adios2/python/TestBPWriteTypesHighLevelAPI.py @@ -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])) @@ -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) @@ -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") @@ -98,8 +99,6 @@ s.write_attribute("varattrR64Array", data.R64, "varR64") s.write_attribute("varattrR64Value", data.R64, "varR64") - s.end_step() - comm.Barrier() # Reader @@ -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) @@ -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") @@ -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') @@ -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") @@ -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]: