code: def retrace_from_importance_weights(
      log_rhos,
      discounts,
      rewards,
      q_values,
      values,
      bootstrap_value,
      lambda_=1.0,
      name="retrace_from_importance_weights",
  ):
      """Constructs Q/Retrace ops.
  
      This is an implementation of Retrace. In the description of the arguments
      the notation is as follows: `T` refers to the sequence size over which
      the return is calculated, finally `B` denotes the batch size.
  
      Args:
        log_rhos: Log-probabilities for target policy. Shape [T, B]
        discounts: Also called pcontinues. Discount encountered when following
          the behaviour policy. Shape [T, B].
        rewards: A tensor containing rewards generated by following the behaviour
          policy. Shape [T, B].
        q_values: Q-function estimates wrt. the target policy. Shape [T, B].
        values: Value function estimates wrt. the target policy. Shape [T, B].
        bootstrap_value: Value function estimate at time `T`. Shape [B].
        lambda_: Mix between 1-step (lambda_=0) and n-step (lambda_=1).
        name: The name scope that all qtrace ops will be created in.
  
      Returns:
        A `QTraceReturns` namedtuple containing:
  
          * qs: The Retrace regression/policy gradient targets.
            Can be used to calculate estimates of the advantage for policy
            gradients or as regression target for Q-value functions. Shape [T, B].
          * importance_weights: Importance sampling weights. Shape [T, B].
          * log_importance_weights: Importance sampling weights. Shape [T, B].
          * truncated_importance_weights: Called c_t in the paper. Shape [T, B].
          * deltas: Shape [T, B]
          * vs_minus_q_xs: Q-Retrace targets - Q(x_s, u_s). Shape [T, B].
  
      Raises:
        ValueError: If compiled=True, but log_rhos has rank other than 2.
      """
      # Make sure tensor ranks are consistent.
      rho_rank = log_rhos.get_shape().ndims  # Usually 2.
      q_values.get_shape().assert_has_rank(rho_rank)
      values.get_shape().assert_has_rank(rho_rank)
      bootstrap_value.get_shape().assert_has_rank(rho_rank - 1)
      discounts.get_shape().assert_has_rank(rho_rank)
      rewards.get_shape().assert_has_rank(rho_rank)
  
      lambda_ = tf.convert_to_tensor(lambda_, dtype=tf.float32)
  
      with tf.name_scope(
          name,
          values=[
              log_rhos,
              discounts,
              rewards,
              values,
              bootstrap_value,
          ],
      ):
          rhos = tf.exp(log_rhos)
  
          cs = tf.minimum(1.0, rhos, name="cs")
  
          # Set the last c to 1.
          cs = tf.concat([cs[1:], tf.ones_like(cs[-1:])], axis=0)
          cs *= lambda_
  
          # Append bootstrapped value to get [v1, ..., v_t+1]
          values_t_plus_1 = tf.concat(
              [values[1:], tf.expand_dims(bootstrap_value, 0)], axis=0
          )
  
          # delta_t = (r_t + discount * V(x_{t+1}) - Q(x_t, a_t))
          deltas = rewards + discounts * values_t_plus_1 - q_values
  
          # Note that all sequences are reversed, computation starts from the back.
          sequences = (
              tf.reverse(discounts, axis=[0]),
              tf.reverse(cs, axis=[0]),
              tf.reverse(deltas, axis=[0]),
          )
  
          # Re-trace vs are calculated through a scan from the back to the beginning
          # of the given trajectory.
          def scanfunc(acc, sequence_item):
              discount_t, c_t, delta_t = sequence_item
              return delta_t + discount_t * c_t * acc
  
          initial_values = tf.zeros_like(bootstrap_value)
          vs_minus_q_xs = tf.scan(
              fn=scanfunc,
              elems=sequences,
              initializer=initial_values,
              parallel_iterations=1,
              back_prop=False,
              name="scan",
          )
          # Reverse the results back to original order.
          vs_minus_q_xs = tf.reverse(
              vs_minus_q_xs, [0], name="vs_minus_q_xs"
          )
  
          # Add V(x_s) to get q targets.
          qs = tf.add(vs_minus_q_xs, q_values, name="s")
  
          result = QTraceReturns(
              qs=tf.stop_gradient(qs),
              importance_weights=tf.stop_gradient(rhos),
              log_importance_weights=tf.stop_gradient(log_rhos),
              truncated_importance_weights=tf.stop_gradient(cs),
              deltas=tf.stop_gradient(deltas),
              vs_minus_q_xs=tf.stop_gradient(vs_minus_q_xs),
          )
          return result
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import collections
  import tensorflow.compat.v1
label_desc: Use image node_id 2 for calling a global function with example usage: retrace_from_importance_weights(log_rhos, discounts, rewards, q_values, values, bootstrap_value, lambda_, name) and returns: result, unknown