code: def testVirtualGpu(self):
      config.set_soft_device_placement(False)
      gpus = config.list_physical_devices("GPU")
      self.assertNotEqual(len(gpus), 0)
  
      self.assertIsNone(
          config.get_logical_device_configuration(gpus[-1])
      )
      config.set_logical_device_configuration(
          gpus[-1],
          [
              context.LogicalDeviceConfiguration(memory_limit=10),
              context.LogicalDeviceConfiguration(memory_limit=10),
          ],
      )
      self.assertEqual(
          len(config.get_logical_device_configuration(gpus[-1])), 2
      )
  
      logical_gpus = config.list_logical_devices("GPU")
      self.assertTrue(len(logical_gpus), len(gpus) + 1)
      for i in range(0, len(logical_gpus)):
          with ops.device("/device:GPU:" + str(i)):
              a = array_ops.identity(1.0)
              self.evaluate(a)
  
      with self.assertRaisesRegex(
          errors.InvalidArgumentError, "Could not satisfy"
      ):
          with ops.device("/device:GPU:" + str(len(logical_gpus))):
              a = array_ops.identity(1.0)
              self.evaluate(a)
  
      # Modifying the GPU configuration is not supported
      with self.assertRaisesRegex(RuntimeError, "cannot be modified"):
          config.set_logical_device_configuration(
              gpus[-1],
              [
                  context.LogicalDeviceConfiguration(memory_limit=20),
                  context.LogicalDeviceConfiguration(memory_limit=20),
              ],
          )
  
      with self.assertRaisesRegex(RuntimeError, "cannot be modified"):
          config.set_logical_device_configuration(
              gpus[-1],
              [
                  context.LogicalDeviceConfiguration(memory_limit=10),
                  context.LogicalDeviceConfiguration(memory_limit=10),
                  context.LogicalDeviceConfiguration(memory_limit=10),
              ],
          )
  
      # Setting the same GPU configuration is fine
      config.set_logical_device_configuration(
          gpus[-1],
          [
              context.LogicalDeviceConfiguration(memory_limit=10),
              context.LogicalDeviceConfiguration(memory_limit=10),
          ],
      )
  
imports: from absl.testing import parameterized
  from tensorflow.core.protobuf import cluster_pb2
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.core.protobuf import rewriter_config_pb2
  from tensorflow.core.protobuf import tensorflow_server_pb2
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import config
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.platform import test
  from tensorflow.python.util import compat
label_desc: Use image node_id 7 for calling the DeviceTest obj's underlying member method code with example usage: obj.testVirtualGpu() without return types