code: def _unflatten_graph(space: Graph, x: GraphInstance) -> GraphInstance:
      """We're not using `.unflatten() for :class:`Box` and :class:`Discrete` because a graph is not a homogeneous space.
  
      The size of the outcome is actually not fixed, but determined based on the number of
      nodes and edges in the graph.
      """
  
      def _graph_unflatten(space, x):
          ret = None
          if space is not None and x is not None:
              if isinstance(space, Box):
                  ret = x.reshape(-1, *space.shape)
              elif isinstance(space, Discrete):
                  ret = np.asarray(np.nonzero(x))[-1, :]
          return ret
  
      nodes = _graph_unflatten(space.node_space, x.nodes)
      edges = _graph_unflatten(space.edge_space, x.edges)
  
      return GraphInstance(nodes, edges, x.edge_links)
  
imports: import operator
  from collections import OrderedDict
  from functools import reduce, singledispatch
  from typing import Dict
  from typing import TypeVar, Union, cast
  import numpy
  from gym.spaces import Box, Dict, Discrete, Graph, GraphInstance, MultiBinary, MultiDiscrete, Sequence, Space, Text, Tuple
label_desc: Use image node_id 24 for calling a global function with example usage: _unflatten_graph(space, x) and returns: GraphInstance, ret