code: def contract_expression(equation, *shapes, **kwargs):
      """
      Wrapper around :func:`opt_einsum.contract_expression` that optionally uses
      Pyro's cheap optimizer and optionally caches contraction paths.
  
      :param bool cache_path: whether to cache the contraction path.
          Defaults to True.
      """
      # memoize the contraction path
      cache_path = kwargs.pop("cache_path", True)
      if cache_path:
          kwargs_key = tuple(kwargs.items())
          key = equation, shapes, kwargs_key
          if key in _PATH_CACHE:
              return _PATH_CACHE[key]
  
      expr = opt_einsum.contract_expression(equation, *shapes, **kwargs)
      if cache_path:
          _PATH_CACHE[key] = expr
      return expr
  
imports: import opt_einsum
  from pyro.util import ignore_jit_warnings
label_desc: Use image node_id 1 for calling a global function with example usage: contract_expression(equation) and returns: expr, _PATH_CACHE