Visualization Module

The visualize module provides rich visualization and analysis tools for infrastructure simulation results.

Dashboard

Real-time dashboard for infrastructure simulation monitoring.

class infralib.visualize.dashboard.DashboardState(simulator: ~infralib.simulator.Simulator = None, is_running: bool = False, current_step: int = 0, max_steps: int = 1000, step_delay: float = 0.1, states_history: ~collections.deque = <factory>, budget_history: ~collections.deque = <factory>, cost_history: ~collections.deque = <factory>, failure_history: ~collections.deque = <factory>, action_history: ~collections.deque = <factory>)[source]

Bases: object

Container for dashboard state data.

simulator: Simulator = None
is_running: bool = False
current_step: int = 0
max_steps: int = 1000
step_delay: float = 0.1
states_history: deque
budget_history: deque
cost_history: deque
failure_history: deque
action_history: deque
__init__(simulator: ~infralib.simulator.Simulator = None, is_running: bool = False, current_step: int = 0, max_steps: int = 1000, step_delay: float = 0.1, states_history: ~collections.deque = <factory>, budget_history: ~collections.deque = <factory>, cost_history: ~collections.deque = <factory>, failure_history: ~collections.deque = <factory>, action_history: ~collections.deque = <factory>) None
class infralib.visualize.dashboard.SimulatorDashboard[source]

Bases: object

Real-time dashboard for monitoring infrastructure simulation.

__init__()[source]
setup_sidebar()[source]

Setup dashboard sidebar controls.

create_policy_function(policy_type: str, n_components: int) Callable[source]

Create policy function based on selected type.

initialize_simulator(n_components: int)[source]

Initialize simulator with default configuration.

run_simulation_step(policy_fn: Callable)[source]

Run one simulation step.

display_key_metrics()[source]

Display key simulation metrics.

display_real_time_plots()[source]

Display real-time plots.

run()[source]

Main dashboard run loop.

infralib.visualize.dashboard.launch_dashboard()[source]

Launch the Streamlit dashboard.

Network Visualization

Network topology visualization for infrastructure systems.

class infralib.visualize.network.NetworkVisualizer[source]

Bases: object

Visualize infrastructure networks and topologies.

__init__()[source]
create_network_graph(components: list[dict], connections: list[tuple] = None, layout: str = 'spring') Figure[source]

Create network graph visualization of infrastructure components.

create_geographic_map(components: list[dict], center_lat: float = 52.5, center_lon: float = 13.4, zoom: int = 10) Map[source]

Create geographic map with infrastructure components.

create_cascade_visualization(components: list[dict], cascade_steps: list[dict], connections: list[tuple] = None) list[Figure][source]

Create animation frames showing cascade failure propagation.

create_traffic_flow_map(road_network: dict, traffic_data: dict = None) Map[source]

Create map showing traffic flow on road network.

create_heatmap(components: list[dict], value_field: str = 'state', center_lat: float = 52.5, center_lon: float = 13.4) Map[source]

Create heatmap of component values.

Plots

Static visualization plots for infrastructure simulation data.

class infralib.visualize.plots.PlotGenerator[source]

Bases: object

Generate various plots for infrastructure simulation analysis.

__init__()[source]
plot_component_states(states_history: list[ndarray], title: str = 'Component States Over Time') Figure[source]

Plot component state evolution over time.

plot_budget_usage(budget_history: list[float], cost_history: list[ndarray], title: str = 'Budget Usage Over Time') Figure[source]

Plot budget usage and spending patterns.

plot_failure_analysis(states_history: list[ndarray], title: str = 'Failure Analysis') Figure[source]

Plot failure counts and patterns over time.

plot_action_heatmap(actions_history: list[ndarray], title: str = 'Action Heatmap') Figure[source]

Plot heatmap of actions taken over time and components.

plot_hierarchy_metrics(hierarchy_metrics: dict[str, dict], title: str = 'Hierarchy Performance') Figure[source]

Plot hierarchy-based performance metrics.

plot_learning_curves(training_data: dict[str, list], title: str = 'RL Training Progress') Figure[source]

Plot RL training learning curves.

plot_comparison_algorithms(algorithm_results: dict[str, dict], title: str = 'Algorithm Comparison') Figure[source]

Compare performance of different RL algorithms.

create_performance_report(simulation_data: dict[str, Any]) dict[str, Figure][source]

Create a comprehensive performance report with multiple plots.

Simulator Plots

Matplotlib/Seaborn visualization utilities for infrastructure simulators.

infralib.visualize.simulator_plots.set_plot_style(style: str = 'whitegrid', context: str = 'paper', font_scale: float = 1.5)[source]

Set consistent plot style for publication-quality figures.

Parameters:
  • style (str) – Seaborn style preset

  • context (str) – Seaborn context for scaling

  • font_scale (float) – Font scaling factor

infralib.visualize.simulator_plots.plot_state_budget_history(simulator: Any, num_steps: int, save_path: str | None = None, show: bool = True, figsize: tuple[int, int] = (14, 15)) Figure[source]

Plot the distribution of component states over time, budget changes, and action counts.

This visualization provides a comprehensive view of the simulation history including: - Distribution of component states (violin plot) - Budget evolution over time - Action counts per timestep

Parameters:
  • simulator (Simulator) – The simulator instance after simulation with state_history, budget_history, and action_history attributes

  • num_steps (int) – Number of time steps in the simulation

  • save_path (str, optional) – Path to save the figure

  • show (bool) – Whether to display the plot

  • figsize (tuple) – Figure size (width, height)

Returns:

fig – The generated figure

Return type:

matplotlib.figure.Figure

infralib.visualize.simulator_plots.plot_component_states_comparison(state_histories: list[ndarray], action_histories: list[ndarray] | None = None, labels: list[str] | None = None, failure_conditions: ndarray | None = None, component_idx: int = 0, type_indices: ndarray | None = None, max_steps: int | None = None, save_path: str | None = None, show: bool = True, figsize: tuple[int, int] | None = None) Figure[source]

Plot and compare condition index over time for a specific component across different policies.

This is useful for comparing how different control strategies affect individual component degradation and maintenance.

Parameters:
  • state_histories (list of np.ndarray) – State history for each policy/strategy. Shape: (timesteps, n_components)

  • action_histories (list of np.ndarray, optional) – Action history for each policy. Shape: (timesteps, n_components)

  • labels (list of str, optional) – Labels for each policy/strategy

  • failure_conditions (np.ndarray, optional) – Failure thresholds for each component type

  • component_idx (int) – Index of component to visualize

  • type_indices (np.ndarray, optional) – Mapping from component index to component type

  • max_steps (int, optional) – Maximum number of steps to show

  • save_path (str, optional) – Path to save the figure

  • show (bool) – Whether to display the plot

  • figsize (tuple, optional) – Figure size (width, height)

Returns:

fig – The generated figure

Return type:

matplotlib.figure.Figure

infralib.visualize.simulator_plots.plot_action_distribution(action_history: ndarray, save_path: str | None = None, show: bool = True, figsize: tuple[int, int] = (10, 6)) Figure[source]

Plot the distribution of actions taken during simulation.

Parameters:
  • action_history (np.ndarray) – Action history array. Shape: (timesteps, n_components)

  • save_path (str, optional) – Path to save the figure

  • show (bool) – Whether to display the plot

  • figsize (tuple) – Figure size (width, height)

Returns:

fig – The generated figure

Return type:

matplotlib.figure.Figure