class_docstr: Test case which handles TPU hard placement.
class_docstr_tok: ["Test","case","which","handles","TPU","hard","placement","."]
code: def setUp(self):
      super().setUp()
  
      # Enable autograph strict mode - any autograph errors will trigger an error
      # rather than falling back to no conversion.
      os.environ["AUTOGRAPH_STRICT_CONVERSION"] = "1"
  
      self._device_types = frozenset(
          d.device_type
          for d in tf.config.experimental.list_logical_devices()
      )
      self._on_tpu = "TPU" in self._device_types
  
      # Initialize the TPU system once and only once.
      global tpu_initialized
      if tpu_initialized is None:
          with tpu_initialized_lock:
              if tpu_initialized is None and self._on_tpu:
                  tf.tpu.experimental.initialize_tpu_system()
              tpu_initialized = True
  
      if self.ENTER_PRIMARY_DEVICE:
          self._device = tf.device("/device:%s:0" % self.primary_device)
          self._device.__enter__()
  
imports: import functools
  import inspect
  import itertools
  import os
  import sys
  import threading
  import types
  from typing import Sequence, Tuple, Type, TypeVar
  from absl.testing import parameterized
  import tensorflow
label_desc: Use image node_id 1 for calling the TestCase obj's underlying member method code with example usage: obj.setUp() without return types