code: def replay_shape_env_events(events):
      from torch.fx.experimental.symbolic_shapes import ShapeEnv
  
      constructor_event = events[0]
      assert constructor_event.f == ShapeEnv
  
      # Constructs the new ShapeEnv.
      shape_env = constructor_event.run()
  
      for event in events[1:]:
          try:
              # Actually replays each event.
              # We need to call create_mapping_fn every time, since the node list might
              # change after each event is replayed.
              event.run(shape_env)
          except Exception as e:
              raise RuntimeError(
                  f"failed when running event: {event}"
              ) from e
  
      return shape_env
  
imports: import functools
  import itertools
  from dataclasses import dataclass
  from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import torch
  import torch.utils._pytree
label_desc: Use image node_id 3 for calling a global function with example usage: replay_shape_env_events(events) and returns: shape_env