Repository: Qiskit/qiskit

Issue:
Need a dag visualizer
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues to confirm this idea does not exist. -->

### What is the expected behavior?
A dag visualizer is important for developing transpiler passes. It should be easy to use like the circuit visualizer.




Discussion:

Resolving patch:
diff --git a/qiskit/tools/visualization/__init__.py b/qiskit/tools/visualization/__init__.py
--- a/qiskit/tools/visualization/__init__.py
+++ b/qiskit/tools/visualization/__init__.py
@@ -5,7 +5,7 @@
 # This source code is licensed under the Apache License, Version 2.0 found in
 # the LICENSE.txt file in the root directory of this source tree.
 
-"""Main QISKit visualization methods."""
+"""Main Qiskit visualization methods."""
 
 import sys
 from qiskit._util import _has_connection
@@ -13,6 +13,7 @@
     latex_circuit_drawer, matplotlib_circuit_drawer, qx_color_scheme
 from ._error import VisualizationError
 from ._state_visualization import plot_bloch_vector
+from ._dag_visualization import dag_drawer
 
 
 if ('ipykernel' in sys.modules) and ('spyder' not in sys.modules):
diff --git a/qiskit/tools/visualization/_dag_visualization.py b/qiskit/tools/visualization/_dag_visualization.py
new file mode 100644
--- /dev/null
+++ b/qiskit/tools/visualization/_dag_visualization.py
@@ -0,0 +1,69 @@
+# -*- coding: utf-8 -*-
+
+# Copyright 2018, IBM.
+#
+# This source code is licensed under the Apache License, Version 2.0 found in
+# the LICENSE.txt file in the root directory of this source tree.
+
+# pylint: disable=invalid-name
+
+"""
+Visualization function for DAG circuit representation.
+"""
+
+import sys
+import copy
+import nxpd
+from ._error import VisualizationError
+
+
+def dag_drawer(dag, scale=0.7, filename=None, style='color'):
+    """Plot the directed acyclic graph (dag) to represent operation dependencies
+    in a quantum circuit.
+
+    Args:
+        dag (DAGCircuit): The dag to draw.
+        scale (float): scaling factor
+        filename (str): file path to save image to (format inferred from name)
+        style (str): 'plain': B&W graph
+                     'color' (default): color input/output/op nodes
+
+    Returns:
+        Ipython.display.Image: if in Jupyter notebook and not saving to file,
+            otherwise None.
+
+    Raises:
+        VisualizationError: when style is not recognized.
+    """
+    G = copy.deepcopy(dag.multi_graph)  # don't modify the original graph attributes
+    G.graph['dpi'] = 100 * scale
+
+    if style == 'plain':
+        pass
+    elif style == 'color':
+        for n in G.nodes:
+            G.nodes[n]['label'] = str(G.nodes[n]['name'])
+            if G.nodes[n]['type'] == 'op':
+                G.nodes[n]['color'] = 'blue'
+                G.nodes[n]['style'] = 'filled'
+                G.nodes[n]['fillcolor'] = 'lightblue'
+            if G.nodes[n]['type'] == 'in':
+                G.nodes[n]['color'] = 'black'
+                G.nodes[n]['style'] = 'filled'
+                G.nodes[n]['fillcolor'] = 'green'
+            if G.nodes[n]['type'] == 'out':
+                G.nodes[n]['color'] = 'black'
+                G.nodes[n]['style'] = 'filled'
+                G.nodes[n]['fillcolor'] = 'red'
+    else:
+        raise VisualizationError("Unrecognized style for the dag_drawer.")
+
+    show = nxpd.nxpdParams['show']
+    if filename:
+        show = False
+    elif ('ipykernel' in sys.modules) and ('spyder' not in sys.modules):
+        show = 'ipynb'
+    else:
+        show = True
+
+    return nxpd.draw(G, filename=filename, show=show)


Test patch: