@@ -75,6 +75,7 @@ def circuit_drawer(
7575 wire_order : list [int ] | None = None ,
7676 expr_len : int = 30 ,
7777 measure_arrows : bool | None = None ,
78+ barrier_label_len : int = 16 ,
7879):
7980 r"""Draw the quantum circuit. Use the output parameter to choose the drawing format:
8081
@@ -187,6 +188,9 @@ def circuit_drawer(
187188 instead place the name of the bit or register in the measure box.
188189 Default is ``True`` unless the user config file (usually ``~/.qiskit/settings.conf``)
189190 has an alternative value set. For example, ``circuit_measure_arrows = False``.
191+ barrier_label_len: The number of characters to display for
192+ :class:`.Barrier` labels in the output circuit. If this number is exceeded,
193+ the string will be truncated at that number and '...' added to the end.
190194
191195 Returns:
192196 :class:`.TextDrawing` or :class:`matplotlib.figure` or :class:`PIL.Image` or
@@ -219,6 +223,7 @@ def circuit_drawer(
219223 """
220224 image = None
221225 expr_len = max (expr_len , 0 )
226+ barrier_label_len = max (barrier_label_len , 0 )
222227 config = user_config .get_config ()
223228 # Get default from config file else use text
224229 default_output = "text"
@@ -324,6 +329,7 @@ def check_clbit_in_inst(circuit, cregbundle):
324329 cregbundle = cregbundle ,
325330 wire_order = complete_wire_order ,
326331 expr_len = expr_len ,
332+ barrier_label_len = barrier_label_len ,
327333 measure_arrows = measure_arrows ,
328334 )
329335 elif output == "latex" :
@@ -340,6 +346,7 @@ def check_clbit_in_inst(circuit, cregbundle):
340346 initial_state = initial_state ,
341347 cregbundle = cregbundle ,
342348 wire_order = complete_wire_order ,
349+ barrier_label_len = barrier_label_len ,
343350 )
344351 elif output == "latex_source" :
345352 return _generate_latex_source (
@@ -355,6 +362,7 @@ def check_clbit_in_inst(circuit, cregbundle):
355362 initial_state = initial_state ,
356363 cregbundle = cregbundle ,
357364 wire_order = complete_wire_order ,
365+ barrier_label_len = barrier_label_len ,
358366 )
359367 elif output == "mpl" :
360368 image = _matplotlib_circuit_drawer (
@@ -406,6 +414,7 @@ def _text_circuit_drawer(
406414 wire_order = None ,
407415 expr_len = 30 ,
408416 measure_arrows = True ,
417+ barrier_label_len = 16 ,
409418):
410419 """Draws a circuit using ascii art.
411420
@@ -441,6 +450,8 @@ def _text_circuit_drawer(
441450 measure_arrows: If True, draw an arrow from each measure box down to the classical bit
442451 or register where the measure value is placed. If False, do not draw arrow, but
443452 instead place the name of the bit or register in the measure box.
453+ barrier_label_len (int): Optional. The number of characters to display for
454+ :class:`.Barrier` labels. If this number is exceeded, the string will be truncated.
444455
445456 Returns:
446457 TextDrawing: An instance that, when printed, draws the circuit in ascii art.
@@ -467,6 +478,7 @@ def _text_circuit_drawer(
467478 encoding = encoding ,
468479 with_layout = with_layout ,
469480 expr_len = expr_len ,
481+ barrier_label_len = barrier_label_len ,
470482 measure_arrows = measure_arrows ,
471483 )
472484 text_drawing .plotbarriers = plot_barriers
@@ -499,6 +511,7 @@ def _latex_circuit_drawer(
499511 initial_state = False ,
500512 cregbundle = None ,
501513 wire_order = None ,
514+ barrier_label_len = 16 ,
502515):
503516 """Draw a quantum circuit based on latex (Qcircuit package)
504517
@@ -525,6 +538,8 @@ def _latex_circuit_drawer(
525538 wire_order (list): Optional. A list of integers used to reorder the display
526539 of the bits. The list must have an entry for every bit with the bits
527540 in the range 0 to (num_qubits + num_clbits).
541+ barrier_label_len (int): Optional. The number of characters to display for
542+ :class:`.Barrier` labels. If this number is exceeded, the string will be truncated.
528543
529544 Returns:
530545 PIL.Image: an in-memory representation of the circuit diagram
@@ -552,6 +567,7 @@ def _latex_circuit_drawer(
552567 initial_state = initial_state ,
553568 cregbundle = cregbundle ,
554569 wire_order = wire_order ,
570+ barrier_label_len = barrier_label_len ,
555571 )
556572
557573 try :
@@ -618,6 +634,7 @@ def _generate_latex_source(
618634 initial_state = False ,
619635 cregbundle = None ,
620636 wire_order = None ,
637+ barrier_label_len = 16 ,
621638):
622639 """Convert QuantumCircuit to LaTeX string.
623640
@@ -641,6 +658,8 @@ def _generate_latex_source(
641658 wire_order (list): Optional. A list of integers used to reorder the display
642659 of the bits. The list must have an entry for every bit with the bits
643660 in the range 0 to (num_qubits + num_clbits).
661+ barrier_label_len (int): Optional. The number of characters to display for
662+ :class:`.Barrier` labels. If this number is exceeded, the string will be truncated.
644663
645664 Returns:
646665 str: Latex string appropriate for writing to file.
@@ -664,6 +683,7 @@ def _generate_latex_source(
664683 cregbundle = cregbundle ,
665684 with_layout = with_layout ,
666685 circuit = circuit ,
686+ barrier_label_len = barrier_label_len ,
667687 )
668688 latex = qcimg .latex ()
669689 if filename :
@@ -695,6 +715,7 @@ def _matplotlib_circuit_drawer(
695715 wire_order = None ,
696716 expr_len = 30 ,
697717 measure_arrows = None ,
718+ barrier_label_len = 16 ,
698719):
699720 """Draw a quantum circuit based on matplotlib.
700721 If `%matplotlib inline` is invoked in a Jupyter notebook, it visualizes a circuit inline.
@@ -732,6 +753,8 @@ def _matplotlib_circuit_drawer(
732753 measure_arrows: If True, draw an arrow from each measure box down to the classical bit
733754 or register where the measure value is placed. If False, do not draw arrow, but
734755 instead place the name of the bit or register in the measure box.
756+ barrier_label_len (int): Optional. The number of characters to display for
757+ :class:`.Barrier` labels. If this number is exceeded, the string will be truncated.
735758
736759 Returns:
737760 matplotlib.figure: a matplotlib figure object for the circuit diagram
@@ -764,6 +787,7 @@ def _matplotlib_circuit_drawer(
764787 cregbundle = cregbundle ,
765788 with_layout = with_layout ,
766789 expr_len = expr_len ,
790+ barrier_label_len = barrier_label_len ,
767791 measure_arrows = measure_arrows ,
768792 )
769793 return qcd .draw (filename )
0 commit comments