def test_fetch(self): vec = array(range(100), uint32) n = Node() n['a'] = vec na = n.fetch('a') na_val = na.value() self.assertEqual(na_val[99], 99)
def test_julia_nestsets(self): n = Node() info = Node() self.assertTrue(blueprint.verify("mesh", n, info)) self.assertTrue(self.has_empty_warning(info)) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertTrue(self.has_empty_warning(info)) # simple case blueprint.mesh.examples.julia_nestsets_simple(-2.0, 2.0, -2.0, 2.0, 0.285, 0.01, n) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertFalse(self.has_empty_warning(info)) n_idx = Node() blueprint.mesh.generate_index(n["domain_000000"], "", 1, n_idx) self.assertTrue(blueprint.verify("mesh/index", n_idx, info)) self.assertTrue( blueprint.mesh.verify(protocol="index", node=n_idx, info=info)) # complex case blueprint.mesh.examples.julia_nestsets_complex(50, 50, -2.0, 2.0, -2.0, 2.0, 0.285, 0.01, 3, n) self.assertTrue(blueprint.mesh.verify(n, info)) n_idx = Node() blueprint.mesh.generate_index(n["domain_000000"], "", 1, n_idx) self.assertTrue(blueprint.verify("mesh/index", n_idx, info)) self.assertTrue( blueprint.mesh.verify(protocol="index", node=n_idx, info=info))
def test_partition(self): def same(a, b): for i in range(len(a)): if a[i] != b[i]: return False return True n = Node() blueprint.mesh.examples.spiral(4, n) output = Node() options = Node() options["target"] = 2 options["mapping"] = 0 conduit.blueprint.mesh.partition(n, options, output) self.assertTrue(options.number_of_children() == 2) expected_x0 = (0., 1., 2.) expected_y0 = (0., 1., 2., 3.) expected_x1 = (-3.0, -2.0, -1.0, 0.0) expected_y1 = (0.0, 1.0, 2.0, 3.0) self.assertTrue( same(expected_x0, output[0]["coordsets/coords/values/x"])) self.assertTrue( same(expected_y0, output[0]["coordsets/coords/values/y"])) self.assertTrue( same(expected_x1, output[1]["coordsets/coords/values/x"])) self.assertTrue( same(expected_y1, output[1]["coordsets/coords/values/y"]))
def test_save_merged(self): a_val = int64(10) b_val = int64(20) c_val = float64(30.0) d_val = a_val * 4 # n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val tout = "tout_python_relay_io_save_merged.conduit_bin" if os.path.isfile(tout): os.remove(tout) if os.path.isfile(tout + "_json"): os.remove(tout + "_json") relay.io.save_merged(n, tout) self.assertTrue(os.path.isfile(tout)) self.assertTrue(os.path.isfile(tout + "_json")) n2 = Node() n2['d'] = d_val relay.io.save_merged(n2, tout) self.assertTrue(os.path.isfile(tout)) n_load = Node() relay.io.load(n_load, tout) print(n_load) self.assertTrue(n_load.has_child("d")) self.assertTrue(n_load.has_child("a")) self.assertTrue(n_load['a'] == a_val) self.assertTrue(n_load['d'] == d_val)
def test_numpy_slice_as_set_external_input(self): n = Node() # slice with non trivial strides numpy_array = np.array(range(21), dtype='float64') v = numpy_array.reshape((3, 7)) print("Input Array") print(v) print("Desired Slice") print(v[:, 0]) n['v'] = v n['vs'].set_external(v[:, 0]) n['vs_expected'] = np.array(v[:, 0], np.float64) print(n) sdiff = np.setdiff1d(n['vs'], v[:, 0]) print("Set Difference: ", sdiff) self.assertEqual(len(sdiff), 0) # a more complex slice, can't use set external here. n = Node() numpy_array = np.array(range(105), dtype='float64') v = numpy_array.reshape((3, 7, 5)) with self.assertRaises(TypeError): n['vs'].set_external(v[:, 0, 3:5]) # lets do a 1-d eff slice, this should work since # it reduces to a 1-D strided case n['vs'].set_external(v[:, 0, 0]) n['vs_expected'] = np.array(v[:, 0, 0], np.float64)
def test_info(self): n = Node() n['a'] = 1 n['b'] = 2 n['c'] = 3 ni = n.info(); #print ni self.assertEqual(ni["total_bytes"],n.total_bytes())
def test_info(self): n = Node() n['a'] = 1 n['b'] = 2 n['c'] = 3 ni = n.info() #print ni self.assertEqual(ni["total_strided_bytes"], n.total_strided_bytes())
def test_polychain(self): n = Node() info = Node() # simple case blueprint.mesh.examples.polychain(5, n) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertFalse(self.has_empty_warning(info))
def test_total_bytes(self): vec = array(range(100), uint32) n = Node() n['a'] = vec self.assertEqual(n.total_strided_bytes(), 4 * 100) self.assertEqual(n.total_bytes_compact(), 4 * 100) # TODO: check if n.is_compact() should pass as well? # it doesn't currently self.assertTrue(n.fetch('a').is_compact())
def test_total_bytes(self): vec = array(range(100), uint32) n = Node() n['a'] = vec self.assertEqual(n.total_bytes(),4 * 100) self.assertEqual(n.total_bytes_compact(),4 * 100) # TODO: check if n.is_compact() should pass as well? # it doesn't currently self.assertTrue(n.fetch('a').is_compact())
def test_child(self): vec = array(range(100), uint32) n = Node() n['a'] = vec na = n.child(0) na_val = na.value() self.assertEqual(na_val[99], 99) n['b'] = vec self.assertEqual(n.number_of_children(), 2)
def test_reset(self): n = Node() data = np.array(range(10), dtype='float64') n["data"].set_external(data) print(n) n.reset() self.assertEqual(n.number_of_children(), 0)
def test_child(self): vec = array(range(100), uint32) n = Node() n['a'] = vec na = n.child(0) na_val = na.value() self.assertEqual(na_val[99], 99) n['b'] = vec self.assertEqual(n.number_of_children(),2)
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val s = n.schema(); self.assertEqual(s.total_strided_bytes(),16)
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val s = n.schema() self.assertEqual(s.total_strided_bytes(), 16)
def test_set_all_types(self): types = [ 'int8', 'int16', 'int32', 'int64', 'uint8', 'uint16', 'uint32', 'uint64', 'float32', 'float64'] for type in types: data = array(range(10), dtype=type) n = Node() n.set(data) for i in range(len(data)): self.assertEqual(n.value()[i], data[i])
def test_create_node_using_schema_object(self): s = Schema() s["a"] = DataType.float64(10) s["b"] = DataType.float32(10) n = Node() n.set(s) sr = n.schema() self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10) self.assertEqual(sr["a"].total_strided_bytes(),8 * 10) self.assertEqual(sr["b"].total_strided_bytes(),4 * 10)
def test_paths(self): n = Node() n['a'] = 1 n['b'] = 2 n['c'] = 3 for v in ['a','b','c']: self.assertTrue(n.has_path(v)) paths = n.paths() for v in ['a','b','c']: self.assertTrue(v in paths)
def test_xyz_and_verify(self): n = Node() info = Node() self.assertFalse(blueprint.verify("mcarray", n, info)) blueprint.mcarray.examples.xyz("separate", 5, n) self.assertTrue(blueprint.verify("mcarray", n, info)) self.assertTrue(blueprint.mcarray.verify(n, info)) n_int = Node() blueprint.mcarray.to_interleaved(n, n_int) self.assertTrue(blueprint.mcarray.is_interleaved(n_int))
def test_fetch_existing(self): n = Node() n["my/path"] = 10 n_sub = n.fetch_existing("my/path") self.assertEqual(n_sub.value(), 10) with self.assertRaises(Exception): n.fetch_existing('bad/path')
def test_create_node_using_schema_object(self): s = Schema() s["a"] = DataType.float64(10) s["b"] = DataType.float32(10) n = Node() n.set(s) sr = n.schema() self.assertEqual(sr.total_strided_bytes(), 8 * 10 + 4 * 10) self.assertEqual(sr["a"].total_strided_bytes(), 8 * 10) self.assertEqual(sr["b"].total_strided_bytes(), 4 * 10)
def test_paths(self): n = Node() n['a'] = 1 n['b'] = 2 n['c'] = 3 for v in ['a', 'b', 'c']: self.assertTrue(n.has_path(v)) paths = n.child_names() for v in ['a', 'b', 'c']: self.assertTrue(v in paths)
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val s = n.schema() self.assertTrue(s.is_root()) self.assertFalse(n.fetch('a').schema().is_root())
def test_spiral_and_verify(self): n = Node() info = Node() self.assertFalse(blueprint.verify("mesh",n,info)) self.assertFalse(blueprint.mesh.verify(n,info)) blueprint.mesh.examples.spiral(4,n); self.assertTrue(blueprint.mesh.verify(n["domain_000000"],info)) n_idx = Node() blueprint.mesh.generate_index(n["domain_000000"],"",4,n_idx) self.assertTrue(blueprint.verify("mesh/index",n_idx,info)) self.assertTrue(blueprint.mesh.verify(protocol="index",node=n_idx,info=info))
def test_braid_and_verify(self): n = Node() info = Node() self.assertFalse(blueprint.verify("mesh",n,info)) self.assertFalse(blueprint.mesh.verify(n,info)) blueprint.mesh.examples.braid("hexs",2,2,2,n); self.assertTrue(blueprint.mesh.verify(n,info)) n_idx = Node() blueprint.mesh.generate_index(n,"",1,n_idx) self.assertTrue(blueprint.verify("mesh/index",n_idx,info)) self.assertTrue(blueprint.mesh.verify(protocol="index",node=n_idx,info=info))
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val s = n.schema(); self.assertTrue(s.is_root()) self.assertFalse(n.fetch('a').schema().is_root())
def test_polytess(self): n = Node() info = Node() # 2D case blueprint.mesh.examples.polytess(3, 1, n) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertFalse(self.has_empty_warning(info)) # 3D case blueprint.mesh.examples.polytess(3, 3, n) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertFalse(self.has_empty_warning(info))
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val print(n) d = n.fetch('a').dtype() self.assertEqual(d.id(), DataType.name_to_id("uint32")) print(d)
def test_julia_and_verify(self): n = Node() info = Node() self.assertFalse(blueprint.verify("mesh", n, info)) self.assertFalse(blueprint.mesh.verify(n, info)) blueprint.mesh.examples.julia(200, 200, -2.0, 2.0, -2.0, 2.0, 0.285, 0.01, n) self.assertTrue(blueprint.mesh.verify(n, info)) n_idx = Node() blueprint.mesh.generate_index(n, "", 1, n_idx) self.assertTrue(blueprint.verify("mesh/index", n_idx, info)) self.assertTrue( blueprint.mesh.verify(protocol="index", node=n_idx, info=info))
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n['a'] = a_val n['b'] = b_val n['c'] = c_val print(n) d = n.fetch('a').dtype() self.assertEqual(d.id(),DataType.name_to_id("uint32")) print(d)
def test_list(self): n = Node() n.append().set(1) self.assertTrue(n.child(0).value(), 1) # TODO: this needs to work but doesn't #self.assertTrue(n[0],1) n2 = Node() n2_c = n2.append() n2_c.set(2) self.assertEqual(n2.child(0).value(), 2)
def test_relay_io_blueprint_save_load_mesh(self): # only run if we have hdf5 if not relay.io.about()["protocols/hdf5"] == "enabled": return data = Node() blueprint.mesh.examples.julia(200, 200, -2.0, 2.0, -2.0, 2.0, 0.285, 0.01, data) data["state/cycle"] = 0 tbase = "tout_python_relay_io_blueprint_mesh_t1" tout = tbase + ".cycle_000000.root" if os.path.isfile(tout): os.remove(tout) print("saving to {0}".format(tout)) relay.io.blueprint.save_mesh(data, tbase, "hdf5") self.assertTrue(os.path.isfile(tout)) n_load = Node() info = Node() n_load["HERE_IS_SOMETHING_BEFORE_WE_LOAD"] = 1 relay.io.blueprint.load_mesh(n_load, tout) # with load sematics, the input node is cleared, so this # child should no longer exist self.assertFalse(n_load.has_child("HERE_IS_SOMETHING_BEFORE_WE_LOAD")) print(n_load) data.diff(n_load, info) print(info)
def test_improper_calls(self): args = Node() maps = Node() # check for error with trying to call with no args or map with self.assertRaises(Exception): conduit.utils.format(pattern= "") # check for error with trying to call both styles with self.assertRaises(Exception): conduit.utils.format(pattern= "", args = args, maps = maps, map_index = 0)
def test_bad_args(self): args = Node() # args empty, throw exception with self.assertRaises(Exception): conduit.utils.format("{a} {b} {c} {d} {e} {f}", args = args) # args is not a node args = 32 with self.assertRaises(Exception): conduit.utils.format("{a} {b} {c} {d} {e} {f}", args = args) # args not an obj or list, throw exception args = Node() args.set(32) with self.assertRaises(Exception): conduit.utils.format("{a} {b} {c} {d} {e} {f}", args = args) # too little args for fmt string args.reset() args["a"] = 10; with self.assertRaises(Exception): conduit.utils.format("{a} {b} {c} {d} {e} {f}", args = args)
def test_remove(self): n = Node() n['a'] = 1 n['b'] = 2 n['c'] = 3 self.assertEqual(n.number_of_children(), 3) n.remove(path='c') self.assertEqual(n.number_of_children(), 2) paths = n.child_names() for v in ['a', 'b']: self.assertTrue(v in paths) n.remove(index=0) paths = n.child_names() for v in ['b']: self.assertTrue(v in paths)
def test_basic_and_verify(self): n = Node() info = Node() self.assertTrue(blueprint.verify("mesh", n, info)) self.assertTrue(self.has_empty_warning(info)) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertTrue(self.has_empty_warning(info)) blueprint.mesh.examples.basic("hexs", 2, 2, 2, n) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertFalse(self.has_empty_warning(info)) n_idx = Node() blueprint.mesh.generate_index(n, "", 1, n_idx) self.assertTrue(blueprint.verify("mesh/index", n_idx, info)) self.assertTrue( blueprint.mesh.verify(protocol="index", node=n_idx, info=info))
def test_polytess(self): n = Node() info = Node() self.assertTrue(blueprint.verify("mesh", n, info)) self.assertTrue(self.has_empty_warning(info)) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertTrue(self.has_empty_warning(info)) # simple case blueprint.mesh.examples.polytess(3, n) self.assertTrue(blueprint.mesh.verify(n, info)) self.assertFalse(self.has_empty_warning(info)) n_idx = Node() blueprint.mesh.generate_index(n, "", 1, n_idx) self.assertTrue(blueprint.verify("mesh/index", n_idx, info)) self.assertTrue( blueprint.mesh.verify(protocol="index", node=n_idx, info=info))
def test_numpy_slice_as_set_input(self): n = Node() # slice with non trivial strides numpy_array = np.array(range(21), dtype='float64') v = numpy_array.reshape((3, 7)) print("Input Array") print(v) print("Desired Slice") print(v[:, 0]) n['v'] = v n['vs'] = v[:, 0] n['vs_expected'] = np.array(v[:, 0], np.float64) print(n) sdiff = np.setdiff1d(n['vs'], v[:, 0]) print("Set Difference: ", sdiff) self.assertEqual(len(sdiff), 0) # a more complex slice numpy_array = np.array(range(105), dtype='float64') v = numpy_array.reshape((3, 7, 5)) print("Input Array") print(v) print("Desired Slice") print(v[:, 0, 3:5]) n['v'] = v n['vs'] = v[:, 0, 3:5] n['vs_expected'] = np.array(v[:, 0, 3:5], np.float64) print(n) sdiff = np.setdiff1d(n['vs'], v[:, 0, 3:5]) print("Set Difference: ", sdiff) self.assertEqual(len(sdiff), 0)
def test_remove(self): n = Node() n['a'] = 1 n['b'] = 2 n['c'] = 3 self.assertEqual(n.number_of_children(),3) n.remove(path='c') self.assertEqual(n.number_of_children(),2) paths = n.paths() for v in ['a','b']: self.assertTrue(v in paths) n.remove(index=0) paths = n.paths() for v in ['b']: self.assertTrue(v in paths)
def test_set_external(self): types = ['uint8', 'uint16', 'uint32', 'uint64', 'float32', 'float64'] for type in types: ext_data = array(range(10), dtype=type) n = Node() n.set_external(ext_data) for i in range(len(ext_data)): self.assertEqual(n.value()[i], ext_data[i]) ext_data[5] = 11 n.value()[8] = 77 n.value()[2] = 8 for i in range(len(ext_data)): self.assertEqual(n.value()[i], ext_data[i])
def test_base64(self): n = default_node() print(n) n_schema = n.to_json("base64_json"); print("result base64 json", n_schema) g = Generator(n_schema,"base64_json"); ng = Node(); g.walk(node=ng); print("Generator result") print(ng) for p in ["a","b","c"]: orig = n.fetch(p).value() curr = ng.fetch(p).value() print(ng) print(p, orig, curr) orig = n[p] curr = ng[p] print(ng) print(p, orig, curr) self.assertEqual(orig,curr)
def test_list(self): n = Node() n.append().set(1) self.assertTrue(n.child(0).value(),1) # TODO: this needs to work but doesn't #self.assertTrue(n[0],1) n2 = Node() n2_c = n2.append() n2_c.set(2) self.assertEqual(n2.child(0).value(),2)
def test_simple(self): n = default_node() n_schema = n.to_json("conduit"); print("result detailed json", n_schema) g = Generator(json_schema=n_schema); ng = Node(); sg = Schema() g.walk(node=ng); g.walk(schema=sg); print(ng) print(sg) for p in ["a","b","c"]: orig = n.fetch(p).value() curr = ng.fetch(p).value() print(ng) print(p, orig, curr) orig = n[p] curr = ng[p] print(ng) print(p, orig, curr) self.assertEqual(orig,curr)
def test_set_external_basic_slice(self): types = ['uint8', 'uint16', 'uint32', 'uint64', 'float32', 'float64'] for type in types: base_data = array(range(20), dtype=type) ext_data = base_data[1:16] n = Node() n.set_external(ext_data) for i in range(len(ext_data)): self.assertEqual(n.value()[i], ext_data[i]) ext_data[5] = 11 n.value()[6] = 77 n.value()[2] = 8 for i in range(len(ext_data)): self.assertEqual(n.value()[i], ext_data[i])
def test_simple(self): a_val = uint32(10) b_val = uint32(20) c_val = float64(30.0) n = Node() n["a"] = a_val n["b"] = b_val n["c"] = c_val itr = NodeIterator() self.assertFalse(itr.has_next()) itr = n.children() self.assertTrue(itr.has_next()) print(itr.has_next()) for v in itr: print(v.name(), v.node()) idx = v.index() if idx == 0: self.assertEqual(v.node().value(), a_val) elif idx == 1: self.assertEqual(v.node().value(), b_val) elif idx == 2: self.assertEqual(v.node().value(), c_val)
def test_save_load(self): vec = array(range(100), uint32) n = Node() n['a'] = vec n.save("test_pyconduit_node_save_load") nl = Node() nl.load("test_pyconduit_node_save_load") self.assertEqual(nl['a'][99], 99) n.save("test_pyconduit_node_json_save_load",protocol="json") nl = Node() nl.load("test_pyconduit_node_json_save_load", protocol="json") n.save("test_pyconduit_node_base64_json_save_load", protocol="base64_json") nl = Node() nl.load("test_pyconduit_node_base64_json_save_load", protocol="base64_json") self.assertEqual(nl['a'][99], 99)
def test_parent(self): vec = array(range(100), uint32) n = Node() n['a'] = vec na = n.fetch('a') self.assertFalse(na.is_root())