class_docstr: Abstract base class for all attack classes.
class_docstr_tok: ["Abstract","base","class","for","all","attack","classes","."]
docstr: Construct the graph required to run the attack through generate_np.
  
  :param fixed: Structural elements that require defining a new graph.
  :param feedable: Arguments that can be fed to the same graph when
                   they take different values.
  :param x_val: symbolic adversarial example
  :param hash_key: the key used to store this graph in our cache
docstr_tok: ["Construct","the","graph","required","to","run","the","attack","through","generate_np",".",":","param","fixed",":","Structural","elements","that","require","defining","a","new","graph",".",":","param","feedable",":","Arguments","that","can","be","fed","to","the","same","graph","when","they","take","different","values",".",":","param","x_val",":","symbolic","adversarial","example",":","param","hash_key",":","the","key","used","to","store","this","graph","in","our","cache"]
code: def construct_graph(self, fixed, feedable, x_val, hash_key):
      """
      Construct the graph required to run the attack through generate_np.
  
      :param fixed: Structural elements that require defining a new graph.
      :param feedable: Arguments that can be fed to the same graph when
                       they take different values.
      :param x_val: symbolic adversarial example
      :param hash_key: the key used to store this graph in our cache
      """
      # try our very best to create a TF placeholder for each of the
      # feedable keyword arguments, and check the types are one of
      # the allowed types
      class_name = str(self.__class__).split(".")[-1][:-2]
      _logger.info("Constructing new graph for attack " + class_name)
  
      # remove the None arguments, they are just left blank
      for k in list(feedable.keys()):
          if feedable[k] is None:
              del feedable[k]
  
      # process all of the rest and create placeholders for them
      new_kwargs = dict(x for x in fixed.items())
      for name, value in feedable.items():
          given_type = value.dtype
          if isinstance(value, np.ndarray):
              if value.ndim == 0:
                  # This is pretty clearly not a batch of data
                  new_kwargs[name] = tf.placeholder(
                      given_type, shape=[], name=name
                  )
              else:
                  # Assume that this is a batch of data, make the first axis variable
                  # in size
                  new_shape = [None] + list(value.shape[1:])
                  new_kwargs[name] = tf.placeholder(
                      given_type, new_shape, name=name
                  )
          elif isinstance(value, utils.known_number_types):
              new_kwargs[name] = tf.placeholder(
                  given_type, shape=[], name=name
              )
          else:
              raise ValueError(
                  "Could not identify type of argument "
                  + name
                  + ": "
                  + str(value)
              )
  
      # x is a special placeholder we always want to have
      x_shape = [None] + list(x_val.shape)[1:]
      x = tf.placeholder(self.tf_dtype, shape=x_shape)
  
      # now we generate the graph that we want
      x_adv = self.generate(x, **new_kwargs)
  
      self.graphs[hash_key] = (x, new_kwargs, x_adv)
  
      if len(self.graphs) >= 10:
          warnings.warn(
              "Calling generate_np() with multiple different "
              "structural parameters is inefficient and should"
              " be avoided. Calling generate() is preferred."
          )
  
file_path: cleverhans/cleverhans_v3.1.0/cleverhans/attacks/attack.py
imports: from abc import ABCMeta
  import collections
  import warnings
  import numpy
  import tensorflow
  from cleverhans.compat import reduce_max
  from cleverhans.model import Model
  from cleverhans import utils
label_desc: Use image node_id 3 for calling the Attack obj's underlying member method code with example usage: obj.construct_graph(fixed, feedable, x_val, hash_key) without return types