code: def test_model_save(tmpdir):
      save_path_dir = str(tmpdir)
  
      @mb.program(input_specs=[mb.TensorSpec(shape=(10, 20))])
      def prog(x):
          x = mb.square(x=x)
          return x
  
      # save neuralnetwork model without extension and check that it is saved with
      # mlmodel extension
      mlmodel = ct.convert(prog, convert_to="neuralnetwork")
      mlmodel_path = os.path.join(save_path_dir, "model_nn")
      mlmodel.save(mlmodel_path)
      assert os.path.exists(mlmodel_path + ".mlmodel")
  
      # save neuralnetwork model with mlpackage extension
      mlmodel_path = os.path.join(save_path_dir, "model_nn2.mlpackage")
      mlmodel.save(mlmodel_path)
      assert os.path.exists(mlmodel_path)
  
      # save mlprogram model without extension and check that it is saved with
      # mlpackage extension
      mlmodel = ct.convert(prog, convert_to="mlprogram")
      mlmodel_path = os.path.join(save_path_dir, "model_mlprogram")
      mlmodel.save(mlmodel_path)
      assert os.path.exists(mlmodel_path + ".mlpackage")
  
      # check error if mlprogram is saved with mlmodel extension
      mlmodel_path = os.path.join(
          save_path_dir, "model_mlprogram.mlmodel"
      )
      expected_pattern = "For an ML Program\, extension must be \.mlpackage \(not \.mlmodel\)\. Please see .* to see the difference between neuralnetwork and mlprogram model types\."
      with pytest.raises(Exception, match=expected_pattern):
          mlmodel.save(mlmodel_path)
  
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 TestMLProgramConverterExamples obj's underlying member method code with example usage: obj.test_model_save(tmpdir) and returns: x