Repository: Qiskit/qiskit

Issue:
Text circuit output doesn't understand plotbarriers or reversebits style arguments
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**: Latest master
- **Python version**: 3.7
- **Operating system**: linux

### What is the current behavior?

When calling circuit_drawer(output='text') the style kwarg isn't used at all. So even common arguments that aren't matplotlib specific are not understood. These include the 'reversebits' and 'plotbarriers' options which should be implementable on the text drawer too.

### Steps to reproduce the problem

Call circuit_drawer() with the style kwarg and that input has 'reversebits' and/or 'plotbarriers' set.


### What is the expected behavior?

The output circuit ascii art circuit will have reversed bit and/or no barriers drawn.

### Suggested solutions

There are 2 things here, first we need to add an option to reverse the bits and not draw barriers to the text drawer. Then we need to pass that option to the text drawer.

However after writing #1108 I think we should just move plotbarriers and reversebits to kwargs for circuit_drawer() as they should be common options for all backends. The rest of the style dict is just for the matplotlib backend, so I feel we should make all the arguments from the style dict which are used by >=2 backends a top level kwarg.



Discussion:
@1ucian0 what are your thoughts here?
About how to handle the options or about changing the text drawer?
Heh, both I guess. I was asking more about the text drawer updates. But if you have any thoughts on how to handle the options too.
About how to handle options, probably something like this: https://github.com/Qiskit/qiskit-terra/issues/1077#issuecomment-428969647

I can update the drawer for handling `plotbarriers` and `reversebits` next week if it is not a priority.
There's no rush, we were thinking about pushing out a 0.6.2 release soon to get some of the visualization fixes and deprecations out there. I'd like to get this in for that too. But, I don't think that's going to happen this week anyway so there's no real rush.

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
@@ -192,8 +192,12 @@ def circuit_drawer(circuit,
                                             style)
     else:
         if output == 'text':
+            reversebits = style['reversebits'] if style and 'reversebits' in style else False
+            plotbarriers = style['plotbarriers'] if style and 'plotbarriers' in style else True
+
             return _text_circuit_drawer(circuit, filename=filename, basis=basis,
-                                        line_length=line_length)
+                                        line_length=line_length,
+                                        reversebits=reversebits, plotbarriers=plotbarriers)
         elif output == 'latex':
             im = _latex_circuit_drawer(circuit, basis=basis, scale=scale,
                                        filename=filename, style=style)
@@ -290,7 +294,8 @@ def qx_color_scheme():
 
 def _text_circuit_drawer(circuit, filename=None,
                          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", line_length=None):
+                               "cx,cy,cz,ch,crz,cu1,cu3,swap,ccx,cswap", line_length=None,
+                         reversebits=False, plotbarriers=True):
     """
     Draws a circuit using ascii art.
     Args:
@@ -299,13 +304,17 @@ def _text_circuit_drawer(circuit, filename=None,
         basis (str): Optional. Comma-separated list of gate names
         line_length (int): Optional. Sometimes, your console is too small of the drawing. Give me
                            you maximum line length your console supports.
+        reversebits (bool): Rearrange the bits in reverse order.
+        plotbarriers (bool): Draws the barriers when they are there.
     Returns:
         String: The drawing in a loooong string.
     """
     dag_circuit = DAGCircuit.fromQuantumCircuit(circuit, expand_gates=False)
     json_circuit = transpile_dag(dag_circuit, basis_gates=basis, format='json')
 
-    text = "\n".join(_text.TextDrawing(json_circuit).lines(line_length))
+    text = "\n".join(
+        _text.TextDrawing(json_circuit, reversebits=reversebits, plotbarriers=plotbarriers).lines(
+            line_length))
 
     if filename:
         with open(filename, mode='w', encoding="utf8") as text_file:
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,6 +9,8 @@
 A module for drawing circuits in ascii art or some other text representation
 """
 
+from itertools import groupby
+
 
 class DrawElement():
     """ An element is an instruction or an operation that need to be drawn."""
@@ -86,13 +88,11 @@ def connect(self, wire_char, where, label=None):
             where (list["top", "bot"]): Where the connector should be set.
             label (string): Some connectors have a label (see cu1, for example).
         """
-        if 'top' in where:
-            self.top_connect = self.top_connector[
-                wire_char] if wire_char in self.top_connector else wire_char
+        if 'top' in where and self.top_connector:
+            self.top_connect = self.top_connector[wire_char]
 
-        if 'bot' in where:
-            self.bot_connect = self.bot_connector[
-                wire_char] if wire_char in self.bot_connector else wire_char
+        if 'bot' in where and self.bot_connector:
+            self.bot_connect = self.bot_connector[wire_char]
 
         if label:
             self.top_format = self.top_format[:-1] + (label if label else "")
@@ -270,6 +270,8 @@ def __init__(self, label=""):
         self.mid_format = '─%s─'
         self.bot_format = ' %s '
         self._mid_padding = '─'
+        self.top_connector = {"│": '│'}
+        self.bot_connector = {"│": '│'}
 
 
 class Barrier(DirectOnQuWire):
@@ -283,6 +285,8 @@ def __init__(self, label=""):
         super().__init__("░")
         self.top_connect = "░"
         self.bot_connect = "░"
+        self.top_connector = {}
+        self.bot_connector = {}
 
 
 class Ex(DirectOnQuWire):
@@ -394,8 +398,53 @@ def fillup_layer(names):  # pylint: disable=arguments-differ
 class TextDrawing():
     """ The text drawing"""
 
-    def __init__(self, json_circuit):
+    def __init__(self, json_circuit, reversebits=False, plotbarriers=True):
         self.json_circuit = json_circuit
+        self.reversebits = reversebits
+        self.plotbarriers = plotbarriers
+        self.qubitorder = self._get_qubitorder()
+        self.clbitorder = self._get_clbitorder()
+
+    def _get_qubit_labels(self):
+        qubits = []
+        for qubit in self.json_circuit['header']['qubit_labels']:
+            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))
+        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 lines(self, line_length=None):
         """
@@ -467,20 +516,26 @@ def wire_names(self, with_initial_value=True):
         Returns:
             List: The list of wire names.
         """
-        ret = []
+        qubit_labels = self._get_qubit_labels()
+        clbit_labels = self._get_clbit_labels()
 
         if with_initial_value:
-            initial_value = {'qubit': '|0>', 'clbit': '0 '}
+            qubit_labels = ['%s: |0>' % qubit for qubit in qubit_labels]
+            clbit_labels = ['%s: 0 ' % clbit for clbit in clbit_labels]
         else:
-            initial_value = {'qubit': '', 'clbit': ''}
+            qubit_labels = ['%s: ' % qubit for qubit in qubit_labels]
+            clbit_labels = ['%s: ' % clbit for clbit in clbit_labels]
 
-        header = self.json_circuit['header']
-        for qubit in header['qubit_labels']:
-            ret.append("%s_%s: %s" % (qubit[0], qubit[1], initial_value['qubit']))
-        for creg in header['clbit_labels']:
-            for clbit in range(creg[1]):
-                ret.append("%s_%s: %s" % (creg[0], clbit, initial_value['clbit']))
-        return ret
+        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
 
     @staticmethod
     def draw_wires(wires):
