code: def _reduce_to_flow_scope(
      state: AppState, flow: str | LightningFlow
  ) -> AppState:
      """Returns a new AppState with the scope reduced to the given flow."""
      flow_name = flow.name if isinstance(flow, LightningFlow) else flow
      flow_name_parts = flow_name.split(".")[1:]  # exclude root
      flow_state = state
      for part in flow_name_parts:
          flow_state = getattr(flow_state, part)
      return flow_state
  
file_path: pytorch-lightning/src/lightning/app/frontend/utils.py
imports: from __future__ import annotations
  import inspect
  import os
  from typing import Callable
  from lightning.app.core.flow import LightningFlow
  from lightning.app.utilities.state import AppState
label_desc: Use image node_id 1 for calling a global function with example usage: _reduce_to_flow_scope(state, flow) and returns: flow_state