class_docstr: A function that executes the static schedule of a Chain.
  
  An instance of this class executes the static schedule of computations
  that are equivalent to executing the define-by-run code of a Chain.
  
  This class is used by the `static_graph` decorator to wrap the
  define-by-run
  computations of a chain into two static schedules:
  - The forward schedule corresponds to the computations that are executed by
  the define-by-run code of the `__call__()` method of a chain. The static
  schedule corresponding to these computations can be executed by calling the
  `forward()` method of this class.
  - The backward schedule corresponds to the computations that are executed
  by the sequence of calls to `Function.backward()` that occur during when
  backpropagating the gradients through the same chain. That is, for each
  `Function.forward()` that was called during the forward propagation,
  there will be a corresponding call to `Function.backward()` (of the
  same Function object) in the backward schedule. This backward schedule
  can be executed by calling the `backward()` method of this class.
  
  Note the intended usage of this class:
  
  Recall that a "static chain" referes to a chain that is decorated by the
  `static_graph` decorator.
  During the first forward pass of a static chain, the define-by-run code
  is executed. However,
  for subsequent iterations, that define-by-run code is replaced by an
  instance
  of this function and this function will be called instead. Since the
  static
  schedules contained by this function perform the same computations, it is
  safe (and potentially much more efficient) to simply execute the static
  schedule instead
  of the define-by-run code. See `static_graph` for details.
  
  Args:
      schedule_manager (ScheduleManager): The schedule manager of this
          schedule instance.
      in_vars (tuple of Variable): The flattened tuple of input variables
          that is supplied to
          `__call__()` method of the chain that this schedule corresponds to.
      unique_arrays (list of ndarray): A list of all unique array references
          deeply used in an StaticScheduleFunction instance. It is 'None'
          for the StaticScheduleFunction that corresponds to the "forward"
          schedule, but the contained StaticScheduleFunction for the
          "backward" schedule should take the unique_arrays of the
          "forward" schedule.
class_docstr_tok: ["A","function","that","executes","the","static","schedule","of","a","Chain",".","An","instance","of","this","class","executes","the","static","schedule","of","computations","that","are","equivalent","to","executing","the","define-by-run","code","of","a","Chain",".","This","class","is","used","by","the","`","static_graph","`","decorator","to","wrap","the","define-by-run","computations","of","a","chain","into","two","static","schedules",":","-","The","forward","schedule","corresponds","to","the","computations","that","are","executed","by","the","define-by-run","code","of","the","`","__call__","(",")","`","method","of","a","chain",".","The","static","schedule","corresponding","to","these","computations","can","be","executed","by","calling","the","`","forward","(",")","`","method","of","this","class",".","-","The","backward","schedule","corresponds","to","the","computations","that","are","executed","by","the","sequence","of","calls","to","`","Function.backward","(",")","`","that","occur","during","when","backpropagating","the","gradients","through","the","same","chain",".","That","is",",","for","each","`","Function.forward","(",")","`","that","was","called","during","the","forward","propagation",",","there","will","be","a","corresponding","call","to","`","Function.backward","(",")","`","(","of","the","same","Function","object",")","in","the","backward","schedule",".","This","backward","schedule","can","be","executed","by","calling","the","`","backward","(",")","`","method","of","this","class",".","Note","the","intended","usage","of","this","class",":","Recall","that","a","``","static","chain","''","referes","to","a","chain","that","is","decorated","by","the","`","static_graph","`","decorator",".","During","the","first","forward","pass","of","a","static","chain",",","the","define-by-run","code","is","executed",".","However",",","for","subsequent","iterations",",","that","define-by-run","code","is","replaced","by","an","instance","of","this","function","and","this","function","will","be","called","instead",".","Since","the","static","schedules","contained","by","this","function","perform","the","same","computations",",","it","is","safe","(","and","potentially","much","more","efficient",")","to","simply","execute","the","static","schedule","instead","of","the","define-by-run","code",".","See","`","static_graph","`","for","details",".","Args",":","schedule_manager","(","ScheduleManager",")",":","The","schedule","manager","of","this","schedule","instance",".","in_vars","(","tuple","of","Variable",")",":","The","flattened","tuple","of","input","variables","that","is","supplied","to","`","__call__","(",")","`","method","of","the","chain","that","this","schedule","corresponds","to",".","unique_arrays","(","list","of","ndarray",")",":","A","list","of","all","unique","array","references","deeply","used","in","an","StaticScheduleFunction","instance",".","It","is","'None'","for","the","StaticScheduleFunction","that","corresponds","to","the","``","forward","''","schedule",",","but","the","contained","StaticScheduleFunction","for","the","``","backward","''","schedule","should","take","the","unique_arrays","of","the","``","forward","''","schedule","."]
docstr: Build the static schedule.
  
  Perform one-time post-processing on the functions and arguments
  that were
  previously supplied in 'append_function()' to create the static
  schedule.
  
  This method must be called after the final call of 'append_function()'
  and before calling 'forward()' for the first time.
  
  Args:
      chain: The static chain that uses this scheudle.
      in_vars (list of Variable): The input variables to this static
          schedule. This are the input variables (each having no
          creator) of the local sub-graph corresponding to the
          static chain.
