How do you order feature jobs by their prerequisites?
TopologicalSorter accepts predecessors per node and produces an order that respects dependencies. A cycle prevents a full ordering.
Python example and interpretation
Read data, clean it, then score. Independent tasks can admit several valid orderings, so one observed order adds no extra business constraint.
from graphlib import TopologicalSorter
list(TopologicalSorter({'score':['clean'],'clean':['read']}).static_order())Result ['read', 'clean', 'score']
中文
特征生成任务怎样按依赖关系安排执行?
TopologicalSorter 将节点映射到其前置节点并产生满足依赖的顺序;环路会阻止完整排序。
Python 算例与适用条件
先读数据再清洗,最后评分。对于互不依赖的节点,可能有多个合法顺序,不能把其中一个解释为额外业务约束。
from graphlib import TopologicalSorter
list(TopologicalSorter({'score':['clean'],'clean':['read']}).static_order())结果 ['read', 'clean', 'score']