code: def test_silverkite_ad_result(daily_data, forecast_config_info_daily):
      """Tests pickling and unpickling of Greykite anomaly detector."""
      df_train = daily_data["df_train"]
      df_test = daily_data["df_test"]
      df = daily_data["df"]
  
      forecast_config = forecast_config_info_daily
      ad_config = ADConfig(
          volatility_features_list=[["dow"], ["is_weekend"]],
          coverage_grid=[
              0.5,
              0.55,
              0.6,
              0.65,
              0.7,
              0.75,
              0.9,
              0.95,
              0.99,
              0.999,
          ],
          target_anomaly_percent=None,
          variance_scaling=True,
      )
  
      train_data = Data(df=df_train)
  
      def reward_func(data):
          return f1_calc(y_true=data.y_true, y_pred=data.y_pred)
  
      reward = Reward(reward_func)
  
      # Trains the anomaly detector.
      detector = GreykiteDetector(
          forecast_config=forecast_config,
          ad_config=ad_config,
          reward=reward,
      )
      detector.fit(data=train_data)
      fit_data = detector.fit_info["best_calc_result"].data
      fit_df = fit_data.pred_df
  
      # Pickles and deserializes the anomaly detector.
      pickler = GreykitePickler()
      serialized = pickler.dumps(detector)
      deserialized = pickler.loads(serialized)
  
      # Checks that the original and deserialized anomaly detector train results are the same.
      deserialized_fit_data = deserialized.fit_info[
          "best_calc_result"
      ].data
      deserialized_fit_df = deserialized_fit_data.pred_df
  
      # Checks if we get the expected columns in the fit data.
      assert list(fit_df.columns) == DETECTOR_PREDICT_COLS + [
          ANOMALY_COL
      ]
      assert list(
          deserialized_fit_df.columns
      ) == DETECTOR_PREDICT_COLS + [ANOMALY_COL]
  
      fit_obj_value = detector.reward.apply(fit_data)
      deserialized_fit_obj_value = deserialized.reward.apply(
          deserialized_fit_data
      )
      assert fit_obj_value == deserialized_fit_obj_value
  
      fit_recall = calc_recall(
          y_true=fit_data.y_true, y_pred=fit_data.y_pred
      )
      deserialized_f1_recall = calc_recall(
          y_true=deserialized_fit_data.y_true,
          y_pred=deserialized_fit_data.y_pred,
      )
      assert fit_recall == deserialized_f1_recall
  
      fit_precision = calc_precision(
          y_true=fit_data.y_true, y_pred=fit_data.y_pred
      )
      deserialized_f1_precision = calc_precision(
          y_true=deserialized_fit_data.y_true,
          y_pred=deserialized_fit_data.y_pred,
      )
      assert fit_precision == deserialized_f1_precision
  
      # Predicts on the test data with the original and deserialized anomaly detector.
      test_data = Data(df=df_test, y_true=df_test[ANOMALY_COL])
      test_data = detector.predict(test_data)
      pred_df = test_data.pred_df
  
      deserialized_test_data = deserialized.predict(test_data)
      deserialized_pred_df = deserialized_test_data.pred_df
  
      # Checks that the original and deserialized anomaly detector test results are the same.
      assert list(pred_df.columns) == DETECTOR_PREDICT_COLS + [
          ANOMALY_COL
      ]
      assert list(
          deserialized_pred_df.columns
      ) == DETECTOR_PREDICT_COLS + [ANOMALY_COL]
  
      test_obj_value = detector.reward.apply(test_data)
      deserialized_test_obj_value = deserialized.reward.apply(
          deserialized_test_data
      )
      assert test_obj_value == deserialized_test_obj_value
  
      test_recall = calc_recall(
          y_true=test_data.y_true, y_pred=test_data.y_pred
      )
      deserialized_test_recall = calc_recall(
          y_true=deserialized_test_data.y_true,
          y_pred=deserialized_test_data.y_pred,
      )
      assert test_recall == deserialized_test_recall
  
      test_precision = calc_precision(
          y_true=test_data.y_true, y_pred=test_data.y_pred
      )
      deserialized_test_precision = calc_precision(
          y_true=deserialized_test_data.y_true,
          y_pred=deserialized_test_data.y_pred,
      )
      assert test_precision == deserialized_test_precision
  
      # Checks the size of the serialized object.
      memory_size_mb = sys.getsizeof(serialized) * 1e-6
      assert memory_size_mb < 64.0
  
      # Plots the fit and test results of the original and deserialized anomaly detector.
      # This provides a visual check that the results are the same.
      fit_pred_df = pd.concat([fit_df, pred_df], axis=0)
      fit_pred_df[ANOMALY_COL] = df[ANOMALY_COL]
      "Test of train and predict of the Greykite Detector."
      fig = plot_anomalies_over_forecast_vs_actual(
          df=fit_pred_df,
          time_col=TIME_COL,
          actual_col=ACTUAL_COL,
          predicted_col=PREDICTED_COL,
          predicted_anomaly_col=PREDICTED_ANOMALY_COL,
          anomaly_col=ANOMALY_COL,
          marker_opacity=0.6,
          predicted_anomaly_marker_color="black",
          anomaly_marker_color="green",
          predicted_lower_col=PREDICTED_LOWER_COL,
          predicted_upper_col=PREDICTED_UPPER_COL,
          train_end_date=fit_df[TIME_COL].max(),
          title="Test of train and predict of the Greykite Detector.",
      )
      assert fig is not None
      if FIG_SHOW:
          fig.show()
  
      deserialized_pred_df = pd.concat(
          [deserialized_fit_df, deserialized_pred_df], axis=0
      )
      deserialized_pred_df[ANOMALY_COL] = df[ANOMALY_COL]
      fig = plot_anomalies_over_forecast_vs_actual(
          df=deserialized_pred_df,
          time_col=TIME_COL,
          actual_col=ACTUAL_COL,
          predicted_col=PREDICTED_COL,
          predicted_anomaly_col=PREDICTED_ANOMALY_COL,
          anomaly_col=ANOMALY_COL,
          marker_opacity=0.6,
          predicted_anomaly_marker_color="black",
          anomaly_marker_color="red",
          predicted_lower_col=PREDICTED_LOWER_COL,
          predicted_upper_col=PREDICTED_UPPER_COL,
          train_end_date=fit_df[TIME_COL].max(),
          title="Test of train and predict of the deserialized Greykite Detector.",
      )
      assert fig is not None
      if FIG_SHOW:
          fig.show()
  
