pyqpanda.Visualization.circuit_draw

Functions

draw_circuit_pic(prog, pic_name[, scale, verbose, fold])

Draws a visual representation of a quantum circuit based on a given program.

draw_qprog(prog[, output, scale, fold, filename, ...])

Visualizes a quantum circuit in various formats based on the specified output type.

show_prog_info_count(prog)

Visualizes the distribution of nodes and layers within a quantum circuit represented by prog.

Module Contents

pyqpanda.Visualization.circuit_draw.draw_circuit_pic(prog, pic_name, scale=0.7, verbose=False, fold=30)[源代码]

Draws a visual representation of a quantum circuit based on a given program.

Args:
prog (dict):

The quantum program that specifies the quantum circuit.

pic_name (str):

The name of the output file for the circuit picture.

scale (float, optional):

The scale factor for the circuit drawing. Defaults to 0.7.

verbose (bool, optional):

If set to True, prints additional information during the drawing process. Defaults to False.

fold (int, optional):

The number of folds to apply when drawing the circuit. Defaults to 30.

The function utilizes the MatplotlibDrawer class to create the circuit image, which is then saved to the specified file. The drawer is configured with quantum register information, classical register information, and the operations defined in the program. The scale and fold parameters influence the visual presentation of the circuit.

pyqpanda.Visualization.circuit_draw.draw_qprog(prog, output=None, scale=0.7, fold=30, filename=None, with_logo=False, line_length=100, NodeIter_first=None, NodeIter_second=None, console_encode_type='utf8')[源代码]

Visualizes a quantum circuit in various formats based on the specified output type.

Supported output formats include: - 'text': ASCII art representation suitable for console output. - 'pic': Colorful image representation rendered in Python. - 'latex': LaTeX source code for the circuit, suitable for inclusion in LaTeX documents.

Args:
prog (object):

The quantum circuit object to be visualized.

scale (float, optional):

The scale factor for the image output. Defaults to 0.7.

fold (int, optional):

The maximum fold size for the image output. Defaults to 30.

filename (str, optional):

The file path to save the image output. Defaults to 'QCircuit_pic.jpg' for 'pic' output. For 'latex' output, defaults to 'QCircuit_latex.tex'.

with_logo (bool, optional):

Include the pyQPanda logo in the LaTeX output. Defaults to False.

line_length (int, optional):

The length of each line in the ASCII art output. Defaults to 100.

NodeIter_first (object, optional):

The starting position of the circuit segment to be visualized.

NodeIter_second (object, optional):

The ending position of the circuit segment to be visualized.

console_encode_type (str, optional):

The console encoding type, with 'utf8' and 'gbk' supported. Defaults to 'utf8'.

Returns:
str:

The visual representation of the quantum circuit, which is returned as a string depending on the output format.

pyqpanda.Visualization.circuit_draw.show_prog_info_count(prog)[源代码]

Visualizes the distribution of nodes and layers within a quantum circuit represented by prog.

This function creates a pie chart to display the proportion of different types of nodes and layers in the quantum circuit. It utilizes the information obtained from the count_prog_info function, which provides counts for single, double, and multi-control gate nodes, as well as layer-related metrics.

Args:
prog (object):

The quantum circuit object for which the distribution is to be visualized.

Returns:
None:

This function does not return any value; it only displays the visualization.

The visualization is composed of two pie charts:

The first chart shows the distribution of node types: Single Gate, Double Gate, Multi Control Gate, and Other Nodes. The second chart illustrates the distribution of layer types: Single Gate Layer, Double Gate Layer, and Other Layers.

Note:

This function assumes that the count_prog_info function is properly implemented and that the prog object has the necessary attributes to compute the required counts.