code: def test_counterfactual_manager_save_load(self, tmpdir):
      (
          X_train,
          X_test,
          y_train,
          y_test,
          feature_names,
          _,
      ) = create_iris_data()
  
      model = create_lightgbm_classifier(X_train, y_train)
      X_train["target"] = y_train
      X_test["target"] = y_test
  
      rai_insights = RAIInsights(
          model=model,
          train=X_train,
          test=X_test.iloc[0:10],
          target_column="target",
          task_type="classification",
      )
  
      rai_insights.counterfactual.add(
          total_CFs=10,
          desired_class=2,
          features_to_vary=[feature_names[0]],
          permitted_range={feature_names[0]: [2.0, 5.0]},
      )
      rai_insights.counterfactual.add(
          total_CFs=10,
          desired_class=1,
          features_to_vary=[feature_names[0]],
          permitted_range={feature_names[0]: [2.0, 5.0]},
      )
      rai_insights.counterfactual.compute()
  
      counterfactual_config_list_before_save = (
          rai_insights.counterfactual._counterfactual_config_list
      )
      assert len(counterfactual_config_list_before_save) == 2
      assert len(rai_insights.counterfactual.get()) == 2
      cf_obj_1 = rai_insights.counterfactual.get()[0]
      assert cf_obj_1 is not None
      cf_obj_2 = rai_insights.counterfactual.get()[1]
      assert cf_obj_2 is not None
  
      save_dir = tmpdir.mkdir("save-dir")
      rai_insights.save(save_dir)
      rai_insights_copy = RAIInsights.load(save_dir)
  
      counterfactual_config_list_after_save = (
          rai_insights_copy.counterfactual._counterfactual_config_list
      )
      assert len(rai_insights_copy.counterfactual.get()) == 2
      cf_obj_1 = rai_insights_copy.counterfactual.get()[0]
      assert cf_obj_1 is not None
      cf_obj_2 = rai_insights_copy.counterfactual.get()[1]
      assert cf_obj_2 is not None
  
      assert counterfactual_config_list_before_save[0].id in [
          counterfactual_config_list_after_save[0].id,
          counterfactual_config_list_after_save[1].id,
      ]
      assert counterfactual_config_list_before_save[1].id in [
          counterfactual_config_list_after_save[0].id,
          counterfactual_config_list_after_save[1].id,
      ]
  
      # Delete the dice-ml explainer directory so that the dice-ml
      # explainer can be re-trained rather being loaded from the
      # disc
      counterfactual_path = save_dir / "counterfactual"
      all_cf_dirs = DirectoryManager.list_sub_directories(
          counterfactual_path
      )
      for counterfactual_config_dir in all_cf_dirs:
          directory_manager = DirectoryManager(
              parent_directory_path=counterfactual_path,
              sub_directory_name=counterfactual_config_dir,
          )
          explainer_pkl_path = (
              directory_manager.get_generators_directory()
              / ("explainer" + FileFormats.PKL)
          )
          os.remove(explainer_pkl_path)
  
      with pytest.warns(
          UserWarning,
          match="ERROR-LOADING-COUNTERFACTUAL-EXPLAINER: "
          "There was an error loading the "
          "counterfactual explainer model. "
          "Retraining the counterfactual "
          "explainer.",
      ):
          rai_insights_copy_new = RAIInsights.load(save_dir)
      counterfactual_config_list = (
          rai_insights_copy_new.counterfactual._counterfactual_config_list
      )
      assert len(counterfactual_config_list) == 2
      assert counterfactual_config_list[0].explainer is not None
      assert counterfactual_config_list[1].explainer is not None
  
file_path: responsible-ai-toolbox/responsibleai/tests/counterfactual/test_counterfactual_advanced_features.py
imports: import os
  import pytest
  from rai_test_utils.models.lightgbm import create_lightgbm_classifier
  from raiutils.exceptions import UserConfigValidationException
  from responsibleai import RAIInsights
  from responsibleai._interfaces import CounterfactualData
  from responsibleai._internal.constants import FileFormats
  from responsibleai._tools.shared.state_directory_management import DirectoryManager
  from ..common_utils import create_iris_data
label_desc: Use image node_id 3 for calling the TestCounterfactualAdvancedFeatures obj's underlying member method code with example usage: obj.test_counterfactual_manager_save_load(tmpdir) without return types