# qml.circuit_drawer.CircuitDrawer¶

class CircuitDrawer(raw_operation_grid, raw_observable_grid, wires, charset=None, show_all_wires=False)[source]

Bases: object

Creates a circuit diagram from the operators of a CircuitGraph in grid form.

Parameters
• raw_operation_grid (list[list[Operation]]) – The CircuitGraph’s operations

• raw_observable_grid (list[list[qml.operation.Observable]]) – The CircuitGraph’s observables

• wires (Wires) – all wires on the device for which the circuit is drawn

• charset (str, pennylane.circuit_drawer.CharSet, optional) – The CharSet that shall be used for drawing.

• show_all_wires (bool) – If True, all wires, including empty wires, are printed.

 Add multi wire connectors for the given wires to a layer. Draw the circuit diagram. extract_active_wires(raw_operation_grid, …) Get the subset of wires on the device that are used in the circuit. move_multi_wire_gates(operator_grid) Move multi-wire gates so that there are no interlocking multi-wire gates in the same layer. pad_representation(representation_grid, …) Pads the given representation so that width inside layers is constant. resolve_decorations(grid, representation_grid) Resolve the decorations of the given Grid. resolve_representation(grid, representation_grid) Resolve the string representation of the given Grid.
add_multi_wire_connectors_to_layer(wire_indices, decoration_layer)[source]

Add multi wire connectors for the given wires to a layer.

Parameters
• wire_indices (list[int]) – The indices of wires that are to be connected

• decoration_layer (list[str]) – The decoration layer to which the wires will be added

draw()[source]

Draw the circuit diagram.

Returns

The circuit diagram

Return type

str

extract_active_wires(raw_operation_grid, raw_observable_grid)[source]

Get the subset of wires on the device that are used in the circuit.

Parameters
• raw_operation_grid (Iterable[Operator]) – The raw grid of operations

• raw_observable_grid (Iterable[Operator]) – The raw grid of observables

Returns

active wires on the device

Return type

Wires

move_multi_wire_gates(operator_grid)[source]

Move multi-wire gates so that there are no interlocking multi-wire gates in the same layer.

Parameters

operator_grid (pennylane.circuit_drawer.Grid) – Grid that holds the circuit information and that will be edited.

static pad_representation(representation_grid, pad_str, prepend_str, suffix_str, skip_indices)[source]

Pads the given representation so that width inside layers is constant.

Parameters
• representation_grid (pennylane.circuit_drawer.Grid) – Grid that holds the string representations that will be padded

• pad_str (str) – String that shall be used for padding

• prepend_str (str) – String that is prepended to all representations that are not skipped

• suffix_str (str) – String that is appended to all representations

• skip_indices (list[int]) – Indices of layers that should be skipped

resolve_decorations(grid, representation_grid)[source]

Resolve the decorations of the given Grid.

If decorations are in conflict, they are automatically spread over multiple layers.

Parameters
• grid (pennylane.circuit_drawer.Grid) – Grid that holds the circuit information

• representation_grid (pennylane.circuit_drawer.Grid) – Grid that holds the string representations and into which the decorations will be inserted

Returns

List with indices of inserted decoration layers

Return type

list[int]

resolve_representation(grid, representation_grid)[source]

Resolve the string representation of the given Grid.

Parameters
• grid (pennylane.circuit_drawer.Grid) – Grid that holds the circuit information

• representation_grid (pennylane.circuit_drawer.Grid) – Grid that is used to store the string representations