Skip to content

profiling Module

The pyqpanda3.profiling module provides tools for profiling quantum circuit performance, visualizing circuit features, and generating performance diagrams.

Overview

The profiling module helps analyze quantum circuits from a performance perspective by computing metrics such as connectivity, liveness, parallelism, entanglement, and critical depth. It can generate visual performance profiles and circuit Directed Acyclic Graph (DAG) representations.

Functions

draw_circuit_profile

python
draw_circuit_profile(circuit: Union[QCircuit, QProg], gate_times: dict,
                     is_show: bool = False, out_file: str = None) -> None

Draws a performance profile of a quantum circuit based on gate execution times. The profile is visualized as a call-graph style diagram similar to profiling tools like gprof.

Parameters

ParameterTypeDefaultDescription
circuitQCircuit or QProgrequiredThe quantum circuit or program to profile
gate_timesdict[str, float]requiredDictionary mapping gate names to their execution times
is_showboolFalseWhether to display the profile graph after drawing
out_filestrNoneFile path to save the output image (e.g., "profile.png")

Returns

None. The function generates a visual graph and optionally saves it to a file or displays it.

draw_circuit_DAG

python
draw_circuit_DAG(circuit: QCircuit, is_show: bool = False,
                 save_fn: str = None) -> None

Draws the Directed Acyclic Graph (DAG) representation of a quantum circuit, showing the dependency structure between gates organized into layers.

Parameters

ParameterTypeDefaultDescription
circuitQCircuitrequiredThe quantum circuit to visualize as a DAG
is_showboolFalseWhether to display the DAG graph after drawing
save_fnstrNoneFile path to save the output image

Returns

None. The function generates and optionally saves or displays the DAG visualization.

draw_circuit_features

python
draw_circuit_features(circuit: Union[QCircuit, QProg], is_show: bool = False,
                      save_fn: str = None, title: str = "") -> None

Computes and visualizes circuit features as a radar chart. The computed features are:

  • Program Communication: Measures how well qubits are connected through gate operations
  • Liveness: Fraction of qubits that are actively used throughout the circuit
  • Parallelism: Degree of gate-level parallelism in the circuit
  • Entanglement: Measure of entanglement capability in the circuit
  • Critical Depth: Depth of the critical path relative to total depth

Parameters

ParameterTypeDefaultDescription
circuitQCircuit or QProgrequiredThe quantum circuit or program to analyze
is_showboolFalseWhether to display the radar chart
save_fnstrNoneFile path to save the radar chart image
titlestr""Title for the radar chart plot

Returns

None. The function generates and optionally saves or displays the radar chart.

Examples

Profile a circuit with gate timing

python
from pyqpanda3.profiling import draw_circuit_profile
from pyqpanda3.core import QCircuit, H, CNOT

circuit = QCircuit(3)
circuit << H(0) << CNOT(0, 1) << CNOT(1, 2)

# Define gate execution times (in nanoseconds)
gate_times = {"H": 60, "CNOT": 200}

# Generate and save the performance profile
draw_circuit_profile(circuit, gate_times, out_file="circuit_profile.png")

Visualize circuit features

python
from pyqpanda3.profiling import draw_circuit_features
from pyqpanda3.core import QCircuit, H, CNOT, RX

circuit = QCircuit(3)
circuit << H(0) << CNOT(0, 1) << RX(1, 1.57) << CNOT(1, 2)

# Generate a radar chart of circuit features
draw_circuit_features(circuit, is_show=True, title="My Circuit")
draw_circuit_features(circuit, save_fn="features.png", title="Circuit Analysis")

Draw circuit DAG

python
from pyqpanda3.profiling.profiling import draw_circuit_DAG
from pyqpanda3.core import QCircuit, H, CNOT

circuit = QCircuit(3)
circuit << H(0) << CNOT(0, 1) << CNOT(1, 2)

# Visualize the gate dependency structure
draw_circuit_DAG(circuit, save_fn="circuit_dag.png")

Dependencies

The profiling module requires the following Python packages:

  • networkx -- For graph-based circuit analysis
  • graphviz -- For rendering DAG and profile visualizations

See Also

Released under the MIT License.