Repository: Qiskit/qiskit

Issue:
Cleanup mpl circuit_drawer module (post 0.7)
<!-- ⚠️ 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 enhancement?

As pointed out in the review for https://github.com/Qiskit/qiskit-terra/pull/1450 there are a few artifacts leftover from the json->dag conversion for the mpl backend. Things like misleading variable names and out of date notes and comments. After the 0.7 release it would be good to go through the module and clean this up to make maintenance easier.


Discussion:
@nkanazawa1989 @mtreinish OK. Let's discuss about it together.

Resolving patch:
diff --git a/qiskit/tools/visualization/_matplotlib.py b/qiskit/tools/visualization/_matplotlib.py
--- a/qiskit/tools/visualization/_matplotlib.py
+++ b/qiskit/tools/visualization/_matplotlib.py
@@ -32,7 +32,7 @@
 
 logger = logging.getLogger(__name__)
 
-Register = collections.namedtuple('Register', 'name index')
+Register = collections.namedtuple('Register', 'reg index')
 
 WID = 0.65
 HIG = 0.65
@@ -137,13 +137,12 @@ def parse_circuit(self, circuit):
         self._ops = ops
 
     def _registers(self, creg, qreg):
-        # NOTE: formats of clbit and qubit are different!
         self._creg = []
         for e in creg:
-            self._creg.append(Register(name=e[0], index=e[1]))
+            self._creg.append(Register(reg=e[0], index=e[1]))
         self._qreg = []
         for e in qreg:
-            self._qreg.append(Register(name=e[0], index=e[1]))
+            self._qreg.append(Register(reg=e[0], index=e[1]))
 
     @property
     def ast(self):
@@ -363,15 +362,15 @@ def _draw_regs(self):
         # quantum register
         for ii, reg in enumerate(self._qreg):
             if len(self._qreg) > 1:
-                label = '${}_{{{}}}$'.format(reg.name.name, reg.index)
+                label = '${}_{{{}}}$'.format(reg.reg.name, reg.index)
             else:
-                label = '${}$'.format(reg.name.name)
+                label = '${}$'.format(reg.reg.name)
             pos = -ii
             self._qreg_dict[ii] = {
                 'y': pos,
                 'label': label,
                 'index': reg.index,
-                'group': reg.name
+                'group': reg.reg
             }
             self._cond['n_lines'] += 1
         # classical register
@@ -384,22 +383,22 @@ def _draw_regs(self):
                     self._creg, n_creg)):
                 pos = y_off - idx
                 if self._style.bundle:
-                    label = '${}$'.format(reg.name.name)
+                    label = '${}$'.format(reg.reg.name)
                     self._creg_dict[ii] = {
                         'y': pos,
                         'label': label,
                         'index': reg.index,
-                        'group': reg.name
+                        'group': reg.reg
                     }
-                    if not (not nreg or reg.name != nreg.name):
+                    if not (not nreg or reg.reg != nreg.reg):
                         continue
                 else:
-                    label = '${}_{{{}}}$'.format(reg.name.name, reg.index)
+                    label = '${}_{{{}}}$'.format(reg.reg.name, reg.index)
                     self._creg_dict[ii] = {
                         'y': pos,
                         'label': label,
                         'index': reg.index,
-                        'group': reg.name
+                        'group': reg.reg
                     }
                 self._cond['n_lines'] += 1
                 idx += 1


Test patch: