code: def _get_distributions(
      study: Study, params: Optional[List[str]]
  ) -> Dict[str, BaseDistribution]:
      completed_trials = study.get_trials(
          deepcopy=False, states=(TrialState.COMPLETE,)
      )
      _check_evaluate_args(completed_trials, params)
  
      if params is None:
          return intersection_search_space(
              study.get_trials(deepcopy=False)
          )
  
      # New temporary required to pass mypy. Seems like a bug.
      params_not_none = params
      assert params_not_none is not None
  
      # Compute the search space based on the subset of trials containing all parameters.
      distributions = None
      for trial in completed_trials:
          trial_distributions = trial.distributions
          if not all(
              name in trial_distributions for name in params_not_none
          ):
              continue
  
          if distributions is None:
              distributions = dict(
                  filter(
                      lambda name_and_distribution: name_and_distribution[
                          0
                      ]
                      in params_not_none,
                      trial_distributions.items(),
                  )
              )
              continue
  
          if any(
              trial_distributions[name] != distribution
              for name, distribution in distributions.items()
          ):
              raise ValueError(
                  "Parameters importances cannot be assessed with dynamic search spaces if "
                  "parameters are specified. Specified parameters: {}.".format(
                      params
                  )
              )
  
      assert distributions is not None  # Required to pass mypy.
      distributions = dict(
          sorted(
              distributions.items(),
              key=lambda name_and_distribution: name_and_distribution[
                  0
              ],
          )
      )
      return distributions
  
imports: import abc
  from typing import Callable
  from typing import cast
  from typing import Collection
  from typing import Dict
  from typing import List
  from typing import Optional
  from typing import Union
  import numpy
  from optuna._transform import _SearchSpaceTransform
  from optuna.distributions import BaseDistribution
  from optuna.search_space import intersection_search_space
  from optuna.study import Study
  from optuna.trial import FrozenTrial
  from optuna.trial import TrialState
label_desc: Use image node_id 1 for calling a global function with example usage: _get_distributions(study, params) and returns: distributions, intersection_search_space