class_docstr: Task graph composed of layers of dependent subgraphs
  
  This object encodes a Dask task graph that is composed of layers of
  dependent subgraphs, such as commonly occurs when building task graphs
  using high level collections like Dask array, bag, or dataframe.
  
  Typically each high level array, bag, or dataframe operation takes the task
  graphs of the input collections, merges them, and then adds one or more new
  layers of tasks for the new operation.  These layers typically have at
  least as many tasks as there are partitions or chunks in the collection.
  The HighLevelGraph object stores the subgraphs for each operation
  separately in sub-graphs, and also stores the dependency structure between
  them.
  
  Parameters
  ----------
  layers : Mapping[str, Mapping]
      The subgraph layers, keyed by a unique name
  dependencies : Mapping[str, set[str]]
      The set of layers on which each layer depends
  key_dependencies : dict[Key, set], optional
      Mapping (some) keys in the high level graph to their dependencies. If
      a key is missing, its dependencies will be calculated on-the-fly.
  
  Examples
  --------
  Here is an idealized example that shows the internal state of a
  HighLevelGraph
  
  >>> import dask.dataframe as dd
  
  >>> df = dd.read_csv('myfile.*.csv')  # doctest: +SKIP
  >>> df = df + 100  # doctest: +SKIP
  >>> df = df[df.name == 'Alice']  # doctest: +SKIP
  
  >>> graph = df.__dask_graph__()  # doctest: +SKIP
  >>> graph.layers  # doctest: +SKIP
  {
   'read-csv': {('read-csv', 0): (pandas.read_csv, 'myfile.0.csv'),
                ('read-csv', 1): (pandas.read_csv, 'myfile.1.csv'),
                ('read-csv', 2): (pandas.read_csv, 'myfile.2.csv'),
                ('read-csv', 3): (pandas.read_csv, 'myfile.3.csv')},
   'add': {('add', 0): (operator.add, ('read-csv', 0), 100),
           ('add', 1): (operator.add, ('read-csv', 1), 100),
           ('add', 2): (operator.add, ('read-csv', 2), 100),
           ('add', 3): (operator.add, ('read-csv', 3), 100)}
   'filter': {('filter', 0): (lambda part: part[part.name == 'Alice'], ('add', 0)),
              ('filter', 1): (lambda part: part[part.name == 'Alice'], ('add', 1)),
              ('filter', 2): (lambda part: part[part.name == 'Alice'], ('add', 2)),
              ('filter', 3): (lambda part: part[part.name == 'Alice'], ('add', 3))}
  }
  
  >>> graph.dependencies  # doctest: +SKIP
  {
   'read-csv': set(),
   'add': {'read-csv'},
   'filter': {'add'}
  }
  
  See Also
  --------
  HighLevelGraph.from_collections :
      typically used by developers to make new HighLevelGraphs
