code: def save_model(
      sktime_model,
      path,
      conda_env=None,
      code_paths=None,
      mlflow_model=None,
      signature=None,
      input_example=None,
      pip_requirements=None,
      extra_pip_requirements=None,
      serialization_format=SERIALIZATION_FORMAT_PICKLE,
  ):  # TODO: can we specify a type for fitted instance of sktime model below?
      """Save a sktime model to a path on the local file system.
  
      Parameters
      ----------
      sktime_model :
          Fitted sktime model object.
      path : str
          Local path where the model is to be saved.
      conda_env : Union[dict, str], optional (default=None)
          Either a dictionary representation of a Conda environment or the path to a
          conda environment yaml file.
      code_paths : array-like, optional (default=None)
          A list of local filesystem paths to Python file dependencies (or directories
          containing file dependencies). These files are *prepended* to the system path
          when the model is loaded.
      mlflow_model: mlflow.models.Model, optional (default=None)
          mlflow.models.Model configuration to which to add the python_function flavor.
      signature : mlflow.models.signature.ModelSignature, optional (default=None)
          Model Signature mlflow.models.ModelSignature describes
          model input and output :py:class:`Schema <mlflow.types.Schema>`. The model
          signature can be :py:func:`inferred <mlflow.models.infer_signature>` from
          datasets with valid model input (e.g. the training dataset with target column
          omitted) and valid model output (e.g. model predictions generated on the
          training dataset), for example:
  
          .. code-block:: py
  
            from mlflow.models.signature import infer_signature
            train = df.drop_column("target_label")
            predictions = ... # compute model predictions
            signature = infer_signature(train, predictions)
  
          .. Warning:: if performing probabilistic forecasts (``predict_interval``,
            ``predict_quantiles``) with a sktime model, the signature
            on the returned prediction object will not be correctly inferred due
            to the Pandas MultiIndex column type when using the these methods.
            ``infer_schema`` will function correctly if using the ``pyfunc`` flavor
            of the model, though.
      input_example : Union[pandas.core.frame.DataFrame, numpy.ndarray, dict, list, csr_matrix, csc_matrix], optional (default=None)
          Input example provides one or several instances of valid model input.
          The example can be used as a hint of what data to feed the model. The given
          example will be converted to a ``Pandas DataFrame`` and then serialized to json
          using the ``Pandas`` split-oriented format. Bytes are base64-encoded.
      pip_requirements : Union[Iterable, str], optional (default=None)
          Either an iterable of pip requirement strings
          (e.g. ["sktime", "-r requirements.txt", "-c constraints.txt"]) or the string
          path to a pip requirements file on the local filesystem
          (e.g. "requirements.txt")
      extra_pip_requirements : Union[Iterable, str], optional (default=None)
          Either an iterable of pip requirement strings
          (e.g. ["pandas", "-r requirements.txt", "-c constraints.txt"]) or the string
          path to a pip requirements file on the local filesystem
          (e.g. "requirements.txt")
      serialization_format : str, optional (default="pickle")
          The format in which to serialize the model. This should be one of the formats
          "pickle" or "cloudpickle"
  
      References
      ----------
      .. [1] https://www.mlflow.org/docs/latest/python_api/mlflow.models.html#mlflow.models.Model.save
  
      Examples
      --------
      >>> from sktime.datasets import load_airline  # doctest: +SKIP
      >>> from sktime.forecasting.arima import ARIMA  # doctest: +SKIP
      >>> from sktime.utils import mlflow_sktime  # doctest: +SKIP
      >>> y = load_airline()  # doctest: +SKIP
      >>> forecaster = ARIMA(  # doctest: +SKIP
      ...     order=(1, 1, 0),
      ...     seasonal_order=(0, 1, 0, 12),
      ...     suppress_warnings=True)
      >>> forecaster.fit(y)  # doctest: +SKIP
      ARIMA(...)
      >>> model_path = "model"  # doctest: +SKIP
      >>> mlflow_sktime.save_model(  # doctest: +SKIP
      ...     sktime_model=forecaster,
      ...     path=model_path)  # doctest: +SKIP
      >>> loaded_model = mlflow_sktime.load_model(model_uri=model_path)  # doctest: +SKIP
      >>> loaded_model.predict(fh=[1, 2, 3])  # doctest: +SKIP
      """  # noqa: E501
      _check_mlflow_dependencies(severity="error")
      from mlflow.exceptions import MlflowException
      from mlflow.models import Model
      from mlflow.models.model import MLMODEL_FILE_NAME
      from mlflow.models.utils import _save_example
      from mlflow.protos.databricks_pb2 import INVALID_PARAMETER_VALUE
      from mlflow.utils.environment import (
          _CONDA_ENV_FILE_NAME,
          _CONSTRAINTS_FILE_NAME,
          _PYTHON_ENV_FILE_NAME,
          _REQUIREMENTS_FILE_NAME,
          _process_conda_env,
          _process_pip_requirements,
          _PythonEnv,
          _validate_env_arguments,
      )
      from mlflow.utils.file_utils import write_to
      from mlflow.utils.model_utils import (
          _validate_and_copy_code_paths,
          _validate_and_prepare_target_save_path,
      )
  
      _validate_env_arguments(
          conda_env, pip_requirements, extra_pip_requirements
      )
  
      if serialization_format not in SUPPORTED_SERIALIZATION_FORMATS:
          raise MlflowException(
              message=(
                  "Unrecognized serialization format: {serialization_format}. "
                  "Please specify one of the following supported formats: "
                  "{supported_formats}.".format(
                      serialization_format=serialization_format,
                      supported_formats=SUPPORTED_SERIALIZATION_FORMATS,
                  )
              ),
              error_code=INVALID_PARAMETER_VALUE,
          )
  
      _validate_and_prepare_target_save_path(path)
      code_dir_subpath = _validate_and_copy_code_paths(code_paths, path)
  
      if mlflow_model is None:
          mlflow_model = Model()
      if signature is not None:
          mlflow_model.signature = signature
      if input_example is not None:
          _save_example(mlflow_model, input_example, path)
  
      model_data_subpath = "model"
      model_data_path = os.path.join(path, model_data_subpath)
      _save_model(
          sktime_model,
          model_data_path,
          serialization_format=serialization_format,
      )
  
      pyfunc.add_to_model(
          mlflow_model,
          loader_module="sktime.utils.mlflow_sktime",
          model_path=model_data_subpath,
          conda_env=_CONDA_ENV_FILE_NAME,
          python_env=_PYTHON_ENV_FILE_NAME,
          code=code_dir_subpath,
      )
  
      mlflow_model.add_flavor(
          FLAVOR_NAME,
          pickled_model=model_data_subpath,
          sktime_version=sktime.__version__,
          serialization_format=serialization_format,
          code=code_dir_subpath,
      )
      mlflow_model.save(os.path.join(path, MLMODEL_FILE_NAME))
  
      if conda_env is None:
          if pip_requirements is None:
              include_cloudpickle = (
                  serialization_format
                  == SERIALIZATION_FORMAT_CLOUDPICKLE
              )
              default_reqs = get_default_pip_requirements(
                  include_cloudpickle
              )
              default_reqs = sorted(default_reqs)
          else:
              default_reqs = None
          (
              conda_env,
              pip_requirements,
              pip_constraints,
          ) = _process_pip_requirements(
              default_reqs, pip_requirements, extra_pip_requirements
          )
      else:
          (
              conda_env,
              pip_requirements,
              pip_constraints,
          ) = _process_conda_env(conda_env)
  
      with open(os.path.join(path, _CONDA_ENV_FILE_NAME), "w") as f:
          yaml.safe_dump(conda_env, stream=f, default_flow_style=False)
  
      if pip_constraints:
          write_to(
              os.path.join(path, _CONSTRAINTS_FILE_NAME),
              "\n".join(pip_constraints),
          )
  
      write_to(
          os.path.join(path, _REQUIREMENTS_FILE_NAME),
          "\n".join(pip_requirements),
      )
  
      _PythonEnv.current().to_yaml(
          os.path.join(path, _PYTHON_ENV_FILE_NAME)
      )
  
file_path: sktime/sktime/utils/mlflow_sktime.py
imports: import logging
  import os
  import pandas
  import yaml
  import sktime
  from sktime import utils
  from sktime.base._serialize import load
  from sktime.utils.multiindex import flatten_multiindex
  from sktime.utils.validation._dependencies import _check_mlflow_dependencies
label_desc: Use image node_id 3 for calling a global function with example usage: save_model(sktime_model, path, conda_env, code_paths, mlflow_model, signature, input_example, pip_requirements, extra_pip_requirements, serialization_format) without return types