'Compute the Pipeline terms in the graph for the requested start and end
dates.
Parameters
graph : zipline.pipeline.graph.TermGraph
dates : pd.DatetimeIndex
Row labels for our root mask.
assets : pd.Int64Index
Column labels for our root mask.
initial_workspace : dict
Map from term -> output.
Must contain at least entry for `self._root_mask_term` whose shape
is `(len(dates), len(assets))`, but may contain additional
pre-computed terms for testing or optimization purposes.
Returns
results : dict
Dictionary mapping requested results to outputs.'

def compute_chunk(self, graph, dates, assets, initial_workspace):

    self._validate_compute_chunk_params(dates, assets, initial_workspace)
    get_loader = self.get_loader
    workspace = initial_workspace.copy()
    loader_group_key = juxt(get_loader, getitem(graph.extra_rows))
    loader_groups = groupby(loader_group_key, graph.loadable_terms)
    refcounts = graph.initial_refcounts(workspace)
    for term in graph.execution_order(refcounts):
        if (term in workspace):
            continue
        (mask, mask_dates) = graph.mask_and_dates_for_term(term, self._root_mask_term, workspace, dates)
        if isinstance(term, LoadableTerm):
            to_load = sorted(loader_groups[loader_group_key(term)], key=(lambda t: t.dataset))
            loader = get_loader(term)
            loaded = loader.load_adjusted_array(to_load, mask_dates, assets, mask)
            assert (set(loaded) == set(to_load)), ('loader    did    not    return    an    AdjustedArray    for    each    column\nexpected:    %r\ngot:                        %r' % (sorted(to_load), sorted(loaded)))
            workspace.update(loaded)
        else:
            workspace[term] = term._compute(self._inputs_for_term(term, workspace, graph), mask_dates, assets, mask)
            if (term.ndim == 2):
                assert (workspace[term].shape == mask.shape)
            else:
                assert (workspace[term].shape == (mask.shape[0], 1))
            for garbage_term in graph.decref_dependencies(term, refcounts):
                del workspace[garbage_term]
    out = {}
    graph_extra_rows = graph.extra_rows
    for (name, term) in iteritems(graph.outputs):
        out[name] = workspace[term][graph_extra_rows[term]:]
    return out
