code: def tune(
      col,
      backend: pipeline_backend.PipelineBackend,
      contribution_histograms: histograms.DatasetHistograms,
      options: TuneOptions,
      data_extractors: Union[
          pipeline_dp.DataExtractors, pipeline_dp.PreAggregateExtractors
      ],
      public_partitions=None,
      strategy_selector_factory: Optional[
          dp_strategy_selector.DPStrategySelectorFactory
      ] = None,
  ):
      """Tunes parameters.
  
      It works in the following way:
          1. Find candidates for contribution bounding parameters.
          2. Utility analysis run for those parameters.
          3. The best parameter set is chosen according to
            options.minimizing_function.
  
      The result contains output metrics for all utility analysis which were
      performed.
  
      For tuning parameters for DPEngine.select_partitions set
        options.aggregate_params.metrics to an empty list.
  
      Args:
          col: collection where all elements are of the same type.
            contribution_histograms:
          backend: PipelineBackend with which the utility analysis will be run.
          contribution_histograms: contribution histograms that should be
           computed with compute_contribution_histograms().
          options: options for tuning.
          data_extractors: functions that extract needed pieces of information
            from elements of 'col'. In case if the analysis performed on
            pre-aggregated data, it should have type PreAggregateExtractors
            otherwise DataExtractors.
          public_partitions: A collection of partition keys that will be present
            in the result. If not provided, tuning will be performed assuming
            private partition selection is used.
          strategy_selector_factory: factory for creating StrategySelector. If
            non provided, the DPStrategySelector will be used.
      Returns:
         returns tuple (1 element collection which contains TuneResult,
          a collection which contains utility analysis results per partition).
      """
      _check_tune_args(options, public_partitions is not None)
      if strategy_selector_factory is None:
          strategy_selector_factory = (
              dp_strategy_selector.DPStrategySelectorFactory()
          )
  
      metric = None
      if options.aggregate_params.metrics:
          metric = options.aggregate_params.metrics[0]
  
      candidates: analysis.MultiParameterConfiguration = (
          _find_candidate_parameters(
              contribution_histograms,
              options.parameters_to_tune,
              metric,
              options.number_of_parameter_candidates,
          )
      )
  
      # Add DP strategy (noise_kind, partition_selection_strategy) to multi
      # parameter configuration.
      noise_kind = None
      if not options.parameters_to_tune.noise_kind:
          noise_kind = options.aggregate_params.noise_kind
      strategy_selector = strategy_selector_factory.create(
          options.epsilon,
          options.delta,
          metric,
          is_public_partitions=public_partitions is not None,
      )
      _add_dp_strategy_to_multi_parameter_configuration(
          candidates,
          options.aggregate_params,
          noise_kind,
          strategy_selector,
      )
  
      utility_analysis_options = analysis.UtilityAnalysisOptions(
          epsilon=options.epsilon,
          delta=options.delta,
          aggregate_params=options.aggregate_params,
          multi_param_configuration=candidates,
          partitions_sampling_prob=options.partitions_sampling_prob,
          pre_aggregated_data=options.pre_aggregated_data,
      )
  
      (
          utility_result,
          per_partition_utility_result,
      ) = utility_analysis.perform_utility_analysis(
          col,
          backend,
          utility_analysis_options,
          data_extractors,
          public_partitions,
      )
      # utility_result: (UtilityReport)
      # per_partition_utility_result: (pk, (PerPartitionMetrics))
      use_public_partitions = public_partitions is not None
  
      utility_result = backend.to_list(utility_result, "To list")
      # 1 element collection with list[UtilityReport]
      utility_result = backend.map(
          utility_result,
          lambda result: _convert_utility_analysis_to_tune_result(
              result,
              options,
              candidates,
              use_public_partitions,
              contribution_histograms,
          ),
          "To Tune result",
      )
      return utility_result, per_partition_utility_result
  
imports: import logging
  import math
  from numbers import Number
  import pipeline_dp
  from pipeline_dp import dp_computations
  from pipeline_dp import pipeline_backend
  from pipeline_dp import input_validators
  from pipeline_dp.dataset_histograms import histograms
  import analysis
  from analysis import metrics
  from analysis import utility_analysis
  from analysis import dp_strategy_selector
  import dataclasses
  from dataclasses import dataclass
  from typing import Callable, List, Optional, Tuple, Union, Sequence
  from enum import Enum
  import numpy
label_desc: Use image node_id 6 for calling a global function with example usage: tune(col, backend, contribution_histograms, options, data_extractors, public_partitions, strategy_selector_factory) and returns: utility_result,  per_partition_utility_result