docstr: The LightningFlow is used by the :class:`~lightning.app.core.app.LightningApp` to coordinate and manage
  long- running jobs contained, the :class:`~lightning.app.core.work.LightningWork`.
  
  A LightningFlow is characterized by:
  
  * A set of state variables.
  * Long-running jobs (:class:`~lightning.app.core.work.LightningWork`).
  * Its children ``LightningFlow`` or ``LightningWork`` with their state variables.
  
  **State variables**
  
  The LightningFlow are special classes whose attributes require to be
  json-serializable (e.g., int, float, bool, list, dict, ...).
  
  They also may not reach into global variables unless they are constant.
  
  The attributes need to be all defined in `__init__` method,
  and eventually assigned to different values throughout the lifetime of the object.
  However, defining new attributes outside of `__init__` is not allowed.
  
  Attributes taken together represent the state of the component.
  Components are capable of retrieving their state and that of their
  children recursively at any time. They are also capable of setting
  an externally provided state recursively to its children.
  
  **Execution model and work**
  
  The entry point for execution is the ``run`` method at the root component.
  The ``run`` method of the root component may call the ``run`` method of its children, and the children
  may call the ``run`` methods of their children and so on.
  
  The ``run`` method of the root component is called repeatedly in a while loop forever until the app gets
  terminated. In this programming model (reminiscent of React, Vue or Streamlit from the JavaScript world),
  the values of the state variables, or their changes, are translated into actions throughout the component
  hierarchy. This means the flow of execution will only be affected by state changes in a component or one of
  its children, and otherwise remain idempotent.
  
  The actions themselves are self-contained within :class:`~lightning.app.core.work.LightningWork`.
  The :class:`~lightning.app.core.work.LightningWork` are typically used for long-running jobs,
  like downloading a dataset, performing a query, starting a computationally heavy script.
  While one may access any state variable in a LightningWork from a LightningFlow, one may not
  directly call methods of other components from within a LightningWork as LightningWork can't have any children.
  This limitation allows applications to be distributed at scale.
  
  **Component hierarchy and App**
  
  Given the above characteristics, a root LightningFlow, potentially containing
  children components, can be passed to an App object and its execution
  can be distributed (each LightningWork will be run within its own process
  or different arrangements).
  
  Example:
  
      >>> from lightning.app import LightningFlow
      >>> class RootFlow(LightningFlow):
      ...     def __init__(self):
      ...         super().__init__()
      ...         self.counter = 0
      ...     def run(self):
      ...         self.counter += 1
      ...
      >>> flow = RootFlow()
      >>> flow.run()
      >>> assert flow.counter == 1
      >>> assert flow.state["vars"]["counter"] == 1
docstr_tok: ["The","LightningFlow","is","used","by","the",":","class",":","`","~lightning.app.core.app.LightningApp","`","to","coordinate","and","manage","long-","running","jobs","contained",",","the",":","class",":","`","~lightning.app.core.work.LightningWork","`",".","A","LightningFlow","is","characterized","by",":","*","A","set","of","state","variables",".","*","Long-running","jobs","(",":","class",":","`","~lightning.app.core.work.LightningWork","`",")",".","*","Its","children","``","LightningFlow","``","or","``","LightningWork","``","with","their","state","variables",".","*","*","State","variables","*","*","The","LightningFlow","are","special","classes","whose","attributes","require","to","be","json-serializable","(","e.g.",",","int",",","float",",","bool",",","list",",","dict",",","...",")",".","They","also","may","not","reach","into","global","variables","unless","they","are","constant",".","The","attributes","need","to","be","all","defined","in","`","__init__","`","method",",","and","eventually","assigned","to","different","values","throughout","the","lifetime","of","the","object",".","However",",","defining","new","attributes","outside","of","`","__init__","`","is","not","allowed",".","Attributes","taken","together","represent","the","state","of","the","component",".","Components","are","capable","of","retrieving","their","state","and","that","of","their","children","recursively","at","any","time",".","They","are","also","capable","of","setting","an","externally","provided","state","recursively","to","its","children",".","*","*","Execution","model","and","work","*","*","The","entry","point","for","execution","is","the","``","run","``","method","at","the","root","component",".","The","``","run","``","method","of","the","root","component","may","call","the","``","run","``","method","of","its","children",",","and","the","children","may","call","the","``","run","``","methods","of","their","children","and","so","on",".","The","``","run","``","method","of","the","root","component","is","called","repeatedly","in","a","while","loop","forever","until","the","app","gets","terminated",".","In","this","programming","model","(","reminiscent","of","React",",","Vue","or","Streamlit","from","the","JavaScript","world",")",",","the","values","of","the","state","variables",",","or","their","changes",",","are","translated","into","actions","throughout","the","component","hierarchy",".","This","means","the","flow","of","execution","will","only","be","affected","by","state","changes","in","a","component","or","one","of","its","children",",","and","otherwise","remain","idempotent",".","The","actions","themselves","are","self-contained","within",":","class",":","`","~lightning.app.core.work.LightningWork","`",".","The",":","class",":","`","~lightning.app.core.work.LightningWork","`","are","typically","used","for","long-running","jobs",",","like","downloading","a","dataset",",","performing","a","query",",","starting","a","computationally","heavy","script",".","While","one","may","access","any","state","variable","in","a","LightningWork","from","a","LightningFlow",",","one","may","not","directly","call","methods","of","other","components","from","within","a","LightningWork","as","LightningWork","ca","n't","have","any","children",".","This","limitation","allows","applications","to","be","distributed","at","scale",".","*","*","Component","hierarchy","and","App","*","*","Given","the","above","characteristics",",","a","root","LightningFlow",",","potentially","containing","children","components",",","can","be","passed","to","an","App","object","and","its","execution","can","be","distributed","(","each","LightningWork","will","be","run","within","its","own","process","or","different","arrangements",")",".","Example",":",">",">",">","from","lightning.app","import","LightningFlow",">",">",">","class","RootFlow","(","LightningFlow",")",":","...","def","__init__","(","self",")",":","...","super","(",")",".__init__","(",")","...","self.counter","=","0","...","def","run","(","self",")",":","...","self.counter","+=","1","...",">",">",">","flow","=","RootFlow","(",")",">",">",">","flow.run","(",")",">",">",">","assert","flow.counter","==","1",">",">",">","assert","flow.state","[","``","vars","''","]","[","``","counter","''","]","==","1"]
code: def __init__(self) -> None:
      """The LightningFlow is used by the :class:`~lightning.app.core.app.LightningApp` to coordinate and manage
      long- running jobs contained, the :class:`~lightning.app.core.work.LightningWork`.
  
      A LightningFlow is characterized by:
  
      * A set of state variables.
      * Long-running jobs (:class:`~lightning.app.core.work.LightningWork`).
      * Its children ``LightningFlow`` or ``LightningWork`` with their state variables.
  
      **State variables**
  
      The LightningFlow are special classes whose attributes require to be
      json-serializable (e.g., int, float, bool, list, dict, ...).
  
      They also may not reach into global variables unless they are constant.
  
      The attributes need to be all defined in `__init__` method,
      and eventually assigned to different values throughout the lifetime of the object.
      However, defining new attributes outside of `__init__` is not allowed.
  
      Attributes taken together represent the state of the component.
      Components are capable of retrieving their state and that of their
      children recursively at any time. They are also capable of setting
      an externally provided state recursively to its children.
  
      **Execution model and work**
  
      The entry point for execution is the ``run`` method at the root component.
      The ``run`` method of the root component may call the ``run`` method of its children, and the children
      may call the ``run`` methods of their children and so on.
  
      The ``run`` method of the root component is called repeatedly in a while loop forever until the app gets
      terminated. In this programming model (reminiscent of React, Vue or Streamlit from the JavaScript world),
      the values of the state variables, or their changes, are translated into actions throughout the component
      hierarchy. This means the flow of execution will only be affected by state changes in a component or one of
      its children, and otherwise remain idempotent.
  
      The actions themselves are self-contained within :class:`~lightning.app.core.work.LightningWork`.
      The :class:`~lightning.app.core.work.LightningWork` are typically used for long-running jobs,
      like downloading a dataset, performing a query, starting a computationally heavy script.
      While one may access any state variable in a LightningWork from a LightningFlow, one may not
      directly call methods of other components from within a LightningWork as LightningWork can't have any children.
      This limitation allows applications to be distributed at scale.
  
      **Component hierarchy and App**
  
      Given the above characteristics, a root LightningFlow, potentially containing
      children components, can be passed to an App object and its execution
      can be distributed (each LightningWork will be run within its own process
      or different arrangements).
  
      Example:
  
          >>> from lightning.app import LightningFlow
          >>> class RootFlow(LightningFlow):
          ...     def __init__(self):
          ...         super().__init__()
          ...         self.counter = 0
          ...     def run(self):
          ...         self.counter += 1
          ...
          >>> flow = RootFlow()
          >>> flow.run()
          >>> assert flow.counter == 1
          >>> assert flow.state["vars"]["counter"] == 1
  
      """
      self._state: set = set()
      self._name: str = ""
      self._flows: set = set()
      self._works: set = set()
      self._structures: set = set()
      self._calls: dict = {}
      self._changes: dict = {}
      self._layout: Union[List[Dict], Dict] = {}
      self._paths: dict = {}
      self._backend: Optional["Backend"] = None
      # tuple instead of a list so that it cannot be modified without using the setter
      self._lightningignore: Tuple[str, ...] = ()
  
imports: import inspect
  import warnings
  from copy import deepcopy
  from datetime import datetime
  from types import FrameType
  from typing import TYPE_CHECKING, Any, Dict, Generator, Iterable, List, Optional, Tuple, Union, cast
  from deepdiff import DeepHash
  from lightning.app.core.work import LightningWork
  from lightning.app.frontend import Frontend
  from lightning.app.storage.drive import Drive, _maybe_create_drive
  from lightning.app.storage.path import Path
  from lightning.app.utilities.app_helpers import _is_json_serializable, _LightningAppRef, _set_child_name, is_overridden
  from lightning.app.utilities.component import _sanitize_state
  from lightning.app.utilities.exceptions import ExitAppException, LightningFlowException
  from lightning.app.utilities.introspection import _is_init_context, _is_run_context
  from lightning.app.utilities.packaging.cloud_compute import CloudCompute, _maybe_create_cloud_compute
label_desc: Use image node_id 1 to create a new LightningFlow object  with example: obj = LightningFlow()