code: def _run_on_rank_0_and_broadcast(
      func: Callable[[], T],
      distributed: Optional[core.DistributedContext] = None,
  ) -> T:
      result = None
  
      if distributed is None or distributed.rank == 0:
          result = func()
      if distributed is not None:
          result = distributed.broadcast(result)
  
      assert result
  
      return result
  
imports: import logging
  from typing import Callable, Optional, Tuple, TypeVar, Union
  import determined
  from determined import core, experimental
  from determined.common import api, util
  from determined.common.api import bindings
label_desc: Use image node_id 1 for calling a global function with example usage: _run_on_rank_0_and_broadcast(func, distributed) and returns: result