docstr_tok: ["Build","the","static","schedule",".","Perform","one-time","post-processing","on","the","functions","and","arguments","that","were","previously","supplied","in","'append_function","(",")","'","to","create","the","static","schedule",".","This","method","must","be","called","after","the","final","call","of","'append_function","(",")","'","and","before","calling","'forward","(",")","'","for","the","first","time",".","Args",":","chain",":","The","static","chain","that","uses","this","scheudle",".","in_vars","(","list","of","Variable",")",":","The","input","variables","to","this","static","schedule",".","This","are","the","input","variables","(","each","having","no","creator",")","of","the","local","sub-graph","corresponding","to","the","static","chain","."]
code: def build_schedule(self, chain, in_vars):
      """Build the static schedule.
  
      Perform one-time post-processing on the functions and arguments
      that were
      previously supplied in 'append_function()' to create the static
      schedule.
  
      This method must be called after the final call of 'append_function()'
      and before calling 'forward()' for the first time.
  
      Args:
          chain: The static chain that uses this scheudle.
          in_vars (list of Variable): The input variables to this static
              schedule. This are the input variables (each having no
              creator) of the local sub-graph corresponding to the
              static chain.
      """
      self.chain = chain
      self.in_vars = in_vars
  
      # Iterate through all array info objects and for any arrays that
      # still have a valid reference, copy into unique_arrays.
      if self.verbosity_level >= 2:
          print("Building schedule for pass depth: ", self.pass_depth)
      for ind, info in enumerate(self.unique_array_infos):
          if self.verbosity_level >= 2:
              print("unique array index: ", ind)
              print("array info: ", info)
          if not info.was_deleted():
              self.unique_arrays[ind] = info.weak_ref()
  
      # Verify that all array references are actually unique.
      unique_ids = set()
      for ar in self.unique_arrays:
          if ar is not None:
              assert id(ar) not in unique_ids
              unique_ids.add(id(ar))
  
      for param in chain.params():
          param_key = id(param)
          if param_key not in self.param_id_to_index:
              self.params_list.append(param)
              grad_var = param.grad_var
              self.grad_var_list.append(grad_var)
              param_index = len(self.params_list) - 1
              self.param_id_to_index[param_key] = param_index
          else:
              # We have seen this parameter before.
              param_index = self.param_id_to_index[param_key]
          grad_var = param.grad_var
          self.grad_var_list[param_index] = grad_var
          if param.data is not None:
              key = id(param.data)
              if key not in self.array_id_to_param_map:
                  self.array_id_to_param_map[key] = (
                      param_index,
                      "data",
                  )
          if param.grad is not None:
              key = id(param.grad)
              if key not in self.array_id_to_param_map:
                  self.array_id_to_param_map[key] = (
                      param_index,
                      "grad",
                  )
  
      for var_ind, in_var in enumerate(self.in_vars):
          assert in_var.data is not None
          key = id(in_var.data)
          self.array_id_to_input_var_map[key] = var_ind
  
      # Iterate over all arrays used in the schedule and check which ones
      # correspond to parameter arrays or input variables. When a match
      # is found, create a corresponding hook function. This hook will
      # run just before executing the schedule and set the array
      # references used in the schedule to be consistent with the
      # input variables and parameters.
      assert len(self.unique_arrays) > 0
      for unique_array_index, ar in enumerate(self.unique_arrays):
          key = id(ar)
          # Create pre-run parameter hooks.
          if key in self.array_id_to_param_map:
              param_attribute_location = self.array_id_to_param_map[key]
              param_hook = (
                  unique_array_index,
                  param_attribute_location,
              )
              self.param_hooks.append(param_hook)
          # Create pre-run input variable hooks.
          if key in self.array_id_to_input_var_map:
              in_var_ind = self.array_id_to_input_var_map[key]
              in_var_hook = (unique_array_index, in_var_ind)
              self.in_var_hooks.append(in_var_hook)
              if self.verbosity_level >= 2:
                  print(
                      "build_schedule(): Adding input variable hook: ",
                      in_var_hook,
                  )
                  print("For input variable: ", ar)
          # Create post-run hooks for any arrays that are dynamically
          # allocated inside the schedule.
          if (
              unique_array_index
              in self.dynamically_allocated_unique_index
          ):
              if key in self.array_id_to_param_map:
                  param_attribute_location = self.array_id_to_param_map[
                      key
                  ]
                  param_hook = (
                      unique_array_index,
                      param_attribute_location,
                  )
                  self.param_post_hooks.append(param_hook)
  
      if self.verbosity_level >= 2:
          print("self.param_hooks: ", self.param_hooks)
          self.debug_print_unique_arrays_info()
  
      # todo: We can potentially reduce memory usage by freeing memory
      # of intermediate arrays in self.unique_arrays
      # once they are no longer needed in the schedule or by
      # parameters.
  
      print("end of build_schedule()")
      self.schedule_built = True
  
imports: import sys
  import weakref
  import numpy
  import chainer
  from chainer.backends import cuda
  import chainer.function_node
label_desc: Use image node_id 14 for calling the StaticScheduleFunction obj's underlying member method code with example usage: obj.build_schedule(chain, in_vars) without return types