code: def test_optimizer_errors(self):
      opt = 1
      expected_regex = (
          '"opt" must be an instance of a tf.train.Optimizer or '
          "a tf.keras.optimizers.Optimizer, but got"
      )
      with self.assertRaisesRegex(ValueError, expected_regex):
          mixed_precision.enable_mixed_precision_graph_rewrite_v1(opt)
      self.assertFalse(
          config.get_optimizer_experimental_options().get(
              "auto_mixed_precision", False
          )
      )
  
      opt = gradient_descent_v1.GradientDescentOptimizer(1.0)
      opt = loss_scale_optimizer_v1.MixedPrecisionLossScaleOptimizer(
          opt, "dynamic"
      )
      with self.assertRaisesRegex(
          ValueError,
          '"opt" must not already be an instance of a '
          "MixedPrecisionLossScaleOptimizer.",
      ):
          mixed_precision.enable_mixed_precision_graph_rewrite_v1(opt)
      self.assertFalse(
          config.get_optimizer_experimental_options().get(
              "auto_mixed_precision", False
          )
      )
  
imports: import os
  from absl.testing import parameterized
  from tensorflow.core.protobuf import config_pb2
  from tensorflow.python.client import session
  from tensorflow.python.eager import context
  from tensorflow.python.eager import def_function
  from tensorflow.python.framework import config
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
  from tensorflow.python.platform import tf_logging
  from tensorflow.python.training import gradient_descent
  from tensorflow.python.training.experimental import loss_scale_optimizer
  from tensorflow.python.training.experimental import mixed_precision
  from tensorflow.python.training.experimental import mixed_precision_global_state
label_desc: Use image node_id 4 for calling the MixedPrecisionTest obj's underlying member method code with example usage: obj.test_optimizer_errors() without return types