def test_save_netcdf(self): # netcdf support is optional if not ht.io.supports_netcdf(): return # local unsplit data local_data = ht.arange(100) ht.save_netcdf(local_data, self.NETCDF_OUT_PATH, self.NETCDF_VARIABLE) if local_data.comm.rank == 0: with ht.io.nc.Dataset(self.NETCDF_OUT_PATH, "r") as handle: comparison = torch.tensor( handle[self.NETCDF_VARIABLE][:], dtype=torch.int32, device=self.device.torch_device, ) self.assertTrue((local_data.larray == comparison).all()) # distributed data range split_data = ht.arange(100, split=0) ht.save_netcdf(split_data, self.NETCDF_OUT_PATH, self.NETCDF_VARIABLE) if split_data.comm.rank == 0: with ht.io.nc.Dataset(self.NETCDF_OUT_PATH, "r") as handle: comparison = torch.tensor( handle[self.NETCDF_VARIABLE][:], dtype=torch.int32, device=self.device.torch_device, ) self.assertTrue((local_data.larray == comparison).all())
def test_save_netcdf_exception(self): # netcdf support is optional if not ht.io.supports_netcdf(): return # dummy data data = ht.arange(1) with self.assertRaises(TypeError): ht.save_netcdf(1, self.NETCDF_PATH, self.NETCDF_VARIABLE) with self.assertRaises(TypeError): ht.save_netcdf(data, 1, self.NETCDF_VARIABLE) with self.assertRaises(TypeError): ht.save_netcdf(data, self.NETCDF_PATH, 1) with self.assertRaises(TypeError): ht.save_netcdf(data, self.NETCDF_PATH, self.NETCDF_VARIABLE, dimension_names=1) with self.assertRaises(ValueError): ht.save_netcdf(data, self.NETCDF_PATH, self.NETCDF_VARIABLE, dimension_names=["a", "b"])
def test_save_netcdf_exception(self): # netcdf support is optional if not ht.io.supports_netcdf(): return # dummy data data = ht.arange(1, device=ht_device) with self.assertRaises(TypeError): ht.save_netcdf(1, self.NETCDF_PATH, self.NETCDF_VARIABLE) with self.assertRaises(TypeError): ht.save_netcdf(data, 1, self.NETCDF_VARIABLE) with self.assertRaises(TypeError): ht.save_netcdf(data, self.NETCDF_PATH, 1)