code: def collapse_sequences(overlay):
      """Detect and collapse sequences of nodes in an overlay."""
      sequences = []
      for node in overlay.nodes:
          if any([node in seq for seq in sequences]):
              continue
          seq = [node]
          while (
              len(node.consumers) == 1
              and len(list(node.consumers)[0].inputs) == 1
          ):
              node = list(node.consumers)[0]
              seq.append(node)
          if len(seq) > 1:
              sequences.append(seq)
  
      structure_map = {}
      for seq in sequences:
          structure_map[seq[-1]] = OverlayStructure(
              "Sequence", {"sequence": seq}
          )
  
      return overlay.collapse_structures(structure_map)
  
file_path: lucid/lucid/misc/graph_analysis/parse_overlay.py
imports: from lucid.misc.graph_analysis.overlay_graph import OverlayGraph, OverlayNode, OverlayStructure
label_desc: Use image node_id 1 for calling a global function with example usage: collapse_sequences(overlay) and returns: overlay