qulacsvis.visualization.circuit_drawer module
- qulacsvis.visualization.circuit_drawer.circuit_drawer(circuit: qulacs_core.QuantumCircuit, output_method: Optional[str] = None, *, verbose: bool = False, filename: Optional[str] = None, dot: str = 'large', ppi: int = 150, dpi: int = 72, scale: float = 0.6) Union[str, PIL.Image.Image, matplotlib.figure.Figure] [source]
Draws a circuit diagram of a circuit.
- Parameters
circuit (qulacs.QuantumCircuit) – The quantum circuit to be drawn.
output_method (Optional[str], optional) – Set the output method for the drawn circuit. If None, the output method is set to ‘text’.
verbose (bool optional default=False) – (output_method=’text’) If True, a number will be added to the gate. Gates are numbered in the order in which they are added to the circuit.
filename (Optional[str] optional default=None) – (output_method=’mpl’ or ‘latex’) File name to save the drawing image
dot (str optional default='large') – (output_method=’text’) Dot style to mean control qubit(default=”large”)
ppi (int optional default=150) – (output_method=’latex’) The pixels per inch of the output image.
dpi (int optional default=72) – (output_method=’mpl’) The dots per inch of the output image.
scale (float optional default=0.6) – (output_method=’mpl’) The scale of the output image.
- Returns
The output of the circuit drawer. If output_method is ‘text’, the output is a None. Circuit is output to stdout. If output_method is ‘latex’, the output is an Image.Image object. If output_method is ‘latex_source’, the output is a string. If output_method is ‘mpl’, the output is a None. Circuit is drawn to a matplotlib figure.
- Return type
Union[str, Image.Image, None]
- Raises
ValueError – If output_method is not ‘text’, ‘latex’, ‘latex_source’, or ‘mpl’.
Examples
>>> from qulacs import QuantumCircuit >>> from qulacsvis.visualization import circuit_drawer >>> circuit = QuantumCircuit(3) >>> circuit.add_X_gate(0) >>> circuit.add_Y_gate(1) >>> circuit.add_Z_gate(2) >>> circuit.add_dense_matrix_gate( >>> [0, 1], [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]] >>> ) >>> circuit.add_CNOT_gate(2, 0) >>> circuit.add_X_gate(2) >>> circuit_drawer(circuit, output_method='text') ___ ___ ___ | X | |DeM| |CX | --| |---| |---| |---------- |___| | | |___| ___ | | | | Y | | | | --| |---| |-----|------------ |___| |___| | ___ | ___ | Z | | | X | --| |-------------●-----| |-- |___| |___|