code: def distribution_from_spec(
      spec: types.NestedTensorSpec,
      new_distribution_params: types.NestedTensor,
      legacy_distribution_network: bool,
  ) -> types.NestedDistribution:
      """Convert `(spec, new_distribution_params) -> Distribution`.
  
      `new_distribution_params` typically comes from a logged policy info.
  
      Args:
        spec: A nested tensor spec.  If `legacy_distribution_network` is `True`,
          these are typically `actor_net.output_spec`.  If it's `False`, these are
          typically the output of `actor_net.create_variables()`.
        new_distribution_params: Parameters to merge with the spec to create a new
          distribution.  These were typically emitted by `get_distribution_params`
          and stored in the replay buffer.
        legacy_distribution_network: `True` if the spec and params were generated
          from a `network.DistributionNetwork`.
  
      Returns:
        A (possibly nested set of) `Distribution` created from the spec
        merged with the new params.
      """
      if legacy_distribution_network:
          return distribution_spec.nested_distributions_from_specs(
              spec, new_distribution_params
          )
      else:
  
          def merge_and_convert(spec, params):
              return distribution_utils.make_from_parameters(
                  distribution_utils.merge_to_parameters_from_dict(
                      spec.parameters, params
                  )
              )
  
          return nest_utils.map_structure_up_to(
              spec, merge_and_convert, spec, new_distribution_params
          )
  
file_path: agents/tf_agents/agents/ppo/ppo_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Sequence
  import tensorflow
  import tensorflow_probability
  from tf_agents.distributions import utils
  from tf_agents.specs import distribution_spec
  from tf_agents.trajectories import policy_step
  from tf_agents.trajectories import time_step
  from tf_agents.trajectories import trajectory
  from tf_agents.typing import types
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 3 for calling a global function with example usage: distribution_from_spec(spec, new_distribution_params, legacy_distribution_network) and returns: distribution_spec, nest_utils, distribution_utils