Visualization Base Classes¶
The visualization system in QWARD provides a structured approach to creating beautiful, informative plots of quantum circuit analysis results. The base classes define the common interface and utilities used by all visualization strategies.
Key Features: - Strategy Pattern: Extensible design for different visualization types - Consistent Styling: Unified plot configuration and appearance - Automatic Integration: Seamless integration with Scanner and metric results - Flexible Output: Support for saving, showing, and customizing plots
Base Visualization Strategy¶
The VisualizationStrategy class is the abstract base class for all visualizers in QWARD. It provides common functionality and defines the interface that all concrete visualizers must implement.
Core Responsibilities: - Output Management: Handles directory creation and file path management - Plot Configuration: Integrates with PlotConfig for consistent styling - Common Utilities: Provides reusable methods for data validation and plot creation - Abstract Interface: Defines create_dashboard() and plot_all() methods
Usage Pattern:
from qward.visualization.base import VisualizationStrategy, PlotConfig
import pandas as pd
class MyCustomVisualizer(VisualizationStrategy):
def __init__(self, metrics_dict, output_dir="plots", config=None):
super().__init__(output_dir, config)
self.metrics_dict = metrics_dict
def create_dashboard(self, save=True, show=False):
# Create comprehensive dashboard
dashboard_plots = {}
# Implementation here...
return dashboard_plots
def plot_all(self, save=True, show=False):
# Create all individual plots
all_plots = {}
# Implementation here...
return all_plots
API Reference¶
Base classes for QWARD visualization system.
- class PlotConfig(figsize=(10, 6), dpi=300, style='default', color_palette=None, save_format='png', grid=True, alpha=0.7, show_titles=True)[source]¶
Bases:
objectConfiguration for plot appearance and saving.
-
alpha:
float= 0.7¶
-
color_palette:
List[str] = None¶
-
dpi:
int= 300¶
-
figsize:
Tuple[int,int] = (10, 6)¶
-
grid:
bool= True¶
-
save_format:
str= 'png'¶
-
show_titles:
bool= True¶
-
style:
str= 'default'¶
-
alpha:
- class PlotMetadata(name, method_name, description, plot_type, filename, dependencies=None, category=None)[source]¶
Bases:
objectMetadata for individual plots.
-
category:
str= None¶
-
dependencies:
List[str] = None¶
-
description:
str¶
-
filename:
str¶
-
method_name:
str¶
-
name:
str¶
-
category:
- class PlotType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
Bases:
EnumEnumeration of plot types for metadata.
- BAR_CHART = 'bar_chart'¶
- GROUPED_BAR = 'grouped_bar'¶
- LINE_CHART = 'line_chart'¶
- PIE_CHART = 'pie_chart'¶
- RADAR_CHART = 'radar_chart'¶
- SCATTER_PLOT = 'scatter_plot'¶
- STACKED_BAR = 'stacked_bar'¶
- class VisualizationStrategy(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
ABCBase class for all QWARD visualization strategies.
Initialize the visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing metrics data for this strategyoutput_dir (
str) – Directory to save plotsconfig (
Optional[PlotConfig]) – Plot configuration settings
- abstract create_dashboard(save=False, show=False)[source]¶
Create a comprehensive dashboard for this strategy’s metrics.
- Return type:
Figure
- generate_all_plots(save=False, show=False, **kwargs)[source]¶
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)[source]¶
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)[source]¶
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
- abstract classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- abstract classmethod get_plot_metadata(plot_name)[source]¶
Get metadata for a specific plot.
- Return type:
- class VisualizationStrategy(metrics_dict, output_dir='img', config=None)[source]¶
Bases:
ABCBase class for all QWARD visualization strategies.
Initialize the visualization strategy.
- Parameters:
metrics_dict (
Dict[str,DataFrame]) – Dictionary containing metrics data for this strategyoutput_dir (
str) – Directory to save plotsconfig (
Optional[PlotConfig]) – Plot configuration settings
- abstract create_dashboard(save=False, show=False)[source]¶
Create a comprehensive dashboard for this strategy’s metrics.
- Return type:
Figure
- generate_all_plots(save=False, show=False, **kwargs)[source]¶
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)[source]¶
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)[source]¶
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
- abstract classmethod get_available_plots()[source]¶
Return list of available plot names for this strategy.
- Return type:
List[str]
- abstract classmethod get_plot_metadata(plot_name)[source]¶
Get metadata for a specific plot.
- Return type:
Plot Configuration¶
The PlotConfig class provides comprehensive configuration options for plot appearance and behavior.
Configuration Options: - Appearance: Figure size, DPI, color palettes, transparency - Styling: Plot styles (default, quantum, minimal) - Output: Save format (PNG, SVG), grid settings - Extensible: Easy to customize for different visualization needs
Usage Example:
from qward.visualization.base import PlotConfig
# Create custom plot configuration
config = PlotConfig(
figsize=(12, 8), # Larger figures
dpi=150, # High quality
style="quantum", # Quantum-themed styling
color_palette=["#1f77b4", "#ff7f0e", "#2ca02c", "#d62728"],
save_format="svg", # Vector graphics
grid=True, # Show grid lines
alpha=0.8 # Transparency level
)
# Use with any visualizer
from qward.visualization import QiskitVisualizer
visualizer = QiskitVisualizer(metrics_dict, config=config)
- class PlotConfig(figsize=(10, 6), dpi=300, style='default', color_palette=None, save_format='png', grid=True, alpha=0.7, show_titles=True)[source]¶
Bases:
objectConfiguration for plot appearance and saving.
-
alpha:
float= 0.7¶
-
color_palette:
List[str] = None¶
-
dpi:
int= 300¶
-
figsize:
Tuple[int,int] = (10, 6)¶
-
grid:
bool= True¶
-
save_format:
str= 'png'¶
-
show_titles:
bool= True¶
-
style:
str= 'default'¶
-
alpha: