def copy_sequence(sequence, collection, dag=None):
copied = sequence.copy()
if dag:
dag.add_node(copied)
is_copied = set()
for path in sequence.all_path(collection, strict=True):
curr = copied
for seq in path[1:-1]:
if id(seq) in is_copied:
continue
is_copied.add(id(seq))
After Change
stop_cond=lambda x: x is collection, unique=True):
if n is sequence:
copy(n)
continue
if n is collection:
continue
parents = [p for p in dag.successors(n) if p._node_id in traversed]