dag
Visualize pipelines as one or more stage dependency graphs.
Synopsis
usage: dvc dag [-h] [-q | -v] [-o] [--full]
[--md] [--mermaid] [--dot]
[target]
positional arguments:
target Stage or output to show pipeline for (optional)
Uses all stages in the workspace by default.
Description
DVC represents each pipeline internally as a Directed Acyclic Graph (DAG) where the nodes are stages and the edges are dependencies.
dvc dag
displays this dependency graph of the stages in one or more pipelines,
as defined in the dvc.yaml
files found in the project. Provide a
target
stage name to show the pipeline up to that point.
Paginating the output
This command's output is automatically piped to
less if available in the terminal
(the exact command used is less --chop-long-lines --clear-screen
). If less
is not available (e.g. on Windows), the output is simply printed out.
It's also possible to enable
less
on Windows.
Note that this also applies to
dvc exp show
.
Providing a custom pager
It's possible to override the default pager via the DVC_PAGER
environment
variable. Set it to a program found in PATH
or give a full path to it. For
example on Linux shell:
$ DVC_PAGER=more dvc exp show # Use more as pager once.
...
$ export DVC_PAGER=more # Set more as pager for all commands.
$ dvc exp show ...
For a persistent change, set
DVC_PAGER
in the shell configuration, for example in~/.bashrc
for Bash.
Options
-
-o
,--outs
- show a DAG of chained dependencies and outputs instead of the stages themselves. The graph may be significantly different. -
--full
- show full DAG that thetarget
stage belongs to, instead of showing only its ancestors. -
--md
- show DAG in--mermaid
format, wrapped inside a Markdown fenced code block.This can be used to combine
dvc dag
withcml send-comment
-
--mermaid
- show DAG in Mermaid format. It can be passed to third party visualization utilities. -
--dot
- show DAG in DOT format. It can be passed to third party visualization utilities. -
-h
,--help
- prints the usage/help message, and exit. -
-q
,--quiet
- do not write anything to standard output. Exit with 0 if no problems arise, otherwise 1. -
-v
,--verbose
- displays detailed tracing information.
Example: Visualize a DVC Pipeline
Visualize the prepare, featurize, train, and evaluate stages of a pipeline as
defined in dvc.yaml
:
$ dvc dag
+---------+
| prepare |
+---------+
*
*
*
+-----------+
| featurize |
+-----------+
** **
** *
* **
+-------+ *
| train | **
+-------+ *
** **
** **
* *
+----------+
| evaluate |
+----------+
The pipeline can also be seen from the point of view of how stage
outputs/dependencies are connected (using the --outs
option). Notice that the
resulting graph may be different:
$ dvc dag --outs
+---------------+
| data/prepared |
+---------------+
*
*
*
+---------------+
| data/features |
**+---------------+**
**** * *****
***** * ****
**** * ****
*** +-----------+ ***
** | model.pkl | **
** +-----------+ **
** ** ** **
** ** ** **
** ** ** **
+-------------+ +----------+
| scores.json | | prc.json |
+-------------+ +----------+
Example: Mermaid flowchart
The --mermaid
flag will generate a
flowchart in Mermaid format:
$ dvc dag --mermaid
flowchart TD
node1["data/data.xml.dvc"]
node2["evaluate"]
node3["featurize"]
node4["prepare"]
node5["train"]
node1-->node4
node3-->node2
node3-->node5
node4-->node3
node5-->node2
When the --md
flag is passed, the mermaid output will be wrapped inside a
Markdown
fenced code block.
Note that this output is automatically rendered as a diagram
in GitHub
and in GitLab.
You can combine dvc dag --md
with the
cml send-comment
of CML:
dvc dag --md >> dag.md
cml send-comment dag.md