code: def _logical_to_physical_v1(
      sizes_and_strides,
      physical_shape,
      fn_1d=_logical_1d_to_physical_subspace_auto,
  ):
      """Maps logical m-dimensional mesh to physical n-dimensional mesh.
  
      Also see comments to _logical_1d_to_physical_subspace_auto.
  
      We are mapping a m-dimensonal logical mesh to a n-dimensional physical mesh.
  
      output[i] contains the coordinate-tuple in the physical mesh for the i-th
      logical processor (if the logical processors are ordered lexicographically).
  
      sizes_and_strides is a list of m lists of n (size, stride) pairs.
  
      sizes_and_strides[i] specifies the subspace (strided slice containing the
      origin) of the physical mesh covered by axis i of the logical mesh.  See
      comments to _logical_1d_to_physical_subspace_auto for more detail.
  
      For example, say we have a physical mesh with shape [4, 4, 2] and a logical
      mesh with shape [4, 8].  We want to divide the physical mesh into 4 tiles,
      each with shape [2, 2, 2].  The first logical dimension corresponds to which
      tile, and the second logical dimension corresponds to position within a tile.
      This would correspond to:
         physical_shape=[4, 4, 2]
         sizes_and_strides=[[(2, 2), (2, 2), (1, 2)], [(2, 1), (2, 1), (2, 1)]]
  
      physical_shape can be inferred from sizes_and_strides, but is passed in for
      error checking.
  
      Args:
        sizes_and_strides: a list of m list of n (size, stride) pairs
        physical_shape: a list of integers
        fn_1d: a function like _logical_1d_to_physical_subspace_auto
      Returns:
        a list of coordinate-lists
      """
      pndims = len(physical_shape)
      logical_shape = [
          mtf.list_product([p[0] for p in l]) for l in sizes_and_strides
      ]
      n = mtf.list_product(physical_shape)
      if n != mtf.list_product(logical_shape):
          raise ValueError(
              "logical size and physical size must match "
              "- got sizes_and_strides=%s physical_shape=%s"
              % (sizes_and_strides, physical_shape)
          )
      dimension_layouts = [
          fn_1d(l, physical_shape) for l in sizes_and_strides
      ]
      tf.logging.info("physical_shape: %s" % physical_shape)
      tf.logging.info("sizes_and_strides: %s" % sizes_and_strides)
      for i, l in enumerate(dimension_layouts):
          tf.logging.info("dimension_layout %s: %s" % (i, l))
      ret = []
      for logical_pnum in range(n):
          logical_coordinates = mtf.pnum_to_processor_coordinates(
              logical_shape, logical_pnum
          )
          physical_coordinates = [0] * pndims
          for logical_axis, logical_coord in enumerate(
              logical_coordinates
          ):
              for physical_axis in range(pndims):
                  physical_coordinates[
                      physical_axis
                  ] += dimension_layouts[logical_axis][logical_coord][
                      physical_axis
                  ]
          ret.append(physical_coordinates)
      # verify that we have indeed covered all the processors
      l2p = [
          mtf.processor_coordinates_to_pnum(physical_shape, c)
          for c in ret
      ]
      if sorted(l2p) != list(range(n)):
          raise ValueError(
              "logical_to_physical produced something that was not a permutation."
              " sizes_and_strides=%s physical_shape=%s ret=%s"
              % (sizes_and_strides, physical_shape, ret)
          )
      return ret
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import os
  import gin
  from mesh_tensorflow import ops_with_redefined_builtins
  from mesh_tensorflow import tpu_variables
  from mesh_tensorflow import utils
  from six.moves import xrange
  import tensorflow.compat.v1
  from tensorflow.python.tpu.ops import tpu_ops
label_desc: Use image node_id 3 for calling a global function with example usage: _logical_to_physical_v1(sizes_and_strides, physical_shape, fn_1d) and returns: ret