docstr: Since the  compute_precision argument is only applicable when converting to "mlprogram",
  check that an error is correctly raised when conversion is targeted at the neuralnetwork backend
docstr_tok: ["Since","the","compute_precision","argument","is","only","applicable","when","converting","to","``","mlprogram","''",",","check","that","an","error","is","correctly","raised","when","conversion","is","targeted","at","the","neuralnetwork","backend"]
code: def test_invalid_argument_nn_backend():
      """
      Since the  compute_precision argument is only applicable when converting to "mlprogram",
      check that an error is correctly raised when conversion is targeted at the neuralnetwork backend
      """
  
      @mb.program(input_specs=[mb.TensorSpec(shape=(10, 20))])
      def prog(x):
          x = mb.square(x=x)
          return x
  
      expected_err_str = "compute_precision is only supported for mlprogram target and must be None if target.*"
      with pytest.raises(ValueError, match=expected_err_str):
          mlmodel = ct.convert(
              prog,
              convert_to="neuralnetwork",
              compute_precision=ct.precision.FLOAT16,
          )
      with pytest.raises(ValueError, match=expected_err_str):
          mlmodel = ct.convert(
              prog,
              convert_to="neuralnetwork",
              compute_precision=ct.precision.FLOAT32,
          )
  
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 2 for calling the TestMLProgramFP16Transform obj's underlying member method code with example usage: obj.test_invalid_argument_nn_backend() and returns: x