code: def test_distributed_explainer_get_explanation(
      data_generator,
      expln_args,
      expln_kwargs,
      distributed_opts,
      return_generator,
      concatenate_results,
  ):
      atol = 1e-5  # tolerance for numerical comparisons
  
      batch_size = distributed_opts["batch_size"]
      ncpus = distributed_opts["n_cpus"]
      distributed_explainer = DistributedExplainer(
          distributed_opts,
          MockExplainer,
          expln_args,
          expln_kwargs,
          return_generator=return_generator,
          concatenate_results=concatenate_results,
      )
      X = data_generator
      result = distributed_explainer.get_explanation(X)
  
      if return_generator:
          # test a generator is returned immediately
          assert inspect.isgenerator(result)
          # take all elems from generator so distributed execution can be tested
          for elem in result:
              assert isinstance(elem, tuple)
      else:
          # test batching
          if concatenate_results:
              assert isinstance(result, np.ndarray)
              assert result.shape == X.shape
  
          else:
              if batch_size is None:
                  assert (
                      len(result) == ncpus
                  )  # split batch evenly if not specified
              elif X.shape[0] % batch_size == 0:
                  assert len(result) == X.shape[0] // batch_size
              else:
                  assert (
                      sum(res.shape[0] for res in result) == X.shape[0]
                  )
              # result correctness
              result = np.concatenate(result, axis=0).squeeze()
          assert np.isclose(
              np.unique(result / X),
              expln_kwargs["multiplier"],
              atol=atol,
          )
  
      # test distributed execution
      proc_ids = []
      for idx in range(ncpus):
          distributed_explainer.actor_index = (
              idx  # set this to retrieve state from different actors
          )
          proc_ids.append(distributed_explainer.proc_id)
      assert len(set(proc_ids)) == ncpus
  
      # clean up after test
      ray.shutdown()
  
imports: import inspect
  import os
  import pytest
  import time
  from itertools import product
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  from alibi.utils.distributed import DistributedExplainer, PoolCollection, ResourceError, invert_permutation, concatenate_minibatches
label_desc: Use image node_id 6 for calling a global function with example usage: test_distributed_explainer_get_explanation(data_generator, expln_args, expln_kwargs, distributed_opts, return_generator, concatenate_results) without return types