code: def test_compute_precision_api():
      @mb.program(input_specs=[mb.TensorSpec(shape=(10, 20))])
      def prog(x):
          x = mb.square(x=x)
          return x
  
      mlmodel = ct.convert(
          copy.deepcopy(prog),
          compute_precision=ct.precision.FLOAT16,
          convert_to="mlprogram",
      )
      mil_prog = mlmodel._get_mil_internal()
      np.testing.assert_array_equal(
          ["cast", "square", "cast"], get_op_types_in_program(mil_prog)
      )
  
      mlmodel = ct.convert(
          copy.deepcopy(prog),
          compute_precision=ct.precision.FLOAT32,
          convert_to="mlprogram",
      )
      mil_prog = mlmodel._get_mil_internal()
      np.testing.assert_array_equal(
          ["square"], get_op_types_in_program(mil_prog)
      )
  
      mlmodel = ct.convert(
          copy.deepcopy(prog),
          compute_precision=ct.transform.FP16ComputePrecision(
              op_selector=lambda op: op.op_type != "square"
          ),
          convert_to="mlprogram",
      )
      mil_prog = mlmodel._get_mil_internal()
      np.testing.assert_array_equal(
          ["square"], get_op_types_in_program(mil_prog)
      )
  
      with pytest.raises(ValueError) as e:
          mlmodel = ct.convert(
              copy.deepcopy(prog),
              compute_precision="fp64",
              convert_to="mlprogram",
          )
      expected_error = (
          "'compute_precision' must be either coremltools.precision.FLOAT32 or "
          "coremltools.precision.FLOAT16 or of type coremltools.transform.FP16ComputePrecision()"
      )
      assert expected_error == str(e.value)
  
      expected_pattern = "compute_precision .* supported .* mlprogram .* None .* target=='neuralnetwork'.*minimum_deployment_target.*"
      with pytest.raises(ValueError, match=expected_pattern) as e:
          mlmodel = ct.convert(
              copy.deepcopy(prog),
              convert_to="neuralnetwork",
              compute_precision="fp16",
          )
  
imports: import copy
  import os
  import tempfile
  import numpy
  import pytest
  import coremltools
  from coremltools._deps import _HAS_TORCH
  from coremltools.converters.mil import Builder
  from coremltools.converters.mil.mil import Function, Program, get_new_symbol
  from coremltools.converters.mil.testing_utils import get_op_types_in_program
label_desc: Use image node_id 1 for calling the TestMLProgramFP16Transform obj's underlying member method code with example usage: obj.test_compute_precision_api() and returns: x