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
draw_circuit_profile(circuit: Union[QCircuit, QProg], gate_times: dict,
is_show: bool = False, out_file: str = None) -> NoneDraws 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
| Parameter | Type | Default | Description |
|---|---|---|---|
| circuit | QCircuit or QProg | required | The quantum circuit or program to profile |
| gate_times | dict[str, float] | required | Dictionary mapping gate names to their execution times |
| is_show | bool | False | Whether to display the profile graph after drawing |
| out_file | str | None | File 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
draw_circuit_DAG(circuit: QCircuit, is_show: bool = False,
save_fn: str = None) -> NoneDraws the Directed Acyclic Graph (DAG) representation of a quantum circuit, showing the dependency structure between gates organized into layers.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| circuit | QCircuit | required | The quantum circuit to visualize as a DAG |
| is_show | bool | False | Whether to display the DAG graph after drawing |
| save_fn | str | None | File path to save the output image |
Returns
None. The function generates and optionally saves or displays the DAG visualization.
draw_circuit_features
draw_circuit_features(circuit: Union[QCircuit, QProg], is_show: bool = False,
save_fn: str = None, title: str = "") -> NoneComputes 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
| Parameter | Type | Default | Description |
|---|---|---|---|
| circuit | QCircuit or QProg | required | The quantum circuit or program to analyze |
| is_show | bool | False | Whether to display the radar chart |
| save_fn | str | None | File path to save the radar chart image |
| title | str | "" | 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
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
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
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 analysisgraphviz-- For rendering DAG and profile visualizations
See Also
- visualization Module -- Circuit drawing and display options
- core Module -- Core quantum computing primitives including QCircuit and QProg