예제 #1
0
def _text_circuit_drawer(circuit, filename=None, line_length=None, reverse_bits=False,
                         plotbarriers=True, justify=None):
    """
    Draws a circuit using ascii art.
    Args:
        circuit (QuantumCircuit): Input circuit
        filename (str): optional filename to write the result
        line_length (int): Optional. Breaks the circuit drawing to this length. This
                   useful when the drawing does not fit in the console. If
                   None (default), it will try to guess the console width using
                   shutil.get_terminal_size(). If you don't want pagination
                   at all, set line_length=-1.
        reverse_bits (bool): Rearrange the bits in reverse order.
        plotbarriers (bool): Draws the barriers when they are there.
        justify (str) : `left`, `right` or `none`. Defaults to `left`. Says how
                        the circuit should be justified.
    Returns:
        TextDrawing: An instances that, when printed, draws the circuit in ascii art.
    """
    qregs, cregs, ops = utils._get_layered_instructions(circuit,
                                                        reverse_bits=reverse_bits,
                                                        justify=justify)
    text_drawing = _text.TextDrawing(qregs, cregs, ops)
    text_drawing.plotbarriers = plotbarriers
    text_drawing.line_length = line_length

    if filename:
        text_drawing.dump(filename)
    return text_drawing
def _text_circuit_drawer(circuit,
                         filename=None,
                         line_length=None,
                         reverse_bits=False,
                         plot_barriers=True,
                         justify=None,
                         vertical_compression='high',
                         idle_wires=True,
                         with_layout=True,
                         fold=None,
                         initial_state=True):
    """Draws a circuit using ascii art.

    Args:
        circuit (QuantumCircuit): Input circuit
        filename (str): optional filename to write the result
        line_length (int): Deprecated. See `fold`.
        reverse_bits (bool): Rearrange the bits in reverse order.
        plot_barriers (bool): Draws the barriers when they are there.
        justify (str) : `left`, `right` or `none`. Defaults to `left`. Says how
                        the circuit should be justified.
        vertical_compression (string): `high`, `medium`, or `low`. It merges the
            lines so the drawing will take less vertical room. Default is `high`.
        idle_wires (bool): Include idle wires. Default is True.
        with_layout (bool): Include layout information, with labels on the physical
            layout. Default: True
        fold (int): Optional. Breaks the circuit drawing to this length. This
                    useful when the drawing does not fit in the console. If
                    None (default), it will try to guess the console width using
                    `shutil.get_terminal_size()`. If you don't want pagination
                   at all, set `fold=-1`.
        initial_state (bool): Optional. Adds |0> in the beginning of the line. Default: `True`.
    Returns:
        TextDrawing: An instances that, when printed, draws the circuit in ascii art.
    """
    qregs, cregs, ops = utils._get_layered_instructions(
        circuit,
        reverse_bits=reverse_bits,
        justify=justify,
        idle_wires=idle_wires)
    if with_layout:
        layout = circuit._layout
    else:
        layout = None
    if line_length:
        warn('The parameter "line_length" is being replaced by "fold"',
             DeprecationWarning, 3)
        fold = line_length
    text_drawing = _text.TextDrawing(qregs,
                                     cregs,
                                     ops,
                                     layout=layout,
                                     initial_state=initial_state)
    text_drawing.plotbarriers = plot_barriers
    text_drawing.line_length = fold
    text_drawing.vertical_compression = vertical_compression

    if filename:
        text_drawing.dump(filename)
    return text_drawing
예제 #3
0
def _text_circuit_drawer(circuit, filename=None, reverse_bits=False,
                         plot_barriers=True, justify=None, vertical_compression='high',
                         idle_wires=True, with_layout=True, fold=None, initial_state=True,
                         cregbundle=False, encoding=None):
    """Draws a circuit using ascii art.

    Args:
        circuit (QuantumCircuit): Input circuit
        filename (str): Optional filename to write the result
        reverse_bits (bool): Rearrange the bits in reverse order.
        plot_barriers (bool): Draws the barriers when they are there.
        justify (str) : `left`, `right` or `none`. Defaults to `left`. Says how
            the circuit should be justified.
        vertical_compression (string): `high`, `medium`, or `low`. It merges the
            lines so the drawing will take less vertical room. Default is `high`.
        idle_wires (bool): Include idle wires. Default is True.
        with_layout (bool): Include layout information with labels on the physical
            layout. Default: True
        fold (int): Optional. Breaks the circuit drawing to this length. This
            is useful when the drawing does not fit in the console. If
            None (default), it will try to guess the console width using
            `shutil.get_terminal_size()`. If you don't want pagination
            at all, set `fold=-1`.
        initial_state (bool): Optional. Adds |0> in the beginning of the line.
            Default: `False`.
        cregbundle (bool): Optional. If set True, bundle classical registers.
            Default: ``True``.
        encoding (str): Optional. Sets the encoding preference of the output.
            Default: ``sys.stdout.encoding``.

    Returns:
        TextDrawing: An instance that, when printed, draws the circuit in ascii art.
    """
    qubits, clbits, ops = utils._get_layered_instructions(circuit,
                                                          reverse_bits=reverse_bits,
                                                          justify=justify,
                                                          idle_wires=idle_wires)

    if with_layout:
        layout = circuit._layout
    else:
        layout = None
    global_phase = circuit.global_phase if hasattr(circuit, 'global_phase') else None
    text_drawing = _text.TextDrawing(qubits, clbits, ops, layout=layout,
                                     initial_state=initial_state,
                                     cregbundle=cregbundle, global_phase=global_phase,
                                     encoding=encoding,
                                     qregs=circuit.qregs, cregs=circuit.cregs)
    text_drawing.plotbarriers = plot_barriers
    text_drawing.line_length = fold
    text_drawing.vertical_compression = vertical_compression

    if filename:
        text_drawing.dump(filename, encoding=encoding)
    return text_drawing