code: def expression_expectation(
      mutable_expr: MutableExpression[float] | Any,
      weights: dict[str, list[float]],
  ) -> float:
      """Compute the expectation of a value choice.
  
      Parameters
      ----------
      mutable_expr
          The value choice to compute expectation.
      weights
          The weights of each leaf node.
  
      Returns
      -------
      float
          The expectation.
      """
      if not isinstance(mutable_expr, MutableExpression):
          return mutable_expr
  
      # Optimization: E(a + b) = E(a) + E(b)
      if (
          hasattr(mutable_expr, "function")
          and mutable_expr.function == operator.add
      ):
          return sum(
              expression_expectation(child, weights)
              for child in mutable_expr.arguments
          )
      # E(a - b) = E(a) - E(b)
      if (
          hasattr(mutable_expr, "function")
          and mutable_expr.function == operator.sub
      ):
          return expression_expectation(
              mutable_expr.arguments[0], weights
          ) - expression_expectation(mutable_expr.arguments[1], weights)
  
      all_options = traverse_all_options(
          mutable_expr, weights
      )  # [(option, weight), ...]
      options, option_weights = zip(
          *all_options
      )  # ([option, ...], [weight, ...])
      return weighted_sum(options, option_weights)
  
file_path: nni/nni/nas/oneshot/pytorch/supermodule/_expression_utils.py
imports: from __future__ import annotations
  import operator
  from typing import Any, TypeVar, List, cast, Mapping, Sequence, Optional, Iterable, overload
  import numpy
  import torch
  from nni.mutable import MutableExpression, Categorical
label_desc: Use image node_id 1 for calling a global function with example usage: expression_expectation(mutable_expr, weights) and returns: weighted_sum, mutable_expr, sum, unknown