class_docstr: Implementation of Cell under differentiable context.
  
  Similar to PathSamplingCell, this cell only handles cells of specific kinds (e.g., with loose end).
  
  An architecture parameter is created on each edge of the full-connected graph.
class_docstr_tok: ["Implementation","of","Cell","under","differentiable","context",".","Similar","to","PathSamplingCell",",","this","cell","only","handles","cells","of","specific","kinds","(","e.g.",",","with","loose","end",")",".","An","architecture","parameter","is","created","on","each","edge","of","the","full-connected","graph","."]
docstr: Tricky export.
  
  Reference: https://github.com/quark0/darts/blob/f276dd346a09ae3160f8e3aca5c7b193fda1da37/cnn/model_search.py#L135
docstr_tok: ["Tricky","export",".","Reference",":","https",":","\/\/github.com\/quark0\/darts\/blob\/f276dd346a09ae3160f8e3aca5c7b193fda1da37\/cnn\/model_search.py","#","L135"]
code: def export(self, memo):
      """Tricky export.
  
      Reference: https://github.com/quark0/darts/blob/f276dd346a09ae3160f8e3aca5c7b193fda1da37/cnn/model_search.py#L135
      """
      exported = {}
      for i in range(
          self.num_predecessors, self.num_nodes + self.num_predecessors
      ):
          # If label already exists, no need to re-export.
          if all(
              f"{self.label}/op_{i}_{k}" in memo
              and f"{self.label}/input_{i}_{k}" in memo
              for k in range(self.num_ops_per_node)
          ):
              continue
  
          # Tuple of (weight, input_index, op_name)
          all_weights: list[tuple[float, int, str]] = []
          for j in range(i):
              for k, name in enumerate(self.op_names):
                  # The last appended weight is automatically skipped in export.
                  all_weights.append(
                      (
                          float(
                              self._arch_alpha[f"{self.label}/{i}_{j}"][
                                  k
                              ].item()
                          ),
                          j,
                          name,
                      )
                  )
  
          all_weights.sort(reverse=True)
          # We first prefer inputs from different input_index.
          # If we have got no other choices, we start to accept duplicates.
          # Therefore we gather first occurrences of distinct input_index to the front.
          first_occurrence_index: list[int] = [
              all_weights.index(  # The index of
                  next(
                      filter(lambda t: t[1] == j, all_weights)
                  )  # First occurence of j
              )
              for j in range(i)  # For j < i
          ]
          first_occurrence_index.sort()  # Keep them ordered too.
  
          all_weights = [
              all_weights[k] for k in first_occurrence_index
          ] + [
              w
              for j, w in enumerate(all_weights)
              if j not in first_occurrence_index
          ]
  
          _logger.info(
              "Sorted weights in differentiable cell export (%s cell, node %d): %s",
              self.label,
              i,
              all_weights,
          )
  
          for k in range(self.num_ops_per_node):
              # all_weights could be too short in case ``num_ops_per_node`` is too large.
              _, j, op_name = all_weights[k % len(all_weights)]
              exported[f"{self.label}/op_{i}_{k}"] = op_name
              exported[f"{self.label}/input_{i}_{k}"] = [j]
  
      return exported
  
imports: from __future__ import annotations
  import functools
  import logging
  import warnings
  from typing import Any, Dict, Sequence, List, Tuple, cast
  import torch
  import torch.nn
  import torch.nn.functional
  from nni.mutable import MutableExpression, Mutable, Categorical
  from nni.nas.nn.pytorch import LayerChoice, InputChoice, Repeat
  from nni.nas.nn.pytorch.cell import preprocess_cell_inputs
  from .base import BaseSuperNetModule
  from .operation import MixedOperation, MixedOperationSamplingPolicy
  from .sampling import PathSamplingCell
  from ._expression_utils import traverse_all_options, weighted_sum
label_desc: Use image node_id 4 for calling the DifferentiableMixedCell obj's underlying member method code with example usage: obj.export(memo) and returns: exported