Skip to content

Sort dvc pipeline list #2669

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions dvc/command/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,18 @@ def run(self):

class CmdPipelineList(CmdBase):
def run(self):
import networkx
import networkx as nx

pipelines = self.repo.pipelines
for p in pipelines:
stages = networkx.get_node_attributes(p, "stage")
for stage in stages:
logger.info(stage)
stages = nx.get_node_attributes(p, "stage")
for node in p:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I'm wrong, but what you are doing here is you are walking through all nodes in the pipeline in the random order, then you do a dfs_postorder for each one of those and then just print it. This is basically the same as what it was before but now with a redundant step of dfs_postorder_nodes. 🙂 Looks like we can do better than that 🙂

Copy link
Contributor

@efiop efiop Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good way to think about it is to imagine how the pipeline looks. So it has a N start nodes (p.out_degree(node) == 0), M end nodes (p.in_degree(node) == 0) and some nodes between them. The way dvc repro --pipeline works, is it finds all end nodes and for each of them does dfs_postorder_nodes and just runs those. But obviously, that real order of execution is not going to look good here 🙁 Could we somehow order them better here? Maybe nx.topological_sort(p)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation. I'll work on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p.out_degree(node) == 0 for end nodes and p.in_degree(node) == 0 for start nodes right?

Copy link
Contributor

@efiop efiop Oct 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SrividyaKK Actually no, our DAG has a reversed shape right now because we put edges in the direction from dependent stage to the one it depends on. So say your pipeline is cleanup step and then process step, then DAG would look like cleanup <- process. Just a caveat of the current design, we might change it in the future 😉

stage = stages[node]
# if not stage.locked:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't leave commented-out code like that. Looks like you don't need it, right? If so - remove it.

# continue
for n in nx.dfs_postorder_nodes(p, node):
if n == node:
logger.info(stage)
if len(stages) != 0:
logger.info("=" * 80)
logger.info("{} pipelines total".format(len(pipelines)))
Expand Down