code: def _save_CounterfactualRL(
      explainer: "CounterfactualRL", path: Union[str, os.PathLike]
  ) -> None:
      from alibi.utils.frameworks import Framework
      from alibi.explainers import CounterfactualRL
  
      CounterfactualRL._verify_backend(explainer.params["backend"])
  
      # get backend module
      backend = explainer.backend
  
      # define extension
      ext = (
          ".tf"
          if explainer.params["backend"] == Framework.TENSORFLOW
          else ".pth"
      )
  
      # save encoder and decoder (autoencoder components)
      encoder = explainer.params["encoder"]
      decoder = explainer.params["decoder"]
      backend.save_model(
          path=Path(path, "encoder" + ext),
          model=explainer.params["encoder"],
      )
      backend.save_model(
          path=Path(path, "decoder" + ext),
          model=explainer.params["decoder"],
      )
  
      # save actor
      actor = explainer.params["actor"]
      optimizer_actor = explainer.params[
          "optimizer_actor"
      ]  # TODO: save the actor optimizer?
      backend.save_model(
          path=Path(path, "actor" + ext),
          model=explainer.params["actor"],
      )
  
      # save critic
      critic = explainer.params["critic"]
      optimizer_critic = explainer.params[
          "optimizer_critic"
      ]  # TODO: save the critic optimizer?
      backend.save_model(
          path=Path(path, "critic" + ext),
          model=explainer.params["critic"],
      )
  
      # save locally prediction function
      predictor = explainer.params["predictor"]
  
      # save callbacks
      callbacks = explainer.params[
          "callbacks"
      ]  # TODO: what to do with the callbacks?
  
      # set encoder, decoder, actor, critic, prediction_func, and backend to `None`
      explainer.params["encoder"] = None
      explainer.params["decoder"] = None
      explainer.params["actor"] = None
      explainer.params["critic"] = None
      explainer.params["optimizer_actor"] = None
      explainer.params["optimizer_critic"] = None
      explainer.params["predictor"] = None
      explainer.params["callbacks"] = None
      explainer.backend = None
  
      # Save explainer. All the pre/post-processing function will be saved in the explainer.
      # TODO: find a better way? (I think this is ok if the functions are not too complex)
      with open(Path(path, "explainer.dill"), "wb") as f:
          dill.dump(explainer, f)
  
      # set back encoder, decoder, actor and critic back
      explainer.params["encoder"] = encoder
      explainer.params["decoder"] = decoder
      explainer.params["actor"] = actor
      explainer.params["critic"] = critic
      explainer.params["optimizer_actor"] = optimizer_actor
      explainer.params["optimizer_critic"] = optimizer_critic
      explainer.params["predictor"] = predictor
      explainer.params["callbacks"] = callbacks
      explainer.backend = backend
  
imports: import copy
  import json
  import numbers
  import os
  from pathlib import Path
  import sys
  from typing import Callable, TYPE_CHECKING, Union
  import warnings
  import dill
  import numpy
  from alibi.version import __version__
label_desc: Use image node_id 14 for calling a global function with example usage: _save_CounterfactualRL(explainer, path) without return types