class_docstr: Graph represention of Pipeline Term dependencies that includes metadata
  about extra rows required to perform computations.
  
  Each node in the graph has an `extra_rows` attribute, indicating how many,
  if any, extra rows we should compute for the node.  Extra rows are most
  often needed when a term is an input to a rolling window computation.  For
  example, if we compute a 30 day moving average of price from day X to day
  Y, we need to load price data for the range from day (X - 29) to day Y.
  
  Parameters
  ----------
  domain : zipline.pipeline.domain.Domain
      The domain of execution for which we need to build a plan.
  terms : dict
      A dict mapping names to final output terms.
  start_date : pd.Timestamp
      The first date for which output is requested for ``terms``.
  end_date : pd.Timestamp
      The last date for which output is requested for ``terms``.
  
  Attributes
  ----------
  domain
  extra_rows
  outputs
  offset
class_docstr_tok: ["Graph","represention","of","Pipeline","Term","dependencies","that","includes","metadata","about","extra","rows","required","to","perform","computations",".","Each","node","in","the","graph","has","an","`","extra_rows","`","attribute",",","indicating","how","many",",","if","any",",","extra","rows","we","should","compute","for","the","node",".","Extra","rows","are","most","often","needed","when","a","term","is","an","input","to","a","rolling","window","computation",".","For","example",",","if","we","compute","a","30","day","moving","average","of","price","from","day","X","to","day","Y",",","we","need","to","load","price","data","for","the","range","from","day","(","X","-","29",")","to","day","Y.","Parameters","--","--","--","--","--","domain",":","zipline.pipeline.domain.Domain","The","domain","of","execution","for","which","we","need","to","build","a","plan",".","terms",":","dict","A","dict","mapping","names","to","final","output","terms",".","start_date",":","pd.Timestamp","The","first","date","for","which","output","is","requested","for","``","terms","``",".","end_date",":","pd.Timestamp","The","last","date","for","which","output","is","requested","for","``","terms","``",".","Attributes","--","--","--","--","--","domain","extra_rows","outputs","offset"]
docstr: For all pairs (term, input) such that `input` is an input to `term`,
  compute a mapping::
  
      (term, input) -> offset(term, input)
  
  where ``offset(term, input)`` is the number of rows that ``term``
  should truncate off the raw array produced for ``input`` before using
  it. We compute this value as follows::
  
      offset(term, input) = (extra_rows_computed(input)
                             - extra_rows_computed(term)
                             - requested_extra_rows(term, input))
  Examples
  --------
  
  Case 1
  ~~~~~~
  
  Factor A needs 5 extra rows of USEquityPricing.close, and Factor B
  needs 3 extra rows of the same.  Factor A also requires 5 extra rows of
  USEquityPricing.high, which no other Factor uses.  We don't require any
  extra rows of Factor A or Factor B
  
  We load 5 extra rows of both `price` and `high` to ensure we can
  service Factor A, and the following offsets get computed::
  
      offset[Factor A, USEquityPricing.close] == (5 - 0) - 5 == 0
      offset[Factor A, USEquityPricing.high]  == (5 - 0) - 5 == 0
      offset[Factor B, USEquityPricing.close] == (5 - 0) - 3 == 2
      offset[Factor B, USEquityPricing.high] raises KeyError.
  
  Case 2
  ~~~~~~
  
  Factor A needs 5 extra rows of USEquityPricing.close, and Factor B
  needs 3 extra rows of Factor A, and Factor B needs 2 extra rows of
  USEquityPricing.close.
  
  We load 8 extra rows of USEquityPricing.close (enough to load 5 extra
  rows of Factor A), and the following offsets get computed::
  
      offset[Factor A, USEquityPricing.close] == (8 - 3) - 5 == 0
      offset[Factor B, USEquityPricing.close] == (8 - 0) - 2 == 6
      offset[Factor B, Factor A]              == (3 - 0) - 3 == 0
  
  Notes
  -----
  `offset(term, input) >= 0` for all valid pairs, since `input` must be
  an input to `term` if the pair appears in the mapping.
  
  This value is useful because we load enough rows of each input to serve
  all possible dependencies.  However, for any given dependency, we only
  want to compute using the actual number of required extra rows for that
  dependency.  We can do so by truncating off the first `offset` rows of
  the loaded data for `input`.
  
  See Also
  --------
  :meth:`zipline.pipeline.graph.ExecutionPlan.offset`
  :meth:`zipline.pipeline.engine.ExecutionPlan.mask_and_dates_for_term`
  :meth:`zipline.pipeline.engine.SimplePipelineEngine._inputs_for_term`
docstr_tok: ["For","all","pairs","(","term",",","input",")","such","that","`","input","`","is","an","input","to","`","term","`",",","compute","a","mapping",":",":","(","term",",","input",")","-",">","offset","(","term",",","input",")","where","``","offset","(","term",",","input",")","``","is","the","number","of","rows","that","``","term","``","should","truncate","off","the","raw","array","produced","for","``","input","``","before","using","it",".","We","compute","this","value","as","follows",":",":","offset","(","term",",","input",")","=","(","extra_rows_computed","(","input",")","-","extra_rows_computed","(","term",")","-","requested_extra_rows","(","term",",","input",")",")","Examples","--","--","--","--","Case","1","~~~~~~","Factor","A","needs","5","extra","rows","of","USEquityPricing.close",",","and","Factor","B","needs","3","extra","rows","of","the","same",".","Factor","A","also","requires","5","extra","rows","of","USEquityPricing.high",",","which","no","other","Factor","uses",".","We","do","n't","require","any","extra","rows","of","Factor","A","or","Factor","B","We","load","5","extra","rows","of","both","`","price","`","and","`","high","`","to","ensure","we","can","service","Factor","A",",","and","the","following","offsets","get","computed",":",":","offset","[","Factor","A",",","USEquityPricing.close","]","==","(","5","-","0",")","-","5","==","0","offset","[","Factor","A",",","USEquityPricing.high","]","==","(","5","-","0",")","-","5","==","0","offset","[","Factor","B",",","USEquityPricing.close","]","==","(","5","-","0",")","-","3","==","2","offset","[","Factor","B",",","USEquityPricing.high","]","raises","KeyError",".","Case","2","~~~~~~","Factor","A","needs","5","extra","rows","of","USEquityPricing.close",",","and","Factor","B","needs","3","extra","rows","of","Factor","A",",","and","Factor","B","needs","2","extra","rows","of","USEquityPricing.close",".","We","load","8","extra","rows","of","USEquityPricing.close","(","enough","to","load","5","extra","rows","of","Factor","A",")",",","and","the","following","offsets","get","computed",":",":","offset","[","Factor","A",",","USEquityPricing.close","]","==","(","8","-","3",")","-","5","==","0","offset","[","Factor","B",",","USEquityPricing.close","]","==","(","8","-","0",")","-","2","==","6","offset","[","Factor","B",",","Factor","A","]","==","(","3","-","0",")","-","3","==","0","Notes","--","--","-","`","offset","(","term",",","input",")",">","=","0","`","for","all","valid","pairs",",","since","`","input","`","must","be","an","input","to","`","term","`","if","the","pair","appears","in","the","mapping",".","This","value","is","useful","because","we","load","enough","rows","of","each","input","to","serve","all","possible","dependencies",".","However",",","for","any","given","dependency",",","we","only","want","to","compute","using","the","actual","number","of","required","extra","rows","for","that","dependency",".","We","can","do","so","by","truncating","off","the","first","`","offset","`","rows","of","the","loaded","data","for","`","input","`",".","See","Also","--","--","--","--",":","meth",":","`","zipline.pipeline.graph.ExecutionPlan.offset","`",":","meth",":","`","zipline.pipeline.engine.ExecutionPlan.mask_and_dates_for_term","`",":","meth",":","`","zipline.pipeline.engine.SimplePipelineEngine._inputs_for_term","`"]
code: def offset(self):
      """
      For all pairs (term, input) such that `input` is an input to `term`,
      compute a mapping::
  
          (term, input) -> offset(term, input)
  
      where ``offset(term, input)`` is the number of rows that ``term``
      should truncate off the raw array produced for ``input`` before using
      it. We compute this value as follows::
  
          offset(term, input) = (extra_rows_computed(input)
                                 - extra_rows_computed(term)
                                 - requested_extra_rows(term, input))
      Examples
      --------
  
      Case 1
      ~~~~~~
  
      Factor A needs 5 extra rows of USEquityPricing.close, and Factor B
      needs 3 extra rows of the same.  Factor A also requires 5 extra rows of
      USEquityPricing.high, which no other Factor uses.  We don't require any
      extra rows of Factor A or Factor B
  
      We load 5 extra rows of both `price` and `high` to ensure we can
      service Factor A, and the following offsets get computed::
  
          offset[Factor A, USEquityPricing.close] == (5 - 0) - 5 == 0
          offset[Factor A, USEquityPricing.high]  == (5 - 0) - 5 == 0
          offset[Factor B, USEquityPricing.close] == (5 - 0) - 3 == 2
          offset[Factor B, USEquityPricing.high] raises KeyError.
  
      Case 2
      ~~~~~~
  
      Factor A needs 5 extra rows of USEquityPricing.close, and Factor B
      needs 3 extra rows of Factor A, and Factor B needs 2 extra rows of
      USEquityPricing.close.
  
      We load 8 extra rows of USEquityPricing.close (enough to load 5 extra
      rows of Factor A), and the following offsets get computed::
  
          offset[Factor A, USEquityPricing.close] == (8 - 3) - 5 == 0
          offset[Factor B, USEquityPricing.close] == (8 - 0) - 2 == 6
          offset[Factor B, Factor A]              == (3 - 0) - 3 == 0
  
      Notes
      -----
      `offset(term, input) >= 0` for all valid pairs, since `input` must be
      an input to `term` if the pair appears in the mapping.
  
      This value is useful because we load enough rows of each input to serve
      all possible dependencies.  However, for any given dependency, we only
      want to compute using the actual number of required extra rows for that
      dependency.  We can do so by truncating off the first `offset` rows of
      the loaded data for `input`.
  
      See Also
      --------
      :meth:`zipline.pipeline.graph.ExecutionPlan.offset`
      :meth:`zipline.pipeline.engine.ExecutionPlan.mask_and_dates_for_term`
      :meth:`zipline.pipeline.engine.SimplePipelineEngine._inputs_for_term`
      """
      extra = self.extra_rows
  
      out = {}
      for term in self.graph:
          for dep, requested_extra_rows in term.dependencies.items():
              specialized_dep = maybe_specialize(dep, self.domain)
  
              # How much bigger is the result for dep compared to term?
              size_difference = extra[specialized_dep] - extra[term]
  
              # Subtract the portion of that difference that was required by
              # term's lookback window.
              offset = size_difference - requested_extra_rows
              out[term, specialized_dep] = offset
  
      return out
  
imports: import uuid
  import networkx
  from six import iteritems, itervalues
  from zipline.utils.memoize import lazyval
  from zipline.pipeline.visualize import display_graph
  from .term import LoadableTerm
label_desc: Use image node_id 3 for calling the ExecutionPlan obj's underlying member method code with example usage: obj.offset() and returns: out