Visualization Strategies¶
QWARD provides specialized visualization strategies for different types of quantum circuit analysis. Each visualizer is designed to create meaningful plots for specific metric categories while maintaining a consistent interface.
QiskitVisualizer¶
The QiskitVisualizer creates visualizations for basic quantum circuit properties extracted by QiskitMetrics. It focuses on fundamental circuit characteristics and instruction analysis.
Visualization Types: - Basic Metrics Overview: Circuit depth, size, qubits, and classical bits - Instruction Analysis: Gate type distribution and frequency analysis - Scheduling Information: Circuit timing and parallelization insights - Comprehensive Dashboard: Combined view of all QiskitMetrics data
Usage Example:
from qiskit import QuantumCircuit
from qward import Scanner
from qward.metrics import QiskitMetrics
from qward.visualization import QiskitVisualizer
# Create and analyze circuit
circuit = QuantumCircuit(3)
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(1, 2)
scanner = Scanner(circuit=circuit)
scanner.add_strategy(QiskitMetrics(circuit))
results = scanner.calculate_metrics()
# Create visualizations
visualizer = QiskitVisualizer(results, output_dir="qiskit_plots")
# Generate dashboard
dashboard = visualizer.create_dashboard(save=True, show=False)
# Generate individual plots
all_plots = visualizer.plot_all(save=True, show=False)
Qiskit visualization strategy for QWARD.
- class QiskitVisualizer(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
VisualizationStrategyVisualization strategy for QiskitMetrics with circuit structure and instruction analysis.
Initialize the Qiskit visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing QiskitMetrics data. Expected key: “QiskitMetrics”.output_dir (
str) – Directory to save plots.config (
Optional[PlotConfig]) – Plot configuration settings.
-
PLOT_REGISTRY:
Dict[str,PlotMetadata] = {'circuit_structure': PlotMetadata(name='circuit_structure', method_name='plot_circuit_structure', description='Visualizes the structure of quantum circuits including depth, width, and gate composition', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='circuit_structure', dependencies=['basic_metrics.depth', 'basic_metrics.num_qubits'], category='Structure Analysis'), 'circuit_summary': PlotMetadata(name='circuit_summary', method_name='plot_circuit_summary', description='Comprehensive overview combining multiple circuit metrics', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='circuit_summary', dependencies=['basic_metrics', 'gate_metrics', 'instruction_metrics'], category='Summary'), 'gate_distribution': PlotMetadata(name='gate_distribution', method_name='plot_gate_distribution', description='Shows the distribution of different gate types used in the circuit', plot_type=<PlotType.PIE_CHART: 'pie_chart'>, filename='gate_distribution', dependencies=['gate_metrics.gate_types'], category='Gate Analysis'), 'instruction_metrics': PlotMetadata(name='instruction_metrics', method_name='plot_instruction_metrics', description='Displays detailed instruction-level metrics and statistics', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='instruction_metrics', dependencies=['instruction_metrics.instruction_count', 'instruction_metrics.instruction_types'], category='Instruction Analysis')}¶
- create_dashboard(save=False, show=False, title=None)[source]¶
Creates a comprehensive dashboard with all QiskitMetrics plots.
- Return type:
Figure
- classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- plot_circuit_structure(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot basic circuit structure metrics.
- Return type:
Figure
- plot_circuit_summary(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot a summary view of key circuit characteristics.
- Return type:
Figure
- class QiskitVisualizer(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
VisualizationStrategyVisualization strategy for QiskitMetrics with circuit structure and instruction analysis.
Initialize the Qiskit visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing QiskitMetrics data. Expected key: “QiskitMetrics”.output_dir (
str) – Directory to save plots.config (
Optional[PlotConfig]) – Plot configuration settings.
-
PLOT_REGISTRY:
Dict[str,PlotMetadata] = {'circuit_structure': PlotMetadata(name='circuit_structure', method_name='plot_circuit_structure', description='Visualizes the structure of quantum circuits including depth, width, and gate composition', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='circuit_structure', dependencies=['basic_metrics.depth', 'basic_metrics.num_qubits'], category='Structure Analysis'), 'circuit_summary': PlotMetadata(name='circuit_summary', method_name='plot_circuit_summary', description='Comprehensive overview combining multiple circuit metrics', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='circuit_summary', dependencies=['basic_metrics', 'gate_metrics', 'instruction_metrics'], category='Summary'), 'gate_distribution': PlotMetadata(name='gate_distribution', method_name='plot_gate_distribution', description='Shows the distribution of different gate types used in the circuit', plot_type=<PlotType.PIE_CHART: 'pie_chart'>, filename='gate_distribution', dependencies=['gate_metrics.gate_types'], category='Gate Analysis'), 'instruction_metrics': PlotMetadata(name='instruction_metrics', method_name='plot_instruction_metrics', description='Displays detailed instruction-level metrics and statistics', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='instruction_metrics', dependencies=['instruction_metrics.instruction_count', 'instruction_metrics.instruction_types'], category='Instruction Analysis')}¶
- create_dashboard(save=False, show=False, title=None)[source]¶
Creates a comprehensive dashboard with all QiskitMetrics plots.
- Return type:
Figure
- generate_all_plots(save=False, show=False, **kwargs)¶
Generate all available plots.
- Parameters:
save (
bool) – Whether to save the plotsshow (
bool) – Whether to display the plots**kwargs – Additional arguments passed to plot methods
- Return type:
Dict[str,Figure]- Returns:
Dictionary mapping plot names to Figure objects
- generate_plot(plot_name, save=False, show=False, **kwargs)¶
Generate a single plot by name.
- Parameters:
plot_name (
str) – Name of the plot to generatesave (
bool) – Whether to save the plotshow (
bool) – Whether to display the plot**kwargs – Additional arguments passed to the plot method
- Return type:
Figure- Returns:
matplotlib Figure object
- Raises:
ValueError – If plot_name is not available
- generate_plots(plot_names=None, save=False, show=False, **kwargs)¶
Generate multiple plots and return as dictionary.
- Parameters:
plot_names (
List[str]) – List of plot names to generate. If None, generates all available plots.save (
bool) – Whether to save the plotsshow (
bool) – Whether to display the plots**kwargs – Additional arguments passed to plot methods
- Return type:
Dict[str,Figure]- Returns:
Dictionary mapping plot names to Figure objects
- classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- plot_circuit_structure(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot basic circuit structure metrics.
- Return type:
Figure
- plot_circuit_summary(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot a summary view of key circuit characteristics.
- Return type:
Figure
- plot_gate_distribution(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot distribution of gate types.
- Return type:
Figure
- plot_instruction_metrics(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot instruction-related metrics.
- Return type:
Figure
- save_plot(fig, filename, **kwargs)¶
Save a plot with consistent settings.
- Parameters:
fig (
Figure) – Matplotlib figure to savefilename (
str) – Name of the file (without extension)**kwargs (
Any) – Additional arguments for savefig
- Return type:
str- Returns:
Full path to saved file
- show_plot(fig)¶
Display a plot.
- Return type:
None
ComplexityVisualizer¶
The ComplexityVisualizer creates sophisticated visualizations for circuit complexity analysis from ComplexityMetrics. It provides insights into various complexity dimensions and their relationships.
Visualization Types: - Gate-Based Analysis: Gate counts, T-gates, CNOT gates, multi-qubit ratios - Entanglement Metrics: Entangling gate density and circuit width analysis - Standardized Metrics: Circuit volume, gate density, and Clifford ratios - Advanced Analysis: Parallelism factors and circuit efficiency - Derived Complexity: Weighted complexity scores and comparative analysis - Comprehensive Dashboard: Multi-dimensional complexity overview
Usage Example:
from qiskit import QuantumCircuit
from qward import Scanner
from qward.metrics import ComplexityMetrics
from qward.visualization import ComplexityVisualizer
# Create complex circuit
circuit = QuantumCircuit(4)
circuit.h(0)
circuit.cx(0, 1)
circuit.cx(1, 2)
circuit.cx(2, 3)
circuit.t(0)
circuit.t(1)
scanner = Scanner(circuit=circuit)
scanner.add_strategy(ComplexityMetrics(circuit))
results = scanner.calculate_metrics()
# Create complexity visualizations
visualizer = ComplexityVisualizer(results, output_dir="complexity_plots")
# Generate comprehensive analysis
dashboard = visualizer.create_dashboard(save=True, show=False)
all_plots = visualizer.plot_all(save=True, show=False)
Complexity visualization strategy for QWARD.
- class ComplexityVisualizer(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
VisualizationStrategyVisualization strategy for ComplexityMetrics with comprehensive complexity analysis.
Initialize the Complexity visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing ComplexityMetrics data. Expected key: “ComplexityMetrics”.output_dir (
str) – Directory to save plots.config (
Optional[PlotConfig]) – Plot configuration settings.
-
PLOT_REGISTRY:
Dict[str,PlotMetadata] = {'complexity_radar': PlotMetadata(name='complexity_radar', method_name='plot_complexity_radar', description='Radar chart showing multiple complexity dimensions for comprehensive analysis', plot_type=<PlotType.RADAR_CHART: 'radar_chart'>, filename='complexity_radar', dependencies=['advanced_metrics.parallelism_factor', 'derived_metrics.weighted_complexity', 'derived_metrics.efficiency_ratio'], category='Comprehensive Analysis'), 'efficiency_metrics': PlotMetadata(name='efficiency_metrics', method_name='plot_efficiency_metrics', description='Shows efficiency-related metrics and derived complexity measures', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='efficiency_metrics', dependencies=['derived_metrics.efficiency_ratio', 'derived_metrics.weighted_complexity'], category='Efficiency Analysis'), 'gate_based_metrics': PlotMetadata(name='gate_based_metrics', method_name='plot_gate_based_metrics', description='Visualizes gate-based complexity metrics including gate counts and distributions', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='gate_based_metrics', dependencies=['gate_based_metrics.gate_count', 'gate_based_metrics.cnot_count', 'gate_based_metrics.single_qubit_gate_count', 'gate_based_metrics.multi_qubit_gate_count'], category='Gate Analysis')}¶
- create_dashboard(save=False, show=False, title=None)[source]¶
Creates a comprehensive dashboard with all ComplexityMetrics plots.
- Return type:
Figure
- classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- plot_complexity_radar(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot complexity metrics as a radar chart.
- Return type:
Figure
- class ComplexityVisualizer(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
VisualizationStrategyVisualization strategy for ComplexityMetrics with comprehensive complexity analysis.
Initialize the Complexity visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing ComplexityMetrics data. Expected key: “ComplexityMetrics”.output_dir (
str) – Directory to save plots.config (
Optional[PlotConfig]) – Plot configuration settings.
-
PLOT_REGISTRY:
Dict[str,PlotMetadata] = {'complexity_radar': PlotMetadata(name='complexity_radar', method_name='plot_complexity_radar', description='Radar chart showing multiple complexity dimensions for comprehensive analysis', plot_type=<PlotType.RADAR_CHART: 'radar_chart'>, filename='complexity_radar', dependencies=['advanced_metrics.parallelism_factor', 'derived_metrics.weighted_complexity', 'derived_metrics.efficiency_ratio'], category='Comprehensive Analysis'), 'efficiency_metrics': PlotMetadata(name='efficiency_metrics', method_name='plot_efficiency_metrics', description='Shows efficiency-related metrics and derived complexity measures', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='efficiency_metrics', dependencies=['derived_metrics.efficiency_ratio', 'derived_metrics.weighted_complexity'], category='Efficiency Analysis'), 'gate_based_metrics': PlotMetadata(name='gate_based_metrics', method_name='plot_gate_based_metrics', description='Visualizes gate-based complexity metrics including gate counts and distributions', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='gate_based_metrics', dependencies=['gate_based_metrics.gate_count', 'gate_based_metrics.cnot_count', 'gate_based_metrics.single_qubit_gate_count', 'gate_based_metrics.multi_qubit_gate_count'], category='Gate Analysis')}¶
- create_dashboard(save=False, show=False, title=None)[source]¶
Creates a comprehensive dashboard with all ComplexityMetrics plots.
- Return type:
Figure
- generate_all_plots(save=False, show=False, **kwargs)¶
Generate all available plots.
- Parameters:
save (
bool) – Whether to save the plotsshow (
bool) – Whether to display the plots**kwargs – Additional arguments passed to plot methods
- Return type:
Dict[str,Figure]- Returns:
Dictionary mapping plot names to Figure objects
- generate_plot(plot_name, save=False, show=False, **kwargs)¶
Generate a single plot by name.
- Parameters:
plot_name (
str) – Name of the plot to generatesave (
bool) – Whether to save the plotshow (
bool) – Whether to display the plot**kwargs – Additional arguments passed to the plot method
- Return type:
Figure- Returns:
matplotlib Figure object
- Raises:
ValueError – If plot_name is not available
- generate_plots(plot_names=None, save=False, show=False, **kwargs)¶
Generate multiple plots and return as dictionary.
- Parameters:
plot_names (
List[str]) – List of plot names to generate. If None, generates all available plots.save (
bool) – Whether to save the plotsshow (
bool) – Whether to display the plots**kwargs – Additional arguments passed to plot methods
- Return type:
Dict[str,Figure]- Returns:
Dictionary mapping plot names to Figure objects
- classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- plot_complexity_radar(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot complexity metrics as a radar chart.
- Return type:
Figure
- plot_efficiency_metrics(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot circuit efficiency and utilization metrics.
- Return type:
Figure
- plot_gate_based_metrics(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot gate-based complexity metrics.
- Return type:
Figure
- save_plot(fig, filename, **kwargs)¶
Save a plot with consistent settings.
- Parameters:
fig (
Figure) – Matplotlib figure to savefilename (
str) – Name of the file (without extension)**kwargs (
Any) – Additional arguments for savefig
- Return type:
str- Returns:
Full path to saved file
- show_plot(fig)¶
Display a plot.
- Return type:
None
CircuitPerformanceVisualizer¶
The CircuitPerformanceVisualizer creates performance analysis visualizations from CircuitPerformanceMetrics. It handles both single job and multiple job scenarios with support for custom success criteria.
Visualization Types: - Success Analysis: Success rates, error rates, and performance trends - Statistical Analysis: Entropy, uniformity, and concentration metrics - Multi-Job Comparison: Comparative analysis across multiple executions - Performance Dashboard: Comprehensive performance overview
Key Features: - Flexible Data Handling: Automatically detects single vs. multiple job scenarios - Custom Success Criteria: Visualizes user-defined success conditions - Statistical Insights: Advanced statistical analysis of quantum measurements - Performance Trends: Identifies patterns in circuit execution performance
Usage Example:
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator
from qward import Scanner
from qward.metrics import CircuitPerformanceMetrics
from qward.visualization import CircuitPerformanceVisualizer
# Create and execute circuit
circuit = QuantumCircuit(2, 2)
circuit.h(0)
circuit.cx(0, 1)
circuit.measure_all()
simulator = AerSimulator()
job = simulator.run(circuit, shots=1000)
# Define success criteria
def bell_state_success(result: str) -> bool:
return result.replace(" ", "") in ["00", "11"]
scanner = Scanner(circuit=circuit, job=job)
scanner.add_strategy(CircuitPerformanceMetrics(
circuit=circuit,
job=job,
success_criteria=bell_state_success
))
results = scanner.calculate_metrics()
# Create performance visualizations
visualizer = CircuitPerformanceVisualizer(results, output_dir="performance_plots")
# Generate performance analysis
dashboard = visualizer.create_dashboard(save=True, show=False)
all_plots = visualizer.plot_all(save=True, show=False)
CircuitPerformance visualization strategy for QWARD.
- class CircuitPerformanceVisualizer(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
VisualizationStrategyVisualization strategy for CircuitPerformance metrics with performance analysis.
Initialize the CircuitPerformance visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing CircuitPerformance metrics. Expected keys: “CircuitPerformance.individual_jobs”, “CircuitPerformance.aggregate”.output_dir (
str) – Directory to save plots.config (
Optional[PlotConfig]) – Plot configuration settings.
-
PLOT_REGISTRY:
Dict[str,PlotMetadata] = {'aggregate_summary': PlotMetadata(name='aggregate_summary', method_name='plot_aggregate_summary', description='Comprehensive summary of all performance metrics in a dashboard format', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='aggregate_summary', dependencies=['success_metrics', 'statistical_metrics'], category='Summary'), 'shot_distribution': PlotMetadata(name='shot_distribution', method_name='plot_shot_distribution', description='Shows the distribution of measurement outcomes across shots', plot_type=<PlotType.STACKED_BAR: 'stacked_bar'>, filename='shot_distribution', dependencies=['success_metrics.total_shots', 'success_metrics.successful_shots'], category='Execution Analysis'), 'success_error_comparison': PlotMetadata(name='success_error_comparison', method_name='plot_success_error_comparison', description='Compares success rates and error rates across different circuit executions', plot_type=<PlotType.GROUPED_BAR: 'grouped_bar'>, filename='success_error_comparison', dependencies=['success_metrics.success_rate', 'success_metrics.error_rate'], category='Performance Analysis')}¶
- create_dashboard(save=False, show=False, title=None)[source]¶
Create a comprehensive dashboard with all CircuitPerformance plots.
- Return type:
Figure
- classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- plot_aggregate_summary(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot aggregate statistics summary.
- Return type:
Figure
- class CircuitPerformanceVisualizer(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
VisualizationStrategyVisualization strategy for CircuitPerformance metrics with performance analysis.
Initialize the CircuitPerformance visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing CircuitPerformance metrics. Expected keys: “CircuitPerformance.individual_jobs”, “CircuitPerformance.aggregate”.output_dir (
str) – Directory to save plots.config (
Optional[PlotConfig]) – Plot configuration settings.
-
PLOT_REGISTRY:
Dict[str,PlotMetadata] = {'aggregate_summary': PlotMetadata(name='aggregate_summary', method_name='plot_aggregate_summary', description='Comprehensive summary of all performance metrics in a dashboard format', plot_type=<PlotType.BAR_CHART: 'bar_chart'>, filename='aggregate_summary', dependencies=['success_metrics', 'statistical_metrics'], category='Summary'), 'shot_distribution': PlotMetadata(name='shot_distribution', method_name='plot_shot_distribution', description='Shows the distribution of measurement outcomes across shots', plot_type=<PlotType.STACKED_BAR: 'stacked_bar'>, filename='shot_distribution', dependencies=['success_metrics.total_shots', 'success_metrics.successful_shots'], category='Execution Analysis'), 'success_error_comparison': PlotMetadata(name='success_error_comparison', method_name='plot_success_error_comparison', description='Compares success rates and error rates across different circuit executions', plot_type=<PlotType.GROUPED_BAR: 'grouped_bar'>, filename='success_error_comparison', dependencies=['success_metrics.success_rate', 'success_metrics.error_rate'], category='Performance Analysis')}¶
- create_dashboard(save=False, show=False, title=None)[source]¶
Create a comprehensive dashboard with all CircuitPerformance plots.
- Return type:
Figure
- generate_all_plots(save=False, show=False, **kwargs)¶
Generate all available plots.
- Parameters:
save (
bool) – Whether to save the plotsshow (
bool) – Whether to display the plots**kwargs – Additional arguments passed to plot methods
- Return type:
Dict[str,Figure]- Returns:
Dictionary mapping plot names to Figure objects
- generate_plot(plot_name, save=False, show=False, **kwargs)¶
Generate a single plot by name.
- Parameters:
plot_name (
str) – Name of the plot to generatesave (
bool) – Whether to save the plotshow (
bool) – Whether to display the plot**kwargs – Additional arguments passed to the plot method
- Return type:
Figure- Returns:
matplotlib Figure object
- Raises:
ValueError – If plot_name is not available
- generate_plots(plot_names=None, save=False, show=False, **kwargs)¶
Generate multiple plots and return as dictionary.
- Parameters:
plot_names (
List[str]) – List of plot names to generate. If None, generates all available plots.save (
bool) – Whether to save the plotsshow (
bool) – Whether to display the plots**kwargs – Additional arguments passed to plot methods
- Return type:
Dict[str,Figure]- Returns:
Dictionary mapping plot names to Figure objects
- classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- plot_aggregate_summary(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot aggregate statistics summary.
- Return type:
Figure
- plot_shot_distribution(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot shot distribution (successful vs failed) as stacked bars.
- Return type:
Figure
- plot_success_error_comparison(save=False, show=False, fig_ax_override=None, title=None)[source]¶
Plot success vs error rates for individual jobs.
- Return type:
Figure
- save_plot(fig, filename, **kwargs)¶
Save a plot with consistent settings.
- Parameters:
fig (
Figure) – Matplotlib figure to savefilename (
str) – Name of the file (without extension)**kwargs (
Any) – Additional arguments for savefig
- Return type:
str- Returns:
Full path to saved file
- show_plot(fig)¶
Display a plot.
- Return type:
None