1# Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================= 15 16"""Tests for topology.py.""" 17 18from tensorflow.python.platform import test 19from tensorflow.python.tpu import topology 20 21 22class TopologyTest(test.TestCase): 23 24 def testSerialization(self): 25 """Tests if the class is able to generate serialized strings.""" 26 original_topology = topology.Topology( 27 mesh_shape=[1, 1, 1, 2], 28 device_coordinates=[[[0, 0, 0, 0], [0, 0, 0, 1]]], 29 ) 30 serialized_str = original_topology.serialized() 31 new_topology = topology.Topology(serialized=serialized_str) 32 33 # Make sure the topology recovered from serialized str is same as the 34 # original topology. 35 self.assertAllEqual( 36 original_topology.mesh_shape, new_topology.mesh_shape) 37 self.assertAllEqual( 38 original_topology.device_coordinates, new_topology.device_coordinates) 39 40if __name__ == "__main__": 41 test.main() 42