Repository: Qiskit/qiskit

Issue:
text visualizer should not use transpiler(format='json')
We are going to remove the option `format='json'` from the transpiler (see #1129). For that, we need to move the visualizers into the function `get_instractions` introduced in PR #1187.

The function `_text_circuit_drawer` calls `transpile_dag(dag_circuit, basis_gates=basis, format='json')`. This needs to be removed in favor of `_utils.get_instructions(dag)`.


Discussion:

Resolving patch:
diff --git a/qiskit/tools/visualization/_circuit_visualization.py b/qiskit/tools/visualization/_circuit_visualization.py
--- a/qiskit/tools/visualization/_circuit_visualization.py
+++ b/qiskit/tools/visualization/_circuit_visualization.py
@@ -320,8 +320,7 @@ def qx_color_scheme():
 # -----------------------------------------------------------------------------
 
 
-def _text_circuit_drawer(circuit, filename=None,
-                         line_length=None, reversebits=False,
+def _text_circuit_drawer(circuit, filename=None, line_length=None, reversebits=False,
                          plotbarriers=True):
     """
     Draws a circuit using ascii art.
@@ -338,11 +337,8 @@ def _text_circuit_drawer(circuit, filename=None,
     Returns:
         TextDrawing: An instances that, when printed, draws the circuit in ascii art.
     """
-    basis = ("id,u0,u1,u2,u3,x,y,z,h,s,sdg,t,tdg,rx,ry,rz,"
-             "cx,cy,cz,ch,crz,cu1,cu3,swap,ccx,cswap")
-    dag_circuit = DAGCircuit.fromQuantumCircuit(circuit, expand_gates=False)
-    json_circuit = transpile_dag(dag_circuit, basis_gates=basis, format='json')
-    text_drawing = _text.TextDrawing(json_circuit, reversebits=reversebits)
+    qregs, cregs, ops = _utils._get_instructions(circuit, reversebits=reversebits)
+    text_drawing = _text.TextDrawing(qregs, cregs, ops)
     text_drawing.plotbarriers = plotbarriers
     text_drawing.line_length = line_length
 
diff --git a/qiskit/tools/visualization/_text.py b/qiskit/tools/visualization/_text.py
--- a/qiskit/tools/visualization/_text.py
+++ b/qiskit/tools/visualization/_text.py
@@ -9,7 +9,6 @@
 A module for drawing circuits in ascii art or some other text representation
 """
 
-from itertools import groupby
 from shutil import get_terminal_size
 
 from ._error import VisualizationError
@@ -401,13 +400,13 @@ def fillup_layer(names):  # pylint: disable=arguments-differ
 class TextDrawing():
     """ The text drawing"""
 
-    def __init__(self, json_circuit, reversebits=False, plotbarriers=True, line_length=None):
-        self.json_circuit = json_circuit
-        self.reversebits = reversebits
+    def __init__(self, qregs, cregs, instructions, plotbarriers=True, line_length=None):
+        self.qregs = qregs
+        self.cregs = cregs
+        self.instructions = instructions
+
         self.plotbarriers = plotbarriers
         self.line_length = line_length
-        self.qubitorder = self._get_qubitorder()
-        self.clbitorder = self._get_clbitorder()
 
     def __str__(self):
         return self.single_string()
@@ -417,45 +416,16 @@ def _repr_html_(self):
 
     def _get_qubit_labels(self):
         qubits = []
-        for qubit in self.json_circuit['header']['qubit_labels']:
+        for qubit in self.qregs:
             qubits.append("%s_%s" % (qubit[0], qubit[1]))
         return qubits
 
     def _get_clbit_labels(self):
         clbits = []
-        for creg in self.json_circuit['header']['clbit_labels']:
-            for clbit in range(creg[1]):
-                clbits.append("%s_%s" % (creg[0], clbit))
+        for clbit in self.cregs:
+            clbits.append("%s_%s" % (clbit[0], clbit[1]))
         return clbits
 
-    def _get_qubitorder(self):
-        header = self.json_circuit['header']
-
-        if not self.reversebits:
-            return [qub for qub in range(header['number_of_qubits'])]
-
-        qreg_dest_order = []
-        for _, qubits in groupby(header['qubit_labels'], lambda x: x[0]):
-            qubits = [qubit for qubit in qubits]
-            qubits.reverse()
-            for qubit in qubits:
-                qreg_dest_order.append("%s_%s" % (qubit[0], qubit[1]))
-        return [qreg_dest_order.index(ind) for ind in self._get_qubit_labels()]
-
-    def _get_clbitorder(self):
-        header = self.json_circuit['header']
-
-        if not self.reversebits:
-            return [clb for clb in range(header['number_of_clbits'])]
-
-        creg_dest_order = []
-        for creg in self.json_circuit['header']['clbit_labels']:
-            bit_nos = [bit for bit in range(creg[1])]
-            bit_nos.reverse()
-            for clbit in bit_nos:
-                creg_dest_order.append("%s_%s" % (creg[0], clbit))
-        return [creg_dest_order.index(ind) for ind in self._get_clbit_labels()]
-
     def single_string(self):
         """
         Creates a loong string with the ascii art
@@ -492,7 +462,7 @@ def lines(self, line_length=None):
         if line_length is None:
             line_length, _ = get_terminal_size()
 
-        noqubits = self.json_circuit['header']['number_of_qubits']
+        noqubits = len(self.qregs)
         layers = self.build_layers()
 
         # TODO compress layers
@@ -565,16 +535,7 @@ def wire_names(self, with_initial_value=True):
             qubit_labels = ['%s: ' % qubit for qubit in qubit_labels]
             clbit_labels = ['%s: ' % clbit for clbit in clbit_labels]
 
-        qubit_wires = [None] * self.json_circuit['header']['number_of_qubits']
-        clbit_wires = [None] * self.json_circuit['header']['number_of_clbits']
-
-        for order, label in enumerate(qubit_labels):
-            qubit_wires[self.qubitorder[order]] = label
-
-        for order, label in enumerate(clbit_labels):
-            clbit_wires[self.clbitorder[order]] = label
-
-        return qubit_wires + clbit_wires
+        return qubit_labels + clbit_labels
 
     @staticmethod
     def draw_wires(wires):
@@ -617,7 +578,7 @@ def draw_wires(wires):
     @staticmethod
     def label_for_conditional(instruction):
         """ Creates the label for a conditional instruction."""
-        return "%s %s" % ('=', instruction['conditional']['val'])
+        return "%s %s" % ('=', instruction['condition'][1])
 
     @staticmethod
     def params_for_label(instruction):
@@ -680,19 +641,6 @@ def merge_lines(top, bot, icod="top"):
                 ret += botc
         return ret
 
-    def clbit_index_from_mask(self, mask):
-        """
-        Given a mask, returns a list of classical indexes affected by that mask.
-        Args:
-            mask (int): The mask.
-
-        Returns:
-            list: A list of indexes affected by the mask.
-        """
-        clbit_len = self.json_circuit['header']['number_of_clbits']
-        bit_mask = [bool(mask & (1 << n)) for n in range(clbit_len)]
-        return [i for i, x in enumerate(bit_mask) if x]
-
     @staticmethod
     def normalize_width(layer):
         """
@@ -717,13 +665,13 @@ def build_layers(self):
 
         layers.append(InputWire.fillup_layer(self.wire_names(with_initial_value=True)))
 
-        for instruction in self.json_circuit['instructions']:
-            layer = Layer(self.qubitorder, self.clbitorder)
+        for instruction in self.instructions:
+            layer = Layer(self.qregs, self.cregs)
             connector_label = None
 
             if instruction['name'] == 'measure':
-                layer.set_qubit(instruction['qubits'][0], MeasureFrom())
-                layer.set_clbit(instruction['clbits'][0], MeasureTo())
+                layer.set_qubit(instruction['qargs'][0], MeasureFrom())
+                layer.set_clbit(instruction['cargs'][0], MeasureTo())
 
             elif instruction['name'] in ['barrier', 'snapshot', 'save', 'load',
                                          'noise']:
@@ -731,79 +679,77 @@ def build_layers(self):
                 if not self.plotbarriers:
                     continue
 
-                for qubit in instruction['qubits']:
+                for qubit in instruction['qargs']:
                     layer.set_qubit(qubit, Barrier())
 
             elif instruction['name'] == 'swap':
                 # swap
-                for qubit in instruction['qubits']:
+                for qubit in instruction['qargs']:
                     layer.set_qubit(qubit, Ex())
 
             elif instruction['name'] == 'cswap':
                 # cswap
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1], Ex())
-                layer.set_qubit(instruction['qubits'][2], Ex())
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1], Ex())
+                layer.set_qubit(instruction['qargs'][2], Ex())
 
             elif instruction['name'] == 'reset':
-                layer.set_qubit(instruction['qubits'][0], Reset())
+                layer.set_qubit(instruction['qargs'][0], Reset())
 
-            elif 'conditional' in instruction:
+            elif instruction['condition'] is not None:
                 # conditional
-                clbits = self.clbit_index_from_mask(int(instruction['conditional']['mask'], 16))
                 cllabel = TextDrawing.label_for_conditional(instruction)
                 qulabel = TextDrawing.label_for_box(instruction)
 
-                layer.set_cl_multibox(clbits, cllabel, top_connect='┴')
-                layer.set_qubit(instruction['qubits'][0], BoxOnQuWire(qulabel, bot_connect='┬'))
+                layer.set_cl_multibox(instruction['condition'][0], cllabel, top_connect='┴')
+                layer.set_qubit(instruction['qargs'][0], BoxOnQuWire(qulabel, bot_connect='┬'))
 
             elif instruction['name'] in ['cx', 'CX', 'ccx']:
                 # cx/ccx
-                for qubit in [qubit for qubit in instruction['qubits'][:-1]]:
+                for qubit in [qubit for qubit in instruction['qargs'][:-1]]:
                     layer.set_qubit(qubit, Bullet())
-                layer.set_qubit(instruction['qubits'][-1], BoxOnQuWire('X'))
+                layer.set_qubit(instruction['qargs'][-1], BoxOnQuWire('X'))
 
             elif instruction['name'] == 'cy':
                 # cy
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1], BoxOnQuWire('Y'))
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1], BoxOnQuWire('Y'))
 
             elif instruction['name'] == 'cz':
                 # cz
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1], Bullet())
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1], Bullet())
 
             elif instruction['name'] == 'ch':
                 # ch
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1], BoxOnQuWire('H'))
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1], BoxOnQuWire('H'))
 
             elif instruction['name'] == 'cu1':
                 # cu1
                 connector_label = TextDrawing.params_for_label(instruction)[0]
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1], Bullet())
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1], Bullet())
 
             elif instruction['name'] == 'cu3':
                 # cu3
                 params = TextDrawing.params_for_label(instruction)
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1],
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1],
                                 BoxOnQuWire("U3(%s)" % ','.join(params)))
 
             elif instruction['name'] == 'crz':
                 # crz
                 label = "Rz(%s)" % TextDrawing.params_for_label(instruction)[0]
-                layer.set_qubit(instruction['qubits'][0], Bullet())
-                layer.set_qubit(instruction['qubits'][1],
-                                BoxOnQuWire(label))
+                layer.set_qubit(instruction['qargs'][0], Bullet())
+                layer.set_qubit(instruction['qargs'][1], BoxOnQuWire(label))
 
-            elif len(instruction['qubits']) == 1 and 'clbits' not in instruction:
+            elif len(instruction['qargs']) == 1 and not instruction['cargs']:
                 # unitary gate
-                layer.set_qubit(instruction['qubits'][0],
+                layer.set_qubit(instruction['qargs'][0],
                                 BoxOnQuWire(TextDrawing.label_for_box(instruction)))
 
-            elif len(instruction['qubits']) >= 2 and 'clbits' not in instruction:
+            elif len(instruction['qubits']) >= 2 and not instruction['cargs']:
                 # multiple qubit gate
                 layer.set_qu_multibox(instruction['qubits'], TextDrawing.label_for_box(instruction))
 
@@ -821,11 +767,11 @@ def build_layers(self):
 class Layer:
     """ A layer is the "column" of the circuit. """
 
-    def __init__(self, qubitorder, clbitorder):
-        self.qubitorder = qubitorder
-        self.clbitorder = clbitorder
-        self.qubit_layer = [None] * len(qubitorder)
-        self.clbit_layer = [None] * len(clbitorder)
+    def __init__(self, qregs, cregs):
+        self.qregs = qregs
+        self.cregs = cregs
+        self.qubit_layer = [None] * len(qregs)
+        self.clbit_layer = [None] * len(cregs)
 
     @property
     def full_layer(self):
@@ -840,58 +786,64 @@ def set_qubit(self, qubit, element):
         """
         Sets the qubit to the element
         Args:
-            qubit (int): Qubit index.
+            qubit (qbit): Element of self.qregs.
             element (DrawElement): Element to set in the qubit
         """
-        self.qubit_layer[self.qubitorder[qubit]] = element
+        self.qubit_layer[self.qregs.index(qubit)] = element
 
     def set_clbit(self, clbit, element):
         """
         Sets the clbit to the element
         Args:
-            clbit (int): Clbit index.
+            clbit (cbit): Element of self.cregs.
             element (DrawElement): Element to set in the clbit
         """
-        self.clbit_layer[self.clbitorder[clbit]] = element
+        self.clbit_layer[self.cregs.index(clbit)] = element
 
     def _set_multibox(self, wire_type, bits, label, top_connect=None):
         # pylint: disable=invalid-name
-        bits = sorted(bits)
         if wire_type == "cl":
+            bit_index = sorted([i for i, x in enumerate(self.cregs) if x in bits])
+            bits.sort(key=self.cregs.index)
             set_bit = self.set_clbit
             BoxOnWire = BoxOnClWire
             BoxOnWireTop = BoxOnClWireTop
             BoxOnWireMid = BoxOnClWireMid
             BoxOnWireBot = BoxOnClWireBot
         elif wire_type == "qu":
+            bit_index = sorted([i for i, x in enumerate(self.qregs) if x in bits])
+            bits.sort(key=self.qregs.index)
             set_bit = self.set_qubit
             BoxOnWire = BoxOnQuWire
             BoxOnWireTop = BoxOnQuWireTop
             BoxOnWireMid = BoxOnQuWireMid
             BoxOnWireBot = BoxOnQuWireBot
+        else:
+            raise VisualizationError("_set_multibox only supports 'cl' and 'qu' as wire types.")
 
-        # Checks if qubits are consecutive
-        if bits != [i for i in range(bits[0], bits[-1] + 1)]:
+        # Checks if bits are consecutive
+        if bit_index != [i for i in range(bit_index[0], bit_index[-1] + 1)]:
             raise VisualizationError("Text visualizaer does know how to build a gate with multiple"
                                      "bits when they are not adjacent to each other")
 
-        if len(bits) == 1:
+        if len(bit_index) == 1:
             set_bit(bits[0], BoxOnWire(label, top_connect=top_connect))
         else:
             set_bit(bits[0], BoxOnWireTop(label, top_connect=top_connect))
             for order, bit in enumerate(bits[1:-1], 1):
-                set_bit(bit, BoxOnWireMid(label, len(bits), order))
-            set_bit(bits[-1], BoxOnWireBot(label, len(bits)))
+                set_bit(bit, BoxOnWireMid(label, len(bit_index), order))
+            set_bit(bits[-1], BoxOnWireBot(label, len(bit_index)))
 
-    def set_cl_multibox(self, bits, label, top_connect='┴'):
+    def set_cl_multibox(self, creg, label, top_connect='┴'):
         """
         Sets the multi clbit box.
         Args:
-            bits (list[int]): A list of affected bits.
+            creg (string): The affected classical register.
             label (string): The label for the multi clbit box.
             top_connect (char): The char to connect the box on the top.
         """
-        self._set_multibox("cl", bits, label, top_connect=top_connect)
+        clbit = [bit for bit in self.cregs if bit[0] == creg]
+        self._set_multibox("cl", clbit, label, top_connect=top_connect)
 
     def set_qu_multibox(self, bits, label):
         """


Test patch:
diff --git a/test/python/references/text_ref.txt b/test/python/references/text_ref.txt
--- a/test/python/references/text_ref.txt
+++ b/test/python/references/text_ref.txt
@@ -1,13 +1,13 @@
-              ┌───┐┌───┐┌───┐ ░ ┌───┐┌───┐┌─────┐┌───┐┌─────┐┌────┐     ┌────────────┐┌────────────┐┌────────────┐┌────────────┐┌────────────┐┌───────────────────┐┌──────────────────────────┐                                                                                      ┌─┐
-q_0: |0>──────┤ X ├┤ Y ├┤ Z ├─░─┤ H ├┤ S ├┤ Sdg ├┤ T ├┤ Tdg ├┤ Id ├─|0>─┤ Rx(3.1416) ├┤ Ry(3.1416) ├┤ Rz(3.1416) ├┤ U0(3.1416) ├┤ U1(3.1416) ├┤ U2(3.1416,3.1416) ├┤ U3(3.1416,3.1416,3.1416) ├─X───■────■───■───■───■────────────────────■────────────────────■─────────■───■───────┤M├
-            ░ └───┘└───┘└───┘ ░ └───┘└───┘└─────┘└───┘└─────┘└────┘     └────────────┘└────────────┘└────────────┘└────────────┘└────────────┘└───────────────────┘└──────────────────────────┘ │ ┌─┴─┐┌─┴─┐ │ ┌─┴─┐ │3.1416 ┌────────────┴─────────────┐┌─────┴──────┐  │   │    ┌─┐└╥┘
-q_1: |0>────░───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────X─┤ X ├┤ Y ├─■─┤ H ├─■───────┤ U3(3.1416,3.1416,3.1416) ├┤ Rz(3.1416) ├──■───X────┤M├─╫─
-         ░  ░                                                                                                                                                                                     └───┘└───┘   └───┘         └──────────────────────────┘└────────────┘┌─┴─┐ │ ┌─┐└╥┘ ║ 
-q_2: |0>─░─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ X ├─X─┤M├─╫──╫─
-         ░                                                                                                                                                                                                                                                             └───┘   └╥┘ ║  ║ 
- c_0: 0 ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╬══╬══╩═
-                                                                                                                                                                                                                                                                                ║  ║    
- c_1: 0 ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╬══╩════
-                                                                                                                                                                                                                                                                                ║       
- c_2: 0 ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╩═══════
+         ░                                                                                                                                                                                                                                                             ┌───┐   ┌─┐      
+q_2: |0>─░─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ X ├─X─┤M├──────
+         ░  ░                                                                                                                                                                                     ┌───┐┌───┐   ┌───┐         ┌──────────────────────────┐┌────────────┐└─┬─┘ │ └╥┘┌─┐   
+q_1: |0>────░───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────X─┤ X ├┤ Y ├─■─┤ H ├─■───────┤ U3(3.1416,3.1416,3.1416) ├┤ Rz(3.1416) ├──■───X──╫─┤M├───
+            ░ ┌───┐┌───┐┌───┐ ░ ┌───┐┌───┐┌─────┐┌───┐┌─────┐┌────┐     ┌────────────┐┌────────────┐┌────────────┐┌────────────┐┌────────────┐┌───────────────────┐┌──────────────────────────┐ │ └─┬─┘└─┬─┘ │ └─┬─┘ │3.1416 └────────────┬─────────────┘└─────┬──────┘  │   │  ║ └╥┘┌─┐
+q_0: |0>──────┤ X ├┤ Y ├┤ Z ├─░─┤ H ├┤ S ├┤ Sdg ├┤ T ├┤ Tdg ├┤ Id ├─|0>─┤ Rx(3.1416) ├┤ Ry(3.1416) ├┤ Rz(3.1416) ├┤ U0(3.1416) ├┤ U1(3.1416) ├┤ U2(3.1416,3.1416) ├┤ U3(3.1416,3.1416,3.1416) ├─X───■────■───■───■───■────────────────────■────────────────────■─────────■───■──╫──╫─┤M├
+              └───┘└───┘└───┘ ░ └───┘└───┘└─────┘└───┘└─────┘└────┘     └────────────┘└────────────┘└────────────┘└────────────┘└────────────┘└───────────────────┘└──────────────────────────┘                                                                                 ║  ║ └╥┘
+ c_2: 0 ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╩══╬══╬═
+                                                                                                                                                                                                                                                                                   ║  ║ 
+ c_1: 0 ═══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╩══╬═
+                                                                                                                                                                                                                                                                                      ║ 
+ c_0: 0 ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════╩═
                                                                                                                                                                                                                                                                                         
\ No newline at end of file
diff --git a/test/python/test_circuit_text_drawer.py b/test/python/test_circuit_text_drawer.py
--- a/test/python/test_circuit_text_drawer.py
+++ b/test/python/test_circuit_text_drawer.py
@@ -55,25 +55,25 @@ def test_measure_from(self):
 
     def test_text_pager(self):
         """ The pager breaks the circuit when the drawing does not fit in the console."""
-        expected = '\n'.join(["        ┌───┐     »",
-                              "q_0: |0>┤ X ├──■──»",
-                              "        └─┬─┘┌─┴─┐»",
+        expected = '\n'.join(["             ┌───┐»",
                               "q_1: |0>──■──┤ X ├»",
-                              "             └───┘»",
+                              "        ┌─┴─┐└─┬─┘»",
+                              "q_0: |0>┤ X ├──■──»",
+                              "        └───┘     »",
                               " c_0: 0 ══════════»",
                               "                  »",
-                              "«     ┌─┐┌───┐     »",
+                              "«             ┌───┐»",
+                              "«q_1: ─────■──┤ X ├»",
+                              "«     ┌─┐┌─┴─┐└─┬─┘»",
                               "«q_0: ┤M├┤ X ├──■──»",
-                              "«     └╥┘└─┬─┘┌─┴─┐»",
-                              "«q_1: ─╫───■──┤ X ├»",
-                              "«      ║      └───┘»",
+                              "«     └╥┘└───┘     »",
                               "«c_0: ═╩═══════════»",
                               "«                  »",
-                              "«     ┌─┐┌───┐     ",
+                              "«             ┌───┐",
+                              "«q_1: ─────■──┤ X ├",
+                              "«     ┌─┐┌─┴─┐└─┬─┘",
                               "«q_0: ┤M├┤ X ├──■──",
-                              "«     └╥┘└─┬─┘┌─┴─┐",
-                              "«q_1: ─╫───■──┤ X ├",
-                              "«      ║      └───┘",
+                              "«     └╥┘└───┘     ",
                               "«c_0: ═╩═══════════",
                               "«                  "])
         qr = QuantumRegister(2, 'q')
@@ -104,27 +104,6 @@ class TestTextDrawerGatesInCircuit(QiskitTestCase):
 
     def test_text_measure_1(self):
         """ The measure operator, using 3-bit-length registers. """
-        expected = '\n'.join(["              ┌─┐",
-                              "q_0: |0>──────┤M├",
-                              "           ┌─┐└╥┘",
-                              "q_1: |0>───┤M├─╫─",
-                              "        ┌─┐└╥┘ ║ ",
-                              "q_2: |0>┤M├─╫──╫─",
-                              "        └╥┘ ║  ║ ",
-                              " c_0: 0 ═╬══╬══╩═",
-                              "         ║  ║    ",
-                              " c_1: 0 ═╬══╩════",
-                              "         ║       ",
-                              " c_2: 0 ═╩═══════",
-                              "                 "])
-        qr = QuantumRegister(3, 'q')
-        cr = ClassicalRegister(3, 'c')
-        circuit = QuantumCircuit(qr, cr)
-        circuit.measure(qr, cr)
-        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
-
-    def test_text_measure_1_reversebits(self):
-        """ The measure operator, using 3-bit-length registers, with reversebits """
         expected = '\n'.join(["        ┌─┐      ",
                               "q_2: |0>┤M├──────",
                               "        └╥┘┌─┐   ",
@@ -142,26 +121,47 @@ def test_text_measure_1_reversebits(self):
         cr = ClassicalRegister(3, 'c')
         circuit = QuantumCircuit(qr, cr)
         circuit.measure(qr, cr)
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_text_measure_1_reversebits(self):
+        """ The measure operator, using 3-bit-length registers, with reversebits """
+        expected = '\n'.join(["              ┌─┐",
+                              "q_0: |0>──────┤M├",
+                              "           ┌─┐└╥┘",
+                              "q_1: |0>───┤M├─╫─",
+                              "        ┌─┐└╥┘ ║ ",
+                              "q_2: |0>┤M├─╫──╫─",
+                              "        └╥┘ ║  ║ ",
+                              " c_0: 0 ═╬══╬══╩═",
+                              "         ║  ║    ",
+                              " c_1: 0 ═╬══╩════",
+                              "         ║       ",
+                              " c_2: 0 ═╩═══════",
+                              "                 "])
+        qr = QuantumRegister(3, 'q')
+        cr = ClassicalRegister(3, 'c')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.measure(qr, cr)
         self.assertEqual(str(_text_circuit_drawer(circuit, reversebits=True)), expected)
 
     def test_text_measure_2(self):
         """ The measure operator, using some registers. """
-        expected = '\n'.join(["               ",
-                              "q1_0: |0>──────",
-                              "               ",
-                              "q1_1: |0>──────",
-                              "            ┌─┐",
-                              "q2_0: |0>───┤M├",
-                              "         ┌─┐└╥┘",
-                              "q2_1: |0>┤M├─╫─",
-                              "         └╥┘ ║ ",
-                              " c1_0: 0 ═╬══╬═",
+        expected = '\n'.join(["         ┌─┐   ",
+                              "q2_1: |0>┤M├───",
+                              "         └╥┘┌─┐",
+                              "q2_0: |0>─╫─┤M├",
+                              "          ║ └╥┘",
+                              "q1_1: |0>─╫──╫─",
                               "          ║  ║ ",
-                              " c1_1: 0 ═╬══╬═",
+                              "q1_0: |0>─╫──╫─",
                               "          ║  ║ ",
-                              " c2_0: 0 ═╬══╩═",
-                              "          ║    ",
-                              " c2_1: 0 ═╩════",
+                              " c2_1: 0 ═╩══╬═",
+                              "             ║ ",
+                              " c2_0: 0 ════╩═",
+                              "               ",
+                              " c1_1: 0 ══════",
+                              "               ",
+                              " c1_0: 0 ══════",
                               "               "])
         qr1 = QuantumRegister(2, 'q1')
         cr1 = ClassicalRegister(2, 'c1')
@@ -174,21 +174,21 @@ def test_text_measure_2(self):
     def test_text_measure_2_reversebits(self):
         """ The measure operator, using some registers, with reversebits """
         expected = '\n'.join(["               ",
-                              "q1_1: |0>──────",
-                              "               ",
                               "q1_0: |0>──────",
-                              "         ┌─┐   ",
-                              "q2_1: |0>┤M├───",
-                              "         └╥┘┌─┐",
-                              "q2_0: |0>─╫─┤M├",
-                              "          ║ └╥┘",
-                              " c1_1: 0 ═╬══╬═",
-                              "          ║  ║ ",
+                              "               ",
+                              "q1_1: |0>──────",
+                              "            ┌─┐",
+                              "q2_0: |0>───┤M├",
+                              "         ┌─┐└╥┘",
+                              "q2_1: |0>┤M├─╫─",
+                              "         └╥┘ ║ ",
                               " c1_0: 0 ═╬══╬═",
                               "          ║  ║ ",
-                              " c2_1: 0 ═╩══╬═",
-                              "             ║ ",
-                              " c2_0: 0 ════╩═",
+                              " c1_1: 0 ═╬══╬═",
+                              "          ║  ║ ",
+                              " c2_0: 0 ═╬══╩═",
+                              "          ║    ",
+                              " c2_1: 0 ═╩════",
                               "               "])
         qr1 = QuantumRegister(2, 'q1')
         cr1 = ClassicalRegister(2, 'c1')
@@ -201,13 +201,13 @@ def test_text_measure_2_reversebits(self):
     def test_text_swap(self):
         """ Swap drawing. """
         expected = '\n'.join(["               ",
-                              "q1_0: |0>────X─",
-                              "             │ ",
-                              "q1_1: |0>─X──┼─",
-                              "          │  │ ",
-                              "q2_0: |0>─┼──X─",
-                              "          │    ",
                               "q2_1: |0>─X────",
+                              "          │    ",
+                              "q2_0: |0>─┼──X─",
+                              "          │  │ ",
+                              "q1_1: |0>─X──┼─",
+                              "             │ ",
+                              "q1_0: |0>────X─",
                               "               "])
         qr1 = QuantumRegister(2, 'q1')
         qr2 = QuantumRegister(2, 'q2')
@@ -218,13 +218,13 @@ def test_text_swap(self):
     def test_text_swap_reversebits(self):
         """ Swap drawing with reversebits. """
         expected = '\n'.join(["               ",
-                              "q1_1: |0>─X────",
-                              "          │    ",
-                              "q1_0: |0>─┼──X─",
-                              "          │  │ ",
-                              "q2_1: |0>─X──┼─",
+                              "q1_0: |0>────X─",
                               "             │ ",
-                              "q2_0: |0>────X─",
+                              "q1_1: |0>─X──┼─",
+                              "          │  │ ",
+                              "q2_0: |0>─┼──X─",
+                              "          │    ",
+                              "q2_1: |0>─X────",
                               "               "])
         qr1 = QuantumRegister(2, 'q1')
         qr2 = QuantumRegister(2, 'q2')
@@ -235,11 +235,11 @@ def test_text_swap_reversebits(self):
     def test_text_cswap(self):
         """ CSwap drawing. """
         expected = '\n'.join(["                 ",
-                              "q_0: |0>─■──X──X─",
+                              "q_2: |0>─X──X──■─",
                               "         │  │  │ ",
                               "q_1: |0>─X──■──X─",
                               "         │  │  │ ",
-                              "q_2: |0>─X──X──■─",
+                              "q_0: |0>─■──X──X─",
                               "                 "])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
@@ -251,11 +251,11 @@ def test_text_cswap(self):
     def test_text_cswap_reversebits(self):
         """ CSwap drawing with reversebits. """
         expected = '\n'.join(["                 ",
-                              "q_2: |0>─X──X──■─",
+                              "q_0: |0>─■──X──X─",
                               "         │  │  │ ",
                               "q_1: |0>─X──■──X─",
                               "         │  │  │ ",
-                              "q_0: |0>─■──X──X─",
+                              "q_2: |0>─X──X──■─",
                               "                 "])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
@@ -266,13 +266,13 @@ def test_text_cswap_reversebits(self):
 
     def test_text_cu3(self):
         """ cu3 drawing. """
-        expected = '\n'.join(["                                    ┌──────────────────────────┐",
-                              "q_0: |0>─────────────■──────────────┤ U3(1.5708,1.5708,1.5708) ├",
-                              "        ┌────────────┴─────────────┐└────────────┬─────────────┘",
-                              "q_1: |0>┤ U3(1.5708,1.5708,1.5708) ├─────────────┼──────────────",
-                              "        └──────────────────────────┘             │              ",
+        expected = '\n'.join(["                                                                ",
                               "q_2: |0>─────────────────────────────────────────■──────────────",
-                              "                                                                "])
+                              "        ┌──────────────────────────┐             │              ",
+                              "q_1: |0>┤ U3(1.5708,1.5708,1.5708) ├─────────────┼──────────────",
+                              "        └────────────┬─────────────┘┌────────────┴─────────────┐",
+                              "q_0: |0>─────────────■──────────────┤ U3(1.5708,1.5708,1.5708) ├",
+                              "                                    └──────────────────────────┘"])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.cu3(pi / 2, pi / 2, pi / 2, qr[0], qr[1])
@@ -281,13 +281,13 @@ def test_text_cu3(self):
 
     def test_text_cu3_reversebits(self):
         """ cu3 drawing with reversebits"""
-        expected = '\n'.join(["                                                                ",
-                              "q_2: |0>─────────────────────────────────────────■──────────────",
-                              "        ┌──────────────────────────┐             │              ",
-                              "q_1: |0>┤ U3(1.5708,1.5708,1.5708) ├─────────────┼──────────────",
-                              "        └────────────┬─────────────┘┌────────────┴─────────────┐",
+        expected = '\n'.join(["                                    ┌──────────────────────────┐",
                               "q_0: |0>─────────────■──────────────┤ U3(1.5708,1.5708,1.5708) ├",
-                              "                                    └──────────────────────────┘"])
+                              "        ┌────────────┴─────────────┐└────────────┬─────────────┘",
+                              "q_1: |0>┤ U3(1.5708,1.5708,1.5708) ├─────────────┼──────────────",
+                              "        └──────────────────────────┘             │              ",
+                              "q_2: |0>─────────────────────────────────────────■──────────────",
+                              "                                                                "])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.cu3(pi / 2, pi / 2, pi / 2, qr[0], qr[1])
@@ -296,13 +296,13 @@ def test_text_cu3_reversebits(self):
 
     def test_text_crz(self):
         """ crz drawing. """
-        expected = '\n'.join(["                      ┌────────────┐",
-                              "q_0: |0>──────■───────┤ Rz(1.5708) ├",
-                              "        ┌─────┴──────┐└─────┬──────┘",
-                              "q_1: |0>┤ Rz(1.5708) ├──────┼───────",
-                              "        └────────────┘      │       ",
+        expected = '\n'.join(["                                    ",
                               "q_2: |0>────────────────────■───────",
-                              "                                    "])
+                              "        ┌────────────┐      │       ",
+                              "q_1: |0>┤ Rz(1.5708) ├──────┼───────",
+                              "        └─────┬──────┘┌─────┴──────┐",
+                              "q_0: |0>──────■───────┤ Rz(1.5708) ├",
+                              "                      └────────────┘"])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.crz(pi / 2, qr[0], qr[1])
@@ -311,13 +311,13 @@ def test_text_crz(self):
 
     def test_text_cx(self):
         """ cx drawing. """
-        expected = '\n'.join(["             ┌───┐",
-                              "q_0: |0>──■──┤ X ├",
-                              "        ┌─┴─┐└─┬─┘",
-                              "q_1: |0>┤ X ├──┼──",
-                              "        └───┘  │  ",
+        expected = '\n'.join(["                  ",
                               "q_2: |0>───────■──",
-                              "                  "])
+                              "        ┌───┐  │  ",
+                              "q_1: |0>┤ X ├──┼──",
+                              "        └─┬─┘┌─┴─┐",
+                              "q_0: |0>──■──┤ X ├",
+                              "             └───┘"])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.cx(qr[0], qr[1])
@@ -326,13 +326,13 @@ def test_text_cx(self):
 
     def test_text_cy(self):
         """ cy drawing. """
-        expected = '\n'.join(["             ┌───┐",
-                              "q_0: |0>──■──┤ Y ├",
-                              "        ┌─┴─┐└─┬─┘",
-                              "q_1: |0>┤ Y ├──┼──",
-                              "        └───┘  │  ",
+        expected = '\n'.join(["                  ",
                               "q_2: |0>───────■──",
-                              "                  "])
+                              "        ┌───┐  │  ",
+                              "q_1: |0>┤ Y ├──┼──",
+                              "        └─┬─┘┌─┴─┐",
+                              "q_0: |0>──■──┤ Y ├",
+                              "             └───┘"])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.cy(qr[0], qr[1])
@@ -342,11 +342,11 @@ def test_text_cy(self):
     def test_text_cz(self):
         """ cz drawing. """
         expected = '\n'.join(["              ",
-                              "q_0: |0>─■──■─",
-                              "         │  │ ",
-                              "q_1: |0>─■──┼─",
-                              "            │ ",
                               "q_2: |0>────■─",
+                              "            │ ",
+                              "q_1: |0>─■──┼─",
+                              "         │  │ ",
+                              "q_0: |0>─■──■─",
                               "              "])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
@@ -356,13 +356,13 @@ def test_text_cz(self):
 
     def test_text_ch(self):
         """ ch drawing. """
-        expected = '\n'.join(["             ┌───┐",
-                              "q_0: |0>──■──┤ H ├",
-                              "        ┌─┴─┐└─┬─┘",
-                              "q_1: |0>┤ H ├──┼──",
-                              "        └───┘  │  ",
+        expected = '\n'.join(["                  ",
                               "q_2: |0>───────■──",
-                              "                  "])
+                              "        ┌───┐  │  ",
+                              "q_1: |0>┤ H ├──┼──",
+                              "        └─┬─┘┌─┴─┐",
+                              "q_0: |0>──■──┤ H ├",
+                              "             └───┘"])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.ch(qr[0], qr[1])
@@ -372,11 +372,11 @@ def test_text_ch(self):
     def test_text_cu1(self):
         """ cu1 drawing. """
         expected = '\n'.join(["                          ",
-                              "q_0: |0>─■────────■───────",
-                              "         │1.5708  │       ",
-                              "q_1: |0>─■────────┼───────",
-                              "                  │1.5708 ",
                               "q_2: |0>──────────■───────",
+                              "                  │       ",
+                              "q_1: |0>─■────────┼───────",
+                              "         │1.5708  │1.5708 ",
+                              "q_0: |0>─■────────■───────",
                               "                          "])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
@@ -387,11 +387,11 @@ def test_text_cu1(self):
     def test_text_cu1_reversebits(self):
         """ cu1 drawing with reversebits"""
         expected = '\n'.join(["                          ",
-                              "q_2: |0>──────────■───────",
-                              "                  │       ",
-                              "q_1: |0>─■────────┼───────",
-                              "         │1.5708  │1.5708 ",
                               "q_0: |0>─■────────■───────",
+                              "         │1.5708  │       ",
+                              "q_1: |0>─■────────┼───────",
+                              "                  │1.5708 ",
+                              "q_2: |0>──────────■───────",
                               "                          "])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
@@ -401,13 +401,13 @@ def test_text_cu1_reversebits(self):
 
     def test_text_ccx(self):
         """ cx drawing. """
-        expected = '\n'.join(["                  ┌───┐",
-                              "q_0: |0>──■────■──┤ X ├",
-                              "          │  ┌─┴─┐└─┬─┘",
-                              "q_1: |0>──■──┤ X ├──■──",
-                              "        ┌─┴─┐└─┬─┘  │  ",
+        expected = '\n'.join(["        ┌───┐          ",
                               "q_2: |0>┤ X ├──■────■──",
-                              "        └───┘          "])
+                              "        └─┬─┘┌─┴─┐  │  ",
+                              "q_1: |0>──■──┤ X ├──■──",
+                              "          │  └─┬─┘┌─┴─┐",
+                              "q_0: |0>──■────■──┤ X ├",
+                              "                  └───┘"])
         qr = QuantumRegister(3, 'q')
         circuit = QuantumCircuit(qr)
         circuit.ccx(qr[0], qr[1], qr[2])
@@ -418,13 +418,13 @@ def test_text_ccx(self):
     def test_text_reset(self):
         """ Reset drawing. """
         expected = '\n'.join(["                        ",
-                              "q1_0: |0>───────────|0>─",
-                              "                        ",
-                              "q1_1: |0>──────|0>──────",
+                              "q2_1: |0>─|0>───────────",
                               "                        ",
                               "q2_0: |0>───────────────",
                               "                        ",
-                              "q2_1: |0>─|0>───────────",
+                              "q1_1: |0>──────|0>──────",
+                              "                        ",
+                              "q1_0: |0>───────────|0>─",
                               "                        "])
         qr1 = QuantumRegister(2, 'q1')
         qr2 = QuantumRegister(2, 'q2')
@@ -435,15 +435,15 @@ def test_text_reset(self):
 
     def test_text_single_gate(self):
         """ Single Qbit gate drawing. """
-        expected = '\n'.join(["                   ┌───┐",
-                              "q1_0: |0>──────────┤ H ├",
-                              "              ┌───┐└───┘",
-                              "q1_1: |0>─────┤ H ├─────",
-                              "              └───┘     ",
-                              "q2_0: |0>───────────────",
-                              "         ┌───┐          ",
+        expected = '\n'.join(["         ┌───┐          ",
                               "q2_1: |0>┤ H ├──────────",
-                              "         └───┘          "])
+                              "         └───┘          ",
+                              "q2_0: |0>───────────────",
+                              "              ┌───┐     ",
+                              "q1_1: |0>─────┤ H ├─────",
+                              "              └───┘┌───┐",
+                              "q1_0: |0>──────────┤ H ├",
+                              "                   └───┘"])
         qr1 = QuantumRegister(2, 'q1')
         qr2 = QuantumRegister(2, 'q2')
         circuit = QuantumCircuit(qr1, qr2)
@@ -453,15 +453,15 @@ def test_text_single_gate(self):
 
     def test_text_barrier(self):
         """ Barrier drawing. """
-        expected = '\n'.join(["             ░ ",
-                              "q1_0: |0>────░─",
+        expected = '\n'.join(["          ░    ",
+                              "q2_1: |0>─░────",
+                              "          ░    ",
+                              "q2_0: |0>──────",
                               "             ░ ",
                               "q1_1: |0>────░─",
                               "             ░ ",
-                              "q2_0: |0>──────",
-                              "          ░    ",
-                              "q2_1: |0>─░────",
-                              "          ░    "])
+                              "q1_0: |0>────░─",
+                              "             ░ "])
         qr1 = QuantumRegister(2, 'q1')
         qr2 = QuantumRegister(2, 'q2')
         circuit = QuantumCircuit(qr1, qr2)
@@ -471,15 +471,15 @@ def test_text_barrier(self):
 
     def test_text_plotbarriers(self):
         """ Drawing without plotbarriers. """
-        expected = '\n'.join(["                        ┌───┐",
-                              "q1_0: |0>───────────────┤ H ├",
-                              "                   ┌───┐└───┘",
-                              "q1_1: |0>──────────┤ H ├─────",
-                              "              ┌───┐└───┘     ",
-                              "q2_0: |0>─────┤ H ├──────────",
-                              "         ┌───┐└───┘          ",
+        expected = '\n'.join(["         ┌───┐               ",
                               "q2_1: |0>┤ H ├───────────────",
-                              "         └───┘               "])
+                              "         └───┘┌───┐          ",
+                              "q2_0: |0>─────┤ H ├──────────",
+                              "              └───┘┌───┐     ",
+                              "q1_1: |0>──────────┤ H ├─────",
+                              "                   └───┘┌───┐",
+                              "q1_0: |0>───────────────┤ H ├",
+                              "                        └───┘"])
         qr1 = QuantumRegister(2, 'q1')
         qr2 = QuantumRegister(2, 'q2')
         circuit = QuantumCircuit(qr1, qr2)
@@ -500,13 +500,13 @@ def test_text_conditional_1(self):
         if(c0==1) x q[0];
         if(c1==1) x q[0];
         """
-        expected = '\n'.join(["        ┌───────┐┌───────┐",
-                              "q_0: |0>┤   X   ├┤   X   ├",
-                              "        ├───┴───┤└───┬───┘",
-                              "c0_0: 0 ╡ = 0x1 ╞════╪════",
-                              "        └───────┘┌───┴───┐",
-                              "c1_0: 0 ═════════╡ = 0x1 ╞",
-                              "                 └───────┘"])
+        expected = '\n'.join(["        ┌─────┐┌─────┐",
+                              "q_0: |0>┤  X  ├┤  X  ├",
+                              "        └──┬──┘├──┴──┤",
+                              "c1_0: 0 ═══╪═══╡ = 1 ╞",
+                              "        ┌──┴──┐└─────┘",
+                              "c0_0: 0 ╡ = 1 ╞═══════",
+                              "        └─────┘       "])
         circuit = QuantumCircuit.from_qasm_str(qasm_string)
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
 
@@ -521,17 +521,17 @@ def test_text_conditional_2(self):
         if(c0==2) x q[0];
         if(c1==2) x q[0];
         """
-        expected = '\n'.join(["        ┌───────┐┌───────┐",
-                              "q_0: |0>┤   X   ├┤   X   ├",
-                              "        ├───┴───┤└───┬───┘",
-                              "c0_0: 0 ╡       ╞════╪════",
-                              "        │ = 0x2 │    │    ",
-                              "c0_1: 0 ╡       ╞════╪════",
-                              "        └───────┘┌───┴───┐",
-                              "c1_0: 0 ═════════╡       ╞",
-                              "                 │ = 0x2 │",
-                              "c1_1: 0 ═════════╡       ╞",
-                              "                 └───────┘"])
+        expected = '\n'.join(["        ┌─────┐┌─────┐",
+                              "q_0: |0>┤  X  ├┤  X  ├",
+                              "        └──┬──┘├──┴──┤",
+                              "c1_1: 0 ═══╪═══╡     ╞",
+                              "           │   │ = 2 │",
+                              "c1_0: 0 ═══╪═══╡     ╞",
+                              "        ┌──┴──┐└─────┘",
+                              "c0_1: 0 ╡     ╞═══════",
+                              "        │ = 2 │       ",
+                              "c0_0: 0 ╡     ╞═══════",
+                              "        └─────┘       "])
         circuit = QuantumCircuit.from_qasm_str(qasm_string)
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
 
@@ -546,21 +546,21 @@ def test_text_conditional_3(self):
         if(c0==3) x q[0];
         if(c1==3) x q[0];
         """
-        expected = '\n'.join(["        ┌───────┐┌───────┐",
-                              "q_0: |0>┤   X   ├┤   X   ├",
-                              "        ├───┴───┤└───┬───┘",
-                              "c0_0: 0 ╡       ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_1: 0 ╡ = 0x3 ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_2: 0 ╡       ╞════╪════",
-                              "        └───────┘┌───┴───┐",
-                              "c1_0: 0 ═════════╡       ╞",
-                              "                 │       │",
-                              "c1_1: 0 ═════════╡ = 0x3 ╞",
-                              "                 │       │",
-                              "c1_2: 0 ═════════╡       ╞",
-                              "                 └───────┘"])
+        expected = '\n'.join(["        ┌─────┐┌─────┐",
+                              "q_0: |0>┤  X  ├┤  X  ├",
+                              "        └──┬──┘├──┴──┤",
+                              "c1_2: 0 ═══╪═══╡     ╞",
+                              "           │   │     │",
+                              "c1_1: 0 ═══╪═══╡ = 3 ╞",
+                              "           │   │     │",
+                              "c1_0: 0 ═══╪═══╡     ╞",
+                              "        ┌──┴──┐└─────┘",
+                              "c0_2: 0 ╡     ╞═══════",
+                              "        │     │       ",
+                              "c0_1: 0 ╡ = 3 ╞═══════",
+                              "        │     │       ",
+                              "c0_0: 0 ╡     ╞═══════",
+                              "        └─────┘       "])
         circuit = QuantumCircuit.from_qasm_str(qasm_string)
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
 
@@ -575,25 +575,25 @@ def test_text_conditional_4(self):
         if(c0==4) x q[0];
         if(c1==4) x q[0];
         """
-        expected = '\n'.join(["        ┌───────┐┌───────┐",
-                              "q_0: |0>┤   X   ├┤   X   ├",
-                              "        ├───┴───┤└───┬───┘",
-                              "c0_0: 0 ╡       ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_1: 0 ╡       ╞════╪════",
-                              "        │ = 0x4 │    │    ",
-                              "c0_2: 0 ╡       ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_3: 0 ╡       ╞════╪════",
-                              "        └───────┘┌───┴───┐",
-                              "c1_0: 0 ═════════╡       ╞",
-                              "                 │       │",
-                              "c1_1: 0 ═════════╡       ╞",
-                              "                 │ = 0x4 │",
-                              "c1_2: 0 ═════════╡       ╞",
-                              "                 │       │",
-                              "c1_3: 0 ═════════╡       ╞",
-                              "                 └───────┘"])
+        expected = '\n'.join(["        ┌─────┐┌─────┐",
+                              "q_0: |0>┤  X  ├┤  X  ├",
+                              "        └──┬──┘├──┴──┤",
+                              "c1_3: 0 ═══╪═══╡     ╞",
+                              "           │   │     │",
+                              "c1_2: 0 ═══╪═══╡     ╞",
+                              "           │   │ = 4 │",
+                              "c1_1: 0 ═══╪═══╡     ╞",
+                              "           │   │     │",
+                              "c1_0: 0 ═══╪═══╡     ╞",
+                              "        ┌──┴──┐└─────┘",
+                              "c0_3: 0 ╡     ╞═══════",
+                              "        │     │       ",
+                              "c0_2: 0 ╡     ╞═══════",
+                              "        │ = 4 │       ",
+                              "c0_1: 0 ╡     ╞═══════",
+                              "        │     │       ",
+                              "c0_0: 0 ╡     ╞═══════",
+                              "        └─────┘       "])
         circuit = QuantumCircuit.from_qasm_str(qasm_string)
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
 
@@ -608,29 +608,29 @@ def test_text_conditional_5(self):
         if(c0==5) x q[0];
         if(c1==5) x q[0];
         """
-        expected = '\n'.join(["        ┌───────┐┌───────┐",
-                              "q_0: |0>┤   X   ├┤   X   ├",
-                              "        ├───┴───┤└───┬───┘",
-                              "c0_0: 0 ╡       ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_1: 0 ╡       ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_2: 0 ╡ = 0x5 ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_3: 0 ╡       ╞════╪════",
-                              "        │       │    │    ",
-                              "c0_4: 0 ╡       ╞════╪════",
-                              "        └───────┘┌───┴───┐",
-                              "c1_0: 0 ═════════╡       ╞",
-                              "                 │       │",
-                              "c1_1: 0 ═════════╡       ╞",
-                              "                 │       │",
-                              "c1_2: 0 ═════════╡ = 0x5 ╞",
-                              "                 │       │",
-                              "c1_3: 0 ═════════╡       ╞",
-                              "                 │       │",
-                              "c1_4: 0 ═════════╡       ╞",
-                              "                 └───────┘"])
+        expected = '\n'.join(["        ┌─────┐┌─────┐",
+                              "q_0: |0>┤  X  ├┤  X  ├",
+                              "        └──┬──┘├──┴──┤",
+                              "c1_4: 0 ═══╪═══╡     ╞",
+                              "           │   │     │",
+                              "c1_3: 0 ═══╪═══╡     ╞",
+                              "           │   │     │",
+                              "c1_2: 0 ═══╪═══╡ = 5 ╞",
+                              "           │   │     │",
+                              "c1_1: 0 ═══╪═══╡     ╞",
+                              "           │   │     │",
+                              "c1_0: 0 ═══╪═══╡     ╞",
+                              "        ┌──┴──┐└─────┘",
+                              "c0_4: 0 ╡     ╞═══════",
+                              "        │     │       ",
+                              "c0_3: 0 ╡     ╞═══════",
+                              "        │     │       ",
+                              "c0_2: 0 ╡ = 5 ╞═══════",
+                              "        │     │       ",
+                              "c0_1: 0 ╡     ╞═══════",
+                              "        │     │       ",
+                              "c0_0: 0 ╡     ╞═══════",
+                              "        └─────┘       "])
         circuit = QuantumCircuit.from_qasm_str(qasm_string)
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)