<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ancestors(self, start, generations=None):
 """ Return the subgraph of all nodes from which the given vertex is reachable, including that vertex. If specified, the optional `generations` argument specifies how many generations to limit to. """

        visited = self.vertex_set()
        visited.add(start)
        to_visit = deque([(start, 0)])
        while to_visit:
            vertex, depth = to_visit.popleft()
            if depth == generations:
                continue
            for parent in self.parents(vertex):
                if parent not in visited:
                    visited.add(parent)
                    to_visit.append((parent, depth+1))
        return self.full_subgraph(visited)