def setUp(self): NX = 10 size = 2 t = np.array(range(NX*size), dtype=np.float64) tt = t.reshape((size, NX)) self.temp = TempFile() ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); fw = ad.writer(self.temp.path) fw.declare_group('group', method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw.attrs['/temperature/description'] = "Global array written from 'size' processes" fw.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"] = 99 fw["/someSubGroup/anOtherGroup/anOtherVariable"] = 77 fw.close() ad.finalize() self.f = ad.file(self.temp.path)
def test_writer_default_group(self): self.temp = TempFile() fw = ad.writer(self.temp.path, method="POSIX1") fw.close() f = ad.file(self.temp.path) f.close()
def test_simple1(self): self.temp = TempFile() NX = 10 size = 2 t = np.array(list(range(NX * size)), dtype=np.float64) tt = t.reshape((size, NX)) fw = ad.writer(self.temp.path) fw.declare_group('group', method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw.attrs[ '/temperature/description'] = "Global array written from 'size' processes" fw.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"] = 99 fw["/someSubGroup/anOtherGroup/anOtherVariable"] = 77 fw.close() f = ad.file(self.temp.path) t = f["temperature"] # here t could have a member dictionary attr(s) again # which looks up all attributes starting with t.name # now match: f.attrs["/temperature/description"] self.assertEqual(t.attrs["description"], f.attrs["/temperature/description"]) # the same should be possible for groups g = f["/someSubGroup/anOtherGroup"] # now match: f.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"] self.assertEqual( g.attrs["anOtherAttribute"], f.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"]) # now match: f["/someSubGroup/anOtherGroup/anOtherVariable"] self.assertEqual(g["anOtherVariable"], f["/someSubGroup/anOtherGroup/anOtherVariable"]) # Missing '/' g = f["someSubGroup/anOtherGroup"] # now match: f.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"] self.assertEqual( g.attrs["anOtherAttribute"], f.attrs["/someSubGroup/anOtherGroup/anOtherAttribute"]) # now match: f["/someSubGroup/anOtherGroup/anOtherVariable"] self.assertEqual(g["anOtherVariable"], f["/someSubGroup/anOtherGroup/anOtherVariable"]) ## Testing name acess self.assertEqual(g["anOtherVariable"][...], g.anOtherVariable[...]) self.assertEqual(g["anOtherAttribute"].value, g.anOtherAttribute.value)
def test_simple2(self): self.temp = TempFile() NX = 10 size = 2 t = np.array(list(range(NX*size)), dtype=np.float64) tt = t.reshape((size, NX)) fw = ad.writer(self.temp.path) fw.declare_group('mygroup', method='POSIX1') fw['/data/0/fields/FieldE/x'] = tt fw['/data/0/fields/FieldE/y'] = tt*2 fw['/data/0/particles/i/globalCellIdx/x'] = t fw['/data/0/particles/i/globalCellIdx/y'] = t*2 fw.attrs['/data/0/fields/FieldE/x/sim_unit'] = 77 fw.attrs['/data/0/fields/FieldE/y/sim_unit'] = 99 fw.attrs['/data/0/fields/e_chargeDensity/sim_unit'] = 88 fw.attrs['/data/0/iteration'] = 33 fw.attrs['/data/0/sim_slides'] = 55 fw.close() f = ad.file(self.temp.path) g = f["data/0"] self.assertTrue((g['fields/FieldE/x'][...] == tt).all()) self.assertEqual(g['fields/FieldE/y/sim_unit'][...], 99) self.assertEqual(g['iteration'][...], 33) g1 = f["/data/0"] self.assertTrue((g1['fields/FieldE/x'][...] == tt).all()) self.assertEqual(g1['fields/FieldE/y/sim_unit'][...], 99) self.assertEqual(g1['iteration'][...], 33) g = f["data"] g = f["/data"] g = f["/data/"] g = f["data/0/"] g = f["/data/0"] g2 = g["fields"] self.assertTrue((g2['FieldE/x'][...] == tt).all()) self.assertTrue((g2['FieldE/y'][...] == tt*2).all()) self.assertEqual(g2['FieldE/x/sim_unit'][...], 77) self.assertEqual(g2['FieldE/y/sim_unit'][...], 99) ## Check dirs() self.assertEqual(sorted(g.dirs()), sorted(['particles', 'fields'])) self.assertEqual(sorted(g['fields'].dirs()), sorted(['e_chargeDensity', 'FieldE'])) self.assertEqual(f.dirs(), ['data'])
def test_softdict2(self): self.temp = TempFile() fw = ad.writer(self.temp.path) fw.vars['a1'] = 12 fw.vars['/a2'] = 42 fw.close() f = ad.file(self.temp.path) self.assertEqual(f.vars['/a1'][...], f['/a1'][...]) self.assertEqual(f.vars['a1'][...], f['a1'][...]) self.assertEqual(f.vars['/a2'][...], f['/a2'][...]) self.assertEqual(f.vars['a2'][...], f['a2'][...])
def test_writer_varname(self): self.temp = TempFile() fw = ad.writer(self.temp.path, method="POSIX1") NVARS = 99 fw.vars['nvars'] = NVARS fw.vars['/nvars'] = NVARS fw.vars['_nvars'] = NVARS fw.close() f = ad.file(self.temp.path) self.assertEqual(f.nvars, 3) self.assertEqual(f._nvars[...], NVARS)
def test_writer_attr(self): self.temp = TempFile() NX = 10 val1 = np.array(list(range(NX)), dtype=np.int32) val2 = np.array(list(range(5)), dtype='f8') single_string = "ABCD" three_string = ("AA", "BBB", "CCCC") single_int = 10 five_int = np.array(list(range(5)), dtype=np.int32) single_double = 1.1 five_double = np.array(list(range(5)), dtype='double') * 1.1 unicode_string = u"unicode" bytes_string = u"bytes" fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw.define_attr("single_string") fw.define_attr("three_string") fw.define_attr("single_int") fw.define_attr("five_int") fw.define_attr("single_double") fw.define_attr("five_double") fw.define_attr("unicode_string") fw.define_attr("bytes_string") fw['single_string'] = single_string fw['three_string'] = three_string fw['single_int'] = single_int fw['five_int'] = five_int fw['single_double'] = single_double fw['five_double'] = five_double fw['unicode_string'] = unicode_string fw['bytes_string'] = bytes_string fw.close() f = ad.file(self.temp.path) self.assertEqual(f['single_string'].value, single_string.encode()) ##self.assertTrue((f['three_string'].value == three_string).all()) self.assertTrue(f['three_string'].value[0], three_string[0].encode()) self.assertTrue(f['three_string'].value[1], three_string[1].encode()) self.assertTrue(f['three_string'].value[2], three_string[2].encode()) self.assertEqual(f['single_int'].value, single_int) self.assertTrue((f['five_int'].value == five_int).all()) self.assertEqual(f['single_double'].value, single_double) self.assertTrue((f['five_double'].value == five_double).all()) self.assertTrue(f['unicode_string'].value, unicode_string.encode()) self.assertTrue(f['bytes_string'].value, bytes_string)
def test_writer_undefined_var(self): self.temp = TempFile() NX = 10 val1 = np.array(list(range(NX)), dtype=np.int32) val2 = np.array(list(range(5)), dtype='f8') fw = ad.writer(self.temp.path, method="POSIX1") fw['NX'] = NX fw['val1'] = val1 fw['val2'] = val2 fw.close() f = ad.file(self.temp.path) self.assertEqual(f['NX'][...], NX) self.assertTrue((f['val1'][:] == val1).all()) self.assertTrue((f['val2'][:] == val2).all())
def test_writer_undefined_var(self): self.temp = TempFile() NX = 10 val1 = np.array(range(NX), dtype=np.int32) val2 = np.array(range(5), dtype="f8") fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw["NX"] = NX fw["val1"] = val1 fw["val2"] = val2 fw.close() f = ad.file(self.temp.path) self.assertEqual(f["NX"][:], NX) self.assertTrue((f["val1"][:] == val1).all()) self.assertTrue((f["val2"][:] == val2).all())
def test_writer_transform(self): self.temp = TempFile() NX = 10 val1 = np.array(list(range(NX)), dtype=np.int32) val2 = np.array(list(range(5)), dtype='f8') fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw['NX'] = NX fw['val1'] = val1 fw['val2'] = val2 fw['val1'].transform = 'identity' fw.close() f = ad.file(self.temp.path) self.assertEqual(f['NX'][...], NX) self.assertTrue((f['val1'][:] == val1).all()) self.assertTrue((f['val2'][:] == val2).all())
def test_writer_timeaggregation(self): self.temp = TempFile() NX = 10 val1 = np.array(list(range(NX)), dtype=np.int32) val2 = np.array(list(range(5)), dtype='f8') fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw.set_time_aggregation(3200) fw['NX'] = NX fw['val1'] = val1 fw['val2'] = val2 fw.close() ad.finalize() f = ad.file(self.temp.path) self.assertEqual(f['NX'][...], NX) self.assertTrue((f['val1'][:] == val1).all()) self.assertTrue((f['val2'][:] == val2).all())
def test_writer_attr(self): self.temp = TempFile() NX = 10 val1 = np.array(range(NX), dtype=np.int32) val2 = np.array(range(5), dtype='f8') single_string = "ABCD" three_string = ("AA", "BBB", "CCCC") single_int = 10 five_int = np.array(range(5), dtype=np.int32) single_double = 1.1 five_double = np.array(range(5), dtype='double') * 1.1 fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw.define_attr("single_string") fw.define_attr("three_string") fw.define_attr("single_int") fw.define_attr("five_int") fw.define_attr("single_double") fw.define_attr("five_double") fw['single_string'] = single_string fw['three_string'] = three_string fw['single_int'] = single_int fw['five_int'] = five_int fw['single_double'] = single_double fw['five_double'] = five_double fw.close() f = ad.file(self.temp.path) self.assertEqual(f['single_string'].value, single_string) self.assertTrue((f['three_string'].value == three_string).all()) self.assertEqual(f['single_int'].value, single_int) self.assertTrue((f['five_int'].value == five_int).all()) self.assertEqual(f['single_double'].value, single_double) self.assertTrue((f['five_double'].value == five_double).all())
def test_writer_attr(self): self.temp = TempFile() NX = 10 val1 = np.array(range(NX), dtype=np.int32) val2 = np.array(range(5), dtype="f8") single_string = "ABCD" three_string = ("AA", "BBB", "CCCC") single_int = 10 five_int = np.array(range(5), dtype=np.int32) single_double = 1.1 five_double = np.array(range(5), dtype="double") * 1.1 fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw.define_attr("single_string") fw.define_attr("three_string") fw.define_attr("single_int") fw.define_attr("five_int") fw.define_attr("single_double") fw.define_attr("five_double") fw["single_string"] = single_string fw["three_string"] = three_string fw["single_int"] = single_int fw["five_int"] = five_int fw["single_double"] = single_double fw["five_double"] = five_double fw.close() f = ad.file(self.temp.path) self.assertEqual(f["single_string"].value, single_string) self.assertTrue((f["three_string"].value == three_string).all()) self.assertEqual(f["single_int"].value, single_int) self.assertTrue((f["five_int"].value == five_int).all()) self.assertEqual(f["single_double"].value, single_double) self.assertTrue((f["five_double"].value == five_double).all())
def test_writer_var(self): self.temp = TempFile() NX = 10 val1 = np.array(range(NX), dtype=np.int32) val2 = np.array(range(5), dtype='f8') fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw.define_var("NX") fw.define_var("val1", "NX") fw.define_var("val2", val2.shape) fw['NX'] = NX fw['val1'] = val1 fw['val2'] = val2 fw.close() f = ad.file(self.temp.path) self.assertEqual(f['NX'][...], NX) self.assertTrue((f['val1'][:] == val1).all()) self.assertTrue((f['val2'][:] == val2).all())
def test_writer_var(self): self.temp = TempFile() NX = 10 val1 = np.array(range(NX), dtype=np.int32) val2 = np.array(range(5), dtype='f8') fw = ad.writer(self.temp.path) fw.declare_group("group", method="POSIX1") fw.define_var("NX") fw.define_var("val1", "NX") fw.define_var("val2", val2.shape) fw['NX'] = NX fw['val1'] = val1 fw['val2'] = val2 fw.close() f = ad.file(self.temp.path) self.assertEqual(f['NX'][:], NX) self.assertTrue((f['val1'][:] == val1).all()) self.assertTrue((f['val2'][:] == val2).all())
""" Import ADIOS Python/Numpy wrapper """ import adios as ad import numpy as np print("\n>>> Prepare ...\n") fname = 'adios_test_writer.bp' NX = 10 size = 2 tt = np.arange(NX*size, dtype=np.float64).reshape((size, NX)) """ Writing """ print("\n>>> Writing ...\n") ad.init_noxml() ad.set_max_buffer_size (10) fw = ad.writer(fname, method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw['temperature'].transform = "zfp:accuracy=0.001" fw.attrs['/temperature/description'] = "Global array written from 'size' processes" fw.close() """ Reading """ print("\n>>> Reading ...\n") f = ad.file(fname) for key, val in f.vars.items(): print(key, '=', val.read())
import adios as ad import numpy as np print "\n>>> Prepare ...\n" fname = 'adios_test_writer.bp' NX = 10 size = 2 t = np.array(range(NX*size), dtype=np.float64) tt = t.reshape((size, NX)) print "\n>>> Writing ...\n" ad.init_noxml() ad.allocate_buffer (ad.BUFFER_ALLOC_WHEN.NOW, 10); fw = ad.writer(fname) fw.declare_group('group', method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw.attrs['/temperature/description'] = "Global array written from 'size' processes" fw.close() ## Reading print "\n>>> Reading ...\n" f = ad.file(fname) for key, val in f.vars.iteritems(): print key, '=', val.read()
import adios as ad import numpy as np print("\n>>> Prepare ...\n") fname = 'adios_test_writer.bp' NX = 10 size = 2 t = np.array(list(range(NX * size)), dtype=np.float64) tt = t.reshape((size, NX)) print("\n>>> Writing ...\n") ad.init_noxml() ad.allocate_buffer(ad.BUFFER_ALLOC_WHEN.NOW, 10) fw = ad.writer(fname) fw.declare_group('group', method='POSIX1') fw['NX'] = NX fw['size'] = size fw['temperature'] = tt fw.attrs[ '/temperature/description'] = "Global array written from 'size' processes" fw.close() ## Reading print("\n>>> Reading ...\n") f = ad.file(fname) for key, val in f.vars.items(): print(key, '=', val.read())