class_docstr_tok: ["Task","graph","composed","of","layers","of","dependent","subgraphs","This","object","encodes","a","Dask","task","graph","that","is","composed","of","layers","of","dependent","subgraphs",",","such","as","commonly","occurs","when","building","task","graphs","using","high","level","collections","like","Dask","array",",","bag",",","or","dataframe",".","Typically","each","high","level","array",",","bag",",","or","dataframe","operation","takes","the","task","graphs","of","the","input","collections",",","merges","them",",","and","then","adds","one","or","more","new","layers","of","tasks","for","the","new","operation",".","These","layers","typically","have","at","least","as","many","tasks","as","there","are","partitions","or","chunks","in","the","collection",".","The","HighLevelGraph","object","stores","the","subgraphs","for","each","operation","separately","in","sub-graphs",",","and","also","stores","the","dependency","structure","between","them",".","Parameters","--","--","--","--","--","layers",":","Mapping","[","str",",","Mapping","]","The","subgraph","layers",",","keyed","by","a","unique","name","dependencies",":","Mapping","[","str",",","set","[","str","]","]","The","set","of","layers","on","which","each","layer","depends","key_dependencies",":","dict","[","Key",",","set","]",",","optional","Mapping","(","some",")","keys","in","the","high","level","graph","to","their","dependencies",".","If","a","key","is","missing",",","its","dependencies","will","be","calculated","on-the-fly",".","Examples","--","--","--","--","Here","is","an","idealized","example","that","shows","the","internal","state","of","a","HighLevelGraph",">",">",">","import","dask.dataframe","as","dd",">",">",">","df","=","dd.read_csv","(","'myfile",".","*",".csv","'",")","#","doctest",":","+SKIP",">",">",">","df","=","df","+","100","#","doctest",":","+SKIP",">",">",">","df","=","df","[","df.name","==","'Alice","'","]","#","doctest",":","+SKIP",">",">",">","graph","=","df.__dask_graph__","(",")","#","doctest",":","+SKIP",">",">",">","graph.layers","#","doctest",":","+SKIP","{","'read-csv","'",":","{","(","'read-csv","'",",","0",")",":","(","pandas.read_csv",",","'myfile.0.csv","'",")",",","(","'read-csv","'",",","1",")",":","(","pandas.read_csv",",","'myfile.1.csv","'",")",",","(","'read-csv","'",",","2",")",":","(","pandas.read_csv",",","'myfile.2.csv","'",")",",","(","'read-csv","'",",","3",")",":","(","pandas.read_csv",",","'myfile.3.csv","'",")","}",",","'add","'",":","{","(","'add","'",",","0",")",":","(","operator.add",",","(","'read-csv","'",",","0",")",",","100",")",",","(","'add","'",",","1",")",":","(","operator.add",",","(","'read-csv","'",",","1",")",",","100",")",",","(","'add","'",",","2",")",":","(","operator.add",",","(","'read-csv","'",",","2",")",",","100",")",",","(","'add","'",",","3",")",":","(","operator.add",",","(","'read-csv","'",",","3",")",",","100",")","}","'filter","'",":","{","(","'filter","'",",","0",")",":","(","lambda","part",":","part","[","part.name","==","'Alice","'","]",",","(","'add","'",",","0",")",")",",","(","'filter","'",",","1",")",":","(","lambda","part",":","part","[","part.name","==","'Alice","'","]",",","(","'add","'",",","1",")",")",",","(","'filter","'",",","2",")",":","(","lambda","part",":","part","[","part.name","==","'Alice","'","]",",","(","'add","'",",","2",")",")",",","(","'filter","'",",","3",")",":","(","lambda","part",":","part","[","part.name","==","'Alice","'","]",",","(","'add","'",",","3",")",")","}","}",">",">",">","graph.dependencies","#","doctest",":","+SKIP","{","'read-csv","'",":","set","(",")",",","'add","'",":","{","'read-csv","'","}",",","'filter","'",":","{","'add","'","}","}","See","Also","--","--","--","--","HighLevelGraph.from_collections",":","typically","used","by","developers","to","make","new","HighLevelGraphs"]
docstr: Construct a HighLevelGraph from a new layer and a set of collections
  
  This constructs a HighLevelGraph in the common case where we have a single
  new layer and a set of old collections on which we want to depend.
  
  This pulls out the ``__dask_layers__()`` method of the collections if
  they exist, and adds them to the dependencies for this new layer.  It
  also merges all of the layers from all of the dependent collections
  together into the new layers for this graph.
  
  Parameters
  ----------
  name : str
      The name of the new layer
  layer : Mapping
      The graph layer itself
  dependencies : List of Dask collections
      A list of other dask collections (like arrays or dataframes) that
      have graphs themselves
  
  Examples
  --------
  
  In typical usage we make a new task layer, and then pass that layer
  along with all dependent collections to this method.
  
  >>> def add(self, other):
  ...     name = 'add-' + tokenize(self, other)
  ...     layer = {(name, i): (add, input_key, other)
  ...              for i, input_key in enumerate(self.__dask_keys__())}
  ...     graph = HighLevelGraph.from_collections(name, layer, dependencies=[self])
  ...     return new_collection(name, graph)
code: def from_collections(
      cls,
      name: str,
      layer: Graph,
      dependencies: Sequence[DaskCollection] = (),
  ) -> HighLevelGraph:
      """Construct a HighLevelGraph from a new layer and a set of collections
  
      This constructs a HighLevelGraph in the common case where we have a single
      new layer and a set of old collections on which we want to depend.
  
      This pulls out the ``__dask_layers__()`` method of the collections if
      they exist, and adds them to the dependencies for this new layer.  It
      also merges all of the layers from all of the dependent collections
      together into the new layers for this graph.
  
      Parameters
      ----------
      name : str
          The name of the new layer
      layer : Mapping
          The graph layer itself
      dependencies : List of Dask collections
          A list of other dask collections (like arrays or dataframes) that
          have graphs themselves
  
      Examples
      --------
  
      In typical usage we make a new task layer, and then pass that layer
      along with all dependent collections to this method.
  
      >>> def add(self, other):
      ...     name = 'add-' + tokenize(self, other)
      ...     layer = {(name, i): (add, input_key, other)
      ...              for i, input_key in enumerate(self.__dask_keys__())}
      ...     graph = HighLevelGraph.from_collections(name, layer, dependencies=[self])
      ...     return new_collection(name, graph)
      """
      if len(dependencies) == 1:
          return cls._from_collection(name, layer, dependencies[0])
      layers = {name: layer}
      name_dep: set[str] = set()
      deps: dict[str, set[str]] = {name: name_dep}
      for collection in toolz.unique(dependencies, key=id):
          if is_dask_collection(collection):
              graph = collection.__dask_graph__()
              if isinstance(graph, HighLevelGraph):
                  layers.update(graph.layers)
                  deps.update(graph.dependencies)
                  name_dep |= set(collection.__dask_layers__())
              else:
                  key = _get_some_layer_name(collection)
                  layers[key] = graph
                  name_dep.add(key)
                  deps[key] = set()
          else:
              raise TypeError(type(collection))
  
      return cls(layers, deps)
  
imports: from __future__ import annotations
  import abc
  import copy
  import html
  from collections.abc import Collection, Hashable, ItemsView, Iterable, Iterator, KeysView, Mapping, Sequence, Set, ValuesView
  from typing import Any
  import tlz
  import dask
  from dask import config
  from dask.base import clone_key, flatten, is_dask_collection
  from dask.core import keys_in_tasks, reverse_dict
  from dask.typing import DaskCollection, Graph, Key
  from dask.utils import ensure_dict, import_required, key_split
  from dask.widgets import get_template
label_desc: Use image node_id 3 for calling the HighLevelGraph obj's underlying member method code with example usage: obj.from_collections(cls, name, layer, dependencies) and returns: cls, cls