From 9fdb76ef66dc93a3a1b788af3123c8f1ad334024 Mon Sep 17 00:00:00 2001 From: Elias Foramitti Date: Fri, 3 Nov 2023 16:40:43 +0100 Subject: [PATCH] fixing swap visualization bug --- src/mqt/qmap/compile.py | 1 + src/mqt/qmap/visualization/search_visualizer.py | 4 ++-- .../qmap/visualization/visualize_search_graph.py | 14 +++++++------- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/mqt/qmap/compile.py b/src/mqt/qmap/compile.py index 4bdfe93b6..c8ec1f556 100644 --- a/src/mqt/qmap/compile.py +++ b/src/mqt/qmap/compile.py @@ -59,6 +59,7 @@ def compile( # noqa: A001 arch: str | Arch | Architecture | Backend | None, calibration: str | BackendProperties | Target | None = None, method: str | Method = "heuristic", + consider_fidelity: bool = False, initial_layout: str | InitialLayout = "dynamic", layering: str | Layering = "individual_gates", lookaheads: int | None = 15, diff --git a/src/mqt/qmap/visualization/search_visualizer.py b/src/mqt/qmap/visualization/search_visualizer.py index 15e5a53e3..f311d388c 100644 --- a/src/mqt/qmap/visualization/search_visualizer.py +++ b/src/mqt/qmap/visualization/search_visualizer.py @@ -9,7 +9,7 @@ from typing_extensions import Self -from mqt.qmap.visualization.visualize_search_graph import Position, SearchNode, visualize_search_graph +from mqt.qmap.visualization.visualize_search_graph import SearchNode, visualize_search_graph if TYPE_CHECKING: from ipywidgets import Widget @@ -54,7 +54,7 @@ def close(self) -> None: def visualize_search_graph( self, layer: int | Literal["interactive"] = "interactive", # 'interactive' (slider menu) | index - architecture_node_positions: MutableMapping[int, Position] | None = None, + architecture_node_positions: MutableMapping[int, tuple[float, float]] | None = None, architecture_layout: Literal["dot", "neato", "fdp", "sfdp", "circo", "twopi", "osage", "patchwork"] = "sfdp", search_node_layout: Literal[ "walker", "dot", "neato", "fdp", "sfdp", "circo", "twopi", "osage", "patchwork" diff --git a/src/mqt/qmap/visualization/visualize_search_graph.py b/src/mqt/qmap/visualization/visualize_search_graph.py index 1679b66b5..c6c4eded9 100644 --- a/src/mqt/qmap/visualization/visualize_search_graph.py +++ b/src/mqt/qmap/visualization/visualize_search_graph.py @@ -55,8 +55,6 @@ class _SwapArrowProps(TypedDict): from plotly.subplots import make_subplots from walkerlayout import WalkerLayouting -# TODO: show_swaps not working! - @dataclass class _TwoQbitMultiplicity: @@ -705,6 +703,7 @@ def _visualize_layout( arch_node_positions: MutableMapping[int, Position], initial_layout: list[int], considered_qubit_colors: MutableMapping[int, str], + show_swaps: bool, swap_arrow_offset: float, arch_x_arrow_spacing: float, arch_y_arrow_spacing: float, @@ -727,7 +726,7 @@ def _visualize_layout( ) stats = go.layout.Annotation(**plotly_settings["stats_legend"]) annotations: list[go.layout.Annotation] = [] - if len(swaps) > 0: + if show_swaps and len(swaps) > 0: annotations = _draw_swap_arrows( arch_node_positions, initial_layout, @@ -875,7 +874,7 @@ def _load_layer_data( ] shuffle(considered_qubits_color_codes) considered_qubit_colors: dict[int, str] = {} - for q in considered_qubit_colors: + for q in considered_qubit_color_groups: considered_qubit_colors[q] = considered_qubits_color_codes[considered_qubit_color_groups[q]] return ( # type: ignore[return-value] @@ -1591,8 +1590,8 @@ def visualize_search_graph( # 'architecture_xaxis': settings for plotly.graph_objects.layout.XAxis # 'architecture_yaxis': settings for plotly.graph_objects.layout.YAxis # } - # TODO: show archticture edge labels (and control text?) - # TODO: control hover text of search (especially for multiple points per node!) and architecture nodes? + # TODO: show archticture edge labels (and make text adjustable) + # TODO: make hover text of search (especially for multiple points per node!) and architecture nodes adjustable ) -> Widget: """Creates a widget to visualize a search graph. @@ -1950,6 +1949,7 @@ def visualize_search_node_layout( architecture_node_positions, # type: ignore[arg-type] initial_layout, considered_qubit_colors, + show_swaps, swap_arrow_offset, arch_x_arrow_spacing, # type: ignore[arg-type] arch_y_arrow_spacing, # type: ignore[arg-type] @@ -2125,7 +2125,7 @@ def update_layer(new_layer: int) -> None: layer_slider = interactive( update_layer, new_layer=IntSlider( - min=0, max=number_of_layers, step=1, value=0, description="Layer:", layout=Layout(width=f"{width-80}px") + min=0, max=number_of_layers-1, step=1, value=0, description="Layer:", layout=Layout(width=f"{width-80}px") ), )