class_docstr: A class used to set and get weights for Tensorflow networks.
  
  Attributes:
      sess (tf.Session): The tensorflow session used to run assignment.
      variables (Dict[str, tf.Variable]): Extracted variables from the loss
          or additional variables that are passed in.
      placeholders (Dict[str, tf.placeholders]): Placeholders for weights.
      assignment_nodes (Dict[str, tf.Tensor]): Nodes that assign weights.
class_docstr_tok: ["A","class","used","to","set","and","get","weights","for","Tensorflow","networks",".","Attributes",":","sess","(","tf.Session",")",":","The","tensorflow","session","used","to","run","assignment",".","variables","(","Dict","[","str",",","tf.Variable","]",")",":","Extracted","variables","from","the","loss","or","additional","variables","that","are","passed","in",".","placeholders","(","Dict","[","str",",","tf.placeholders","]",")",":","Placeholders","for","weights",".","assignment_nodes","(","Dict","[","str",",","tf.Tensor","]",")",":","Nodes","that","assign","weights","."]
docstr: Creates TensorFlowVariables containing extracted variables.
  
  The variables are extracted by performing a BFS search on the
  dependency graph with loss as the root node. After the tree is
  traversed and those variables are collected, we append input_variables
  to the collected variables. For each variable in the list, the
  variable has a placeholder and assignment operation created for it.
  
  Args:
      output (tf.Operation, List[tf.Operation]): The tensorflow
          operation to extract all variables from.
      sess (Optional[tf.Session]): Optional tf.Session used for running
          the get and set methods in tf graph mode.
          Use None for tf eager.
      input_variables (List[tf.Variables]): Variables to include in the
          list.
docstr_tok: ["Creates","TensorFlowVariables","containing","extracted","variables",".","The","variables","are","extracted","by","performing","a","BFS","search","on","the","dependency","graph","with","loss","as","the","root","node",".","After","the","tree","is","traversed","and","those","variables","are","collected",",","we","append","input_variables","to","the","collected","variables",".","For","each","variable","in","the","list",",","the","variable","has","a","placeholder","and","assignment","operation","created","for","it",".","Args",":","output","(","tf.Operation",",","List","[","tf.Operation","]",")",":","The","tensorflow","operation","to","extract","all","variables","from",".","sess","(","Optional","[","tf.Session","]",")",":","Optional","tf.Session","used","for","running","the","get","and","set","methods","in","tf","graph","mode",".","Use","None","for","tf","eager",".","input_variables","(","List","[","tf.Variables","]",")",":","Variables","to","include","in","the","list","."]
code: def __init__(self, output, sess=None, input_variables=None):
      """Creates TensorFlowVariables containing extracted variables.
  
      The variables are extracted by performing a BFS search on the
      dependency graph with loss as the root node. After the tree is
      traversed and those variables are collected, we append input_variables
      to the collected variables. For each variable in the list, the
      variable has a placeholder and assignment operation created for it.
  
      Args:
          output (tf.Operation, List[tf.Operation]): The tensorflow
              operation to extract all variables from.
          sess (Optional[tf.Session]): Optional tf.Session used for running
              the get and set methods in tf graph mode.
              Use None for tf eager.
          input_variables (List[tf.Variables]): Variables to include in the
              list.
      """
      self.sess = sess
      output = force_list(output)
      queue = deque(output)
      variable_names = []
      explored_inputs = set(output)
  
      # We do a BFS on the dependency graph of the input function to find
      # the variables.
      while len(queue) != 0:
          tf_obj = queue.popleft()
          if tf_obj is None:
              continue
          # The object put into the queue is not necessarily an operation,
          # so we want the op attribute to get the operation underlying the
          # object. Only operations contain the inputs that we can explore.
          if hasattr(tf_obj, "op"):
              tf_obj = tf_obj.op
          for input_op in tf_obj.inputs:
              if input_op not in explored_inputs:
                  queue.append(input_op)
                  explored_inputs.add(input_op)
          # Tensorflow control inputs can be circular, so we keep track of
          # explored operations.
          for control in tf_obj.control_inputs:
              if control not in explored_inputs:
                  queue.append(control)
                  explored_inputs.add(control)
          if (
              "Variable" in tf_obj.node_def.op
              or "VarHandle" in tf_obj.node_def.op
          ):
              variable_names.append(tf_obj.node_def.name)
      self.variables = OrderedDict()
      variable_list = [
          v
          for v in tf1.global_variables()
          if v.op.node_def.name in variable_names
      ]
      if input_variables is not None:
          variable_list += input_variables
  
      if not tf1.executing_eagerly():
          for v in variable_list:
              self.variables[v.op.node_def.name] = v
  
          self.placeholders = {}
          self.assignment_nodes = {}
  
          # Create new placeholders to put in custom weights.
          for k, var in self.variables.items():
              self.placeholders[k] = tf1.placeholder(
                  var.value().dtype,
                  var.get_shape().as_list(),
                  name="Placeholder_" + k,
              )
              self.assignment_nodes[k] = var.assign(
                  self.placeholders[k]
              )
      else:
          for v in variable_list:
              self.variables[v.name] = v
  
file_path: ray/python/ray/experimental/tf_utils.py
imports: from collections import OrderedDict, deque
  import numpy
  from ray.rllib.utils import force_list
  from ray.rllib.utils.framework import try_import_tf
label_desc: Use image node_id 1 to create a new TensorFlowVariables object  with example: obj = TensorFlowVariables(output, sess, input_variables)