code: def _construct_dags(prev_nodes, activations, func_names, num_blocks):
      """Constructs a set of DAGs based on the actions, i.e., previous nodes and
      activation functions, sampled from the controller/policy pi.
  
      Args:
          prev_nodes: Previous node actions from the policy.
          activations: Activations sampled from the policy.
          func_names: Mapping from activation function names to functions.
          num_blocks: Number of blocks in the target RNN cell.
  
      Returns:
          A list of DAGs defined by the inputs.
  
      RNN cell DAGs are represented in the following way:
  
      1. Each element (node) in a DAG is a list of `Node`s.
  
      2. The `Node`s in the list dag[i] correspond to the subsequent nodes
         that take the output from node i as their own input.
  
      3. dag[-1] is the node that takes input from x^{(t)} and h^{(t - 1)}.
         dag[-1] always feeds dag[0].
         dag[-1] acts as if `w_xc`, `w_hc`, `w_xh` and `w_hh` are its
         weights.
  
      4. dag[N - 1] is the node that produces the hidden state passed to
         the next timestep. dag[N - 1] is also always a leaf node, and therefore
         is always averaged with the other leaf nodes and fed to the output
         decoder.
      """
      dags = []
      for nodes, func_ids in zip(prev_nodes, activations):
          dag = collections.defaultdict(list)
  
          # add first node
          dag[-1] = [Node(0, func_names[func_ids[0]])]
          dag[-2] = [Node(0, func_names[func_ids[0]])]
  
          # add following nodes
          for jdx, (idx, func_id) in enumerate(
              zip(nodes, func_ids[1:])
          ):
              dag[utils.to_item(idx)].append(
                  Node(jdx + 1, func_names[func_id])
              )
  
          leaf_nodes = set(range(num_blocks)) - dag.keys()
  
          # merge with avg
          for idx in leaf_nodes:
              dag[idx] = [Node(num_blocks, "avg")]
  
          # TODO(brendan): This is actually y^{(t)}. h^{(t)} is node N - 1 in
          # the graph, where N Is the number of nodes. I.e., h^{(t)} takes
          # only one other node as its input.
          # last h[t] node
          last_node = Node(num_blocks + 1, "h[t]")
          dag[num_blocks] = [last_node]
          dags.append(dag)
  
      return dags
  
file_path: ENAS-pytorch/models/controller.py
imports: import collections
  import os
  import torch
  import torch.nn.functional
  import utils
  from utils import Node
label_desc: Use image node_id 1 for calling a global function with example usage: _construct_dags(prev_nodes, activations, func_names, num_blocks) and returns: dags