Visualizer package

Module contents

Utilities used to visualize quantum circuits. It can be extended to support other techniques and libraries.

circuit_visualizer module

CircuitVisualizer class

class qclight.visualizer.circuit_visualizer.CircuitVisualizer(n_qubits)[source]

Bases: object

Utility class used to visualize quantum circuits using connectors.

append_barrier(qubits=None)[source]

Appends a barrier to the circuit. If no qubits are specified, it will be added to all of them. It separates the circuit in different parts.

Parameters

qubits (Optional[Iterable[int]], default: None) – qubits to add the barrier to

append_controlled(gate, control, target)[source]

Appends a gate controlled by the control qubits and targeting the target qubit. All the qubits between the control and the target will be marked with vertical lines.

Parameters
  • gate (Gate) – gate to apply

  • control (Union[int, Iterable[int]]) – control qubits

  • target (int) – target qubit

append_standalone(gate, qubits)[source]

Appends a standalone gate to the provided qubit in the first available position. If the qubits are more than one, the gate will be applied to all of them at the same position.

Parameters
  • gate (Gate) – gate to apply

  • qubits (Union[int, Iterable[int]]) – qubits to apply the gate to

set_state(state)[source]

Sets the initial state of the circuit.

Parameters

state (ndarray[Any, dtype[float64]]) – initial state of the circuit

connector module

Connector class

class qclight.visualizer.connector.Connector(content)[source]

Bases: object

Connector that will be used to represent a block of the quantum circuit. It can be a qubit, a gate, a barrier, a control or a vertical line.

classmethod barrier()[source]

Creates a barrier connector. Used to separate different parts of the circuit.

Returns

Connector – new connector

classmethod control()[source]

Creates a control connector. Used in controlled gates, to indicate the control qubits.

Returns

Connector – new connector

classmethod empty()[source]

Creates an empty connector.

Returns

Connector – new connector

classmethod from_gate(gate)[source]

Creates a connector from a gate.

Parameters

gate (Gate) – gate to create the connector from

Returns

Connector – new connector

is_empty()[source]

Checks if the connector is an empty connector.

Returns

bool – whether the connector is empty

classmethod qubit(idx, label='q', initial_state=0)[source]

Creates a qubit connector. It indicates the name and index of the qubit, as well as its initial state.

Parameters
  • idx (int) – index of the qubit

  • label (str, default: 'q') – label of the qubit

  • initial_state (int | str, default: 0) – initial state of the qubit

Returns

Connector – new connector

classmethod vertical()[source]

Creates a vertical connector. Used in controlled gates.

Returns

Connector – new connector