code: def parse(alpha, beta, k):
      """
      parse continuous alpha to discrete gene.
      alpha is ParameterList:
      ParameterList [
          Parameter(n_edges1, n_ops),
          Parameter(n_edges2, n_ops),
          ...
      ]
  
      beta is ParameterList:
      ParameterList [
          Parameter(n_edges1),
          Parameter(n_edges2),
          ...
      ]
  
      gene is list:
      [
          [('node1_ops_1', node_idx), ..., ('node1_ops_k', node_idx)],
          [('node2_ops_1', node_idx), ..., ('node2_ops_k', node_idx)],
          ...
      ]
      each node has two edges (k=2) in CNN.
      """
  
      gene = []
      assert (
          PRIMITIVES[-1] == "none"
      )  # 'none' is implemented in mutator now
  
      # 1) Convert the mixed op to discrete edge (single op) by choosing top-1 weight edge
      # 2) Choose top-k edges per node by edge score (top-1 weight in edge)
      # output the connect idx[(node_idx, connect_idx, op_idx).... () ()]
      connect_idx = []
      for edges, w in zip(alpha, beta):
          # edges: Tensor(n_edges, n_ops)
          edge_max, primitive_indices = torch.topk(
              (w.view(-1, 1) * edges)[:, :-1], 1
          )  # ignore 'none'
          topk_edge_values, topk_edge_indices = torch.topk(
              edge_max.view(-1), k
          )
          node_gene = []
          node_idx = []
          for edge_idx in topk_edge_indices:
              prim_idx = primitive_indices[edge_idx]
              prim = PRIMITIVES[prim_idx]
              node_gene.append((prim, edge_idx.item()))
              node_idx.append((edge_idx.item(), prim_idx.item()))
  
          gene.append(node_gene)
          connect_idx.append(node_idx)
  
      return gene, connect_idx
  
file_path: nni/examples/nas/legacy/cdarts/genotypes.py
imports: from collections import namedtuple
  import torch
  import torch.nn
  import torch.nn.functional
  import ops
  from ops import PRIMITIVES
label_desc: Use image node_id 3 for calling a global function with example usage: parse(alpha, beta, k) and returns: gene,  connect_idx