imports: import datetime
  import inspect
  import sys
  from collections import OrderedDict
  import dill
  import numpy
  import pandas
  import pytest
  from patsy.desc import Term
  from greykite.common.constants import ACTUAL_COL
  from greykite.common.constants import ANOMALY_COL
  from greykite.common.constants import PREDICTED_ANOMALY_COL
  from greykite.common.constants import PREDICTED_COL
  from greykite.common.constants import PREDICTED_LOWER_COL
  from greykite.common.constants import PREDICTED_UPPER_COL
  from greykite.common.constants import TIME_COL
  from greykite.common.constants import VALUE_COL
  from greykite.common.python_utils import assert_equal
  from greykite.common.testing_utils import generate_df_for_tests
  from greykite.common.testing_utils_anomalies import contaminate_df_with_anomalies
  from greykite.common.viz.timeseries_annotate import plot_anomalies_over_forecast_vs_actual
  from greykite.detection.common.ad_evaluation import f1_score
  from greykite.detection.common.ad_evaluation import precision_score
  from greykite.detection.common.ad_evaluation import recall_score
  from greykite.detection.common.pickler import GreykitePickler
  from greykite.detection.detector.ad_utils import partial_return
  from greykite.detection.detector.config import ADConfig
  from greykite.detection.detector.constants import FIG_SHOW
  from greykite.detection.detector.data import DetectorData
  from greykite.detection.detector.greykite import DETECTOR_PREDICT_COLS
  from greykite.detection.detector.greykite import GreykiteDetector
  from greykite.detection.detector.reward import Reward
  from greykite.framework.templates.autogen.forecast_config import ComputationParam
  from greykite.framework.templates.autogen.forecast_config import EvaluationPeriodParam
  from greykite.framework.templates.autogen.forecast_config import ForecastConfig
  from greykite.framework.templates.autogen.forecast_config import MetadataParam
  from greykite.framework.templates.autogen.forecast_config import ModelComponentsParam
  from greykite.framework.templates.forecaster import Forecaster
  from greykite.framework.templates.model_templates import ModelTemplateEnum
  from greykite.framework.utils.result_summary import summarize_grid_search_results
label_desc: Use image node_id 11 for calling a global function with example usage: test_silverkite_ad_result(daily_data, forecast_config_info_daily) and returns: f1_calc