@@ -620,13 +675,12 @@ def build_layers(self):
             Exception: When the drawing is, for some reason, impossible to be drawn.
         """
         layers = []
-        noqubits = self.json_circuit['header']['number_of_qubits']
-        noclbits = self.json_circuit['header']['number_of_clbits']
 
         layers.append(InputWire.fillup_layer(self.wire_names(with_initial_value=True)))
 
         for instruction in self.json_circuit['instructions']:
-            layer = Layer(noqubits, noclbits)
+            layer = Layer(self.qubitorder, self.clbitorder)
+            connector_label = None
 
             if instruction['name'] == 'measure':
                 layer.set_qubit(instruction['qubits'][0], MeasureFrom())
@@ -634,14 +688,16 @@ def build_layers(self):
 
             elif instruction['name'] == 'barrier':
                 # barrier
+                if not self.plotbarriers:
+                    continue
+
                 for qubit in instruction['qubits']:
-                    layer.qubit_layer[qubit] = Barrier()
+                    layer.set_qubit(qubit, Barrier())
 
             elif instruction['name'] == 'swap':
                 # swap
                 for qubit in instruction['qubits']:
-                    layer.qubit_layer[qubit] = Ex()
-                layer.connect_with("│")
+                    layer.set_qubit(qubit, Ex())
 
             elif instruction['name'] == 'cswap':
                 # cswap
@@ -649,8 +705,6 @@ def build_layers(self):
                 layer.set_qubit(instruction['qubits'][1], Ex())
                 layer.set_qubit(instruction['qubits'][2], Ex())
 
-                layer.connect_with("│")
-
             elif instruction['name'] == 'reset':
                 layer.set_qubit(instruction['qubits'][0], Reset())
 
@@ -667,34 +721,28 @@ def build_layers(self):
                 # cx/ccx
                 for qubit in [qubit for qubit in instruction['qubits'][:-1]]:
                     layer.set_qubit(qubit, Bullet())
-
                 layer.set_qubit(instruction['qubits'][-1], BoxOnQuWire('X'))
-                layer.connect_with("│")
 
             elif instruction['name'] == 'cy':
                 # cy
                 layer.set_qubit(instruction['qubits'][0], Bullet())
                 layer.set_qubit(instruction['qubits'][1], BoxOnQuWire('Y'))
-                layer.connect_with("│")
 
             elif instruction['name'] == 'cz':
                 # cz
                 layer.set_qubit(instruction['qubits'][0], Bullet())
                 layer.set_qubit(instruction['qubits'][1], Bullet())
-                layer.connect_with("│")
 
             elif instruction['name'] == 'ch':
                 # ch
                 layer.set_qubit(instruction['qubits'][0], Bullet())
                 layer.set_qubit(instruction['qubits'][1], BoxOnQuWire('H'))
-                layer.connect_with("│")
 
             elif instruction['name'] == 'cu1':
                 # cu1
-                label = TextDrawing.params_for_label(instruction)[0]
+                connector_label = TextDrawing.params_for_label(instruction)[0]
                 layer.set_qubit(instruction['qubits'][0], Bullet())
                 layer.set_qubit(instruction['qubits'][1], Bullet())
-                layer.connect_with("│", label)
 
             elif instruction['name'] == 'cu3':
                 # cu3
@@ -702,7 +750,6 @@ def build_layers(self):
                 layer.set_qubit(instruction['qubits'][0], Bullet())
                 layer.set_qubit(instruction['qubits'][1],
                                 BoxOnQuWire("U3(%s)" % ','.join(params)))
-                layer.connect_with("│")
 
             elif instruction['name'] == 'crz':
                 # crz
@@ -710,7 +757,6 @@ def build_layers(self):
                 layer.set_qubit(instruction['qubits'][0], Bullet())
                 layer.set_qubit(instruction['qubits'][1],
                                 BoxOnQuWire(label))
-                layer.connect_with("│")
 
             elif len(instruction['qubits']) == 1 and 'clbits' not in instruction:
                 # unitary gate
@@ -724,6 +770,8 @@ def build_layers(self):
             else:
                 raise Exception("I don't know how to handle this instruction", instruction)
 
+            layer.connect_with("│", connector_label)
+
             layers.append(layer.full_layer)
 
         return layers
@@ -732,9 +780,11 @@ def build_layers(self):
 class Layer:
     """ A layer is the "column" of the circuit. """
 
-    def __init__(self, noqubits, noclbits):
-        self.qubit_layer = [None] * noqubits
-        self.clbit_layer = [None] * noclbits
+    def __init__(self, qubitorder, clbitorder):
+        self.qubitorder = qubitorder
+        self.clbitorder = clbitorder
+        self.qubit_layer = [None] * len(qubitorder)
+        self.clbit_layer = [None] * len(clbitorder)
 
     @property
     def full_layer(self):
@@ -752,7 +802,7 @@ def set_qubit(self, qubit, element):
             qubit (int): Qubit index.
             element (DrawElement): Element to set in the qubit
         """
-        self.qubit_layer[qubit] = element
+        self.qubit_layer[self.qubitorder[qubit]] = element
 
     def set_clbit(self, clbit, element):
         """
@@ -761,7 +811,7 @@ def set_clbit(self, clbit, element):
             clbit (int): Clbit index.
             element (DrawElement): Element to set in the clbit
         """
-        self.clbit_layer[clbit] = element
+        self.clbit_layer[self.clbitorder[clbit]] = element
 
     def _set_multibox(self, wire_type, bits, label, top_connect=None):
         # pylint: disable=invalid-name
@@ -819,6 +869,11 @@ def connect_with(self, wire_char, label=None):
             label (string): Some connectors have a label (see cu1, for example).
         """
         affected_bits = [bit for bit in self.full_layer if bit is not None]
+
+        if len([qbit for qbit in self.qubit_layer if qbit is not None]) == 1:
+            # Nothing to connect
+            return
+
         affected_bits[0].connect(wire_char, ['bot'])
         for affected_bit in affected_bits[1:-1]:
             affected_bit.connect(wire_char, ['bot', 'top'])


Test patch:
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
@@ -67,13 +67,39 @@ def test_measure_from(self):
 
     def test_text_pager(self):
         """ The pager breaks the circuit when the drawing does not fit in the console."""
-        qr = QuantumRegister(1, 'q')
-        circuit = QuantumCircuit(qr)
-        no_instructions = 50
-        for _ in range(no_instructions):
-            circuit.x(qr[0])
-        self.assertEqual(_text_circuit_drawer(circuit, line_length=10).count('\n'),
-                         no_instructions * 3 + 2)
+        expected = '\n'.join(["        ┌───┐     »",
+                              "q_0: |0>┤ X ├──■──»",
+                              "        └─┬─┘┌─┴─┐»",
+                              "q_1: |0>──■──┤ X ├»",
+                              "             └───┘»",
+                              " c_0: 0 ══════════»",
+                              "                  »",
+                              "«     ┌─┐┌───┐     »",
+                              "«q_0: ┤M├┤ X ├──■──»",
+                              "«     └╥┘└─┬─┘┌─┴─┐»",
+                              "«q_1: ─╫───■──┤ X ├»",
+                              "«      ║      └───┘»",
+                              "«c_0: ═╩═══════════»",
+                              "«                  »",
+                              "«     ┌─┐┌───┐     ",
+                              "«q_0: ┤M├┤ X ├──■──",
+                              "«     └╥┘└─┬─┘┌─┴─┐",
+                              "«q_1: ─╫───■──┤ X ├",
+                              "«      ║      └───┘",
+                              "«c_0: ═╩═══════════",
+                              "«                  "])
+        qr = QuantumRegister(2, 'q')
+        cr = ClassicalRegister(1, 'c')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.cx(qr[1], qr[0])
+        circuit.cx(qr[0], qr[1])
+        circuit.measure(qr[0], cr[0])
+        circuit.cx(qr[1], qr[0])
+        circuit.cx(qr[0], qr[1])
+        circuit.measure(qr[0], cr[0])
+        circuit.cx(qr[1], qr[0])
+        circuit.cx(qr[0], qr[1])
+        self.assertEqual(_text_circuit_drawer(circuit, line_length=20), expected)
 
 
 @unittest.skipUnless(VALID_MATPLOTLIB, 'osx matplotlib backend not available')
@@ -101,6 +127,27 @@ def test_text_measure_1(self):
         circuit.measure(qr, cr)
         self.assertEqual(_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├──────",
+                              "        └╥┘┌─┐   ",
+                              "q_1: |0>─╫─┤M├───",
+                              "         ║ └╥┘┌─┐",
+                              "q_0: |0>─╫──╫─┤M├",
+                              "         ║  ║ └╥┘",
+                              " c_2: 0 ═╩══╬══╬═",
+                              "            ║  ║ ",
+                              " c_1: 0 ════╩══╬═",
+                              "               ║ ",
+                              " c_0: 0 ═══════╩═",
+                              "                 "])
+        qr = QuantumRegister(3, 'q')
+        cr = ClassicalRegister(3, 'c')
+        circuit = QuantumCircuit(qr, cr)
+        circuit.measure(qr, cr)
+        self.assertEqual(_text_circuit_drawer(circuit, reversebits=True), expected)
+
     def test_text_measure_2(self):
         """ The measure operator, using some registers. """
         expected = '\n'.join(["               ",
@@ -128,6 +175,33 @@ def test_text_measure_2(self):
         circuit.measure(qr2, cr2)
         self.assertEqual(_text_circuit_drawer(circuit), expected)
 
+    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 ═╬══╬═",
+                              "          ║  ║ ",
+                              " c1_0: 0 ═╬══╬═",
+                              "          ║  ║ ",
+                              " c2_1: 0 ═╩══╬═",
+                              "             ║ ",
+                              " c2_0: 0 ════╩═",
+                              "               "])
+        qr1 = QuantumRegister(2, 'q1')
+        cr1 = ClassicalRegister(2, 'c1')
+        qr2 = QuantumRegister(2, 'q2')
+        cr2 = ClassicalRegister(2, 'c2')
+        circuit = QuantumCircuit(qr1, qr2, cr1, cr2)
+        circuit.measure(qr2, cr2)
+        self.assertEqual(_text_circuit_drawer(circuit, reversebits=True), expected)
+
     def test_text_swap(self):
         """ Swap drawing. """
         expected = '\n'.join(["               ",
@@ -145,6 +219,23 @@ def test_text_swap(self):
         circuit.swap(qr1, qr2)
         self.assertEqual(_text_circuit_drawer(circuit), expected)
 
+    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──┼─",
+                              "             │ ",
+                              "q2_0: |0>────X─",
+                              "               "])
+        qr1 = QuantumRegister(2, 'q1')
+        qr2 = QuantumRegister(2, 'q2')
+        circuit = QuantumCircuit(qr1, qr2)
+        circuit.swap(qr1, qr2)
+        self.assertEqual(_text_circuit_drawer(circuit, reversebits=True), expected)
+
     def test_text_cswap(self):
         """ CSwap drawing. """
         expected = '\n'.join(["                 ",
@@ -161,6 +252,22 @@ def test_text_cswap(self):
         circuit.cswap(qr[2], qr[1], qr[0])
         self.assertEqual(_text_circuit_drawer(circuit), expected)
 
+    def test_text_cswap_reversebits(self):
+        """ CSwap drawing with reversebits. """
+        expected = '\n'.join(["                 ",
+                              "q_2: |0>─X──X──■─",
+                              "         │  │  │ ",
+                              "q_1: |0>─X──■──X─",
+                              "         │  │  │ ",
+                              "q_0: |0>─■──X──X─",
+                              "                 "])
+        qr = QuantumRegister(3, 'q')
+        circuit = QuantumCircuit(qr)
+        circuit.cswap(qr[0], qr[1], qr[2])
+        circuit.cswap(qr[1], qr[0], qr[2])
+        circuit.cswap(qr[2], qr[1], qr[0])
+        self.assertEqual(_text_circuit_drawer(circuit, reversebits=True), expected)
+
     def test_text_cu3(self):
         """ cu3 drawing. """
         expected = '\n'.join(["                                    ┌──────────────────────────┐",
@@ -176,6 +283,21 @@ def test_text_cu3(self):
         circuit.cu3(pi / 2, pi / 2, pi / 2, qr[2], qr[0])
         self.assertEqual(_text_circuit_drawer(circuit), expected)
 
+    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) ├─────────────┼──────────────",
+                              "        └────────────┬─────────────┘┌────────────┴─────────────┐",
+                              "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])
+        circuit.cu3(pi / 2, pi / 2, pi / 2, qr[2], qr[0])
+        self.assertEqual(_text_circuit_drawer(circuit, reversebits=True), expected)
+
     def test_text_crz(self):
         """ crz drawing. """
         expected = '\n'.join(["                      ┌────────────┐",
@@ -266,6 +388,21 @@ def test_text_cu1(self):
         circuit.cu1(pi / 2, qr[2], qr[0])
         self.assertEqual(_text_circuit_drawer(circuit), expected)
 
+    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>─■────────■───────",
+                              "                          "])
+        qr = QuantumRegister(3, 'q')
+        circuit = QuantumCircuit(qr)
+        circuit.cu1(pi / 2, qr[0], qr[1])
+        circuit.cu1(pi / 2, qr[2], qr[0])
+        self.assertEqual(_text_circuit_drawer(circuit, reversebits=True), expected)
+
     def test_text_ccx(self):
         """ cx drawing. """
         expected = '\n'.join(["                  ┌───┐",
@@ -336,6 +473,26 @@ def test_text_barrier(self):
         circuit.barrier(qr2[1])
         self.assertEqual(_text_circuit_drawer(circuit), expected)
 
+    def test_text_plotbarriers(self):
+        """ Drawing without plotbarriers. """
+        expected = '\n'.join(["                        ┌───┐",
+                              "q1_0: |0>───────────────┤ H ├",
+                              "                   ┌───┐└───┘",
+                              "q1_1: |0>──────────┤ H ├─────",
+                              "              ┌───┐└───┘     ",
+                              "q2_0: |0>─────┤ H ├──────────",
+                              "         ┌───┐└───┘          ",
+                              "q2_1: |0>┤ H ├───────────────",
+                              "         └───┘               "])
+        qr1 = QuantumRegister(2, 'q1')
+        qr2 = QuantumRegister(2, 'q2')
+        circuit = QuantumCircuit(qr1, qr2)
+        circuit.h(qr1)
+        circuit.barrier(qr1)
+        circuit.barrier(qr2[1])
+        circuit.h(qr2)
+        self.assertEqual(_text_circuit_drawer(circuit, plotbarriers=False), expected)
+
     def test_text_conditional_1(self):
         """ Conditional drawing with 1-bit-length regs."""
         qasm_string = """