code: def to_dag(C_in, gene, reduction, bn_affine=True):
      """generate discrete ops from gene"""
      dag = nn.ModuleList()
      for edges in gene:
          row = nn.ModuleList()
          for op_name, s_idx in edges:
              # reduction cell & from input nodes => stride = 2
              stride = 2 if reduction and s_idx < 2 else 1
              op = ops.OPS[op_name](C_in, stride, bn_affine)
              if not isinstance(
                  op, ops.Identity
              ):  # Identity does not use drop path
                  op = nn.Sequential(op, ops.DropPath_())
              op.s_idx = s_idx
              row.append(op)
          dag.append(row)
  
      return dag
  
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 1 for calling a global function with example usage: to_dag(C_in, gene, reduction, bn_affine) and returns: dag