Visualization tool

graphix.visualization module

This module provides functions to visualize the resource state of MBQC pattern. If flow or gflow exist, the tool take them into account and show the information flow as directed edges.

class graphix.visualization.GraphVisualizer(g: nx.Graph[int], v_in: Collection[int], v_out: Collection[int], meas_plane: Mapping[int, Plane] | None = None, meas_angles: Mapping[int, ExpressionOrFloat] | None = None, local_clifford: Mapping[int, Clifford] | None = None)[source]

A class for visualizing MBQC graphs with flow or gflow structure.

g

The graph to be visualized

Type:

networkx.Graph

v_in

list of input nodes

Type:

list

v_out

list of output nodes

Type:

list

meas_planes

dict specifying the measurement planes for each node, except output nodes.

Type:

dict

meas_angles

dict specifying the measurement angles for each node, except output nodes.

Type:

dict

local_clifford

dict specifying the local clifford for each node.

Type:

dict

__init__(g: nx.Graph[int], v_in: Collection[int], v_out: Collection[int], meas_plane: Mapping[int, Plane] | None = None, meas_angles: Mapping[int, ExpressionOrFloat] | None = None, local_clifford: Mapping[int, Clifford] | None = None)[source]

Construct a graph visualizer.

Parameters:
  • g (networkx.Graph) – NetworkX graph instance

  • v_in (list) – list of input nodes

  • v_out (list) – list of output nodes

  • meas_plane (dict) – dict specifying the measurement planes for each node, except output nodes. if None, all measurements are assumed to be in XY-plane.

  • meas_angles (dict) – dict specifying the measurement angles for each node, except output nodes.

  • local_clifford (dict) – dict specifying the local clifford for each node.

determine_figsize(l_k: Mapping[int, int] | None, pos: Mapping[int, _Point] | None = None, node_distance: tuple[float, float] = (1, 1)) _Point[source]

Return the figure size of the graph.

Parameters:
  • l_k (dict) – Layer mapping.

  • pos (dict) – dictionary of node positions.

  • node_distance (tuple) – Distance multiplication factor between nodes for x and y directions.

Returns:

figsize – figure size of the graph.

Return type:

tuple

place_all_corrections(layers: Mapping[int, int]) dict[int, _Point][source]

Return the position of nodes based on the pattern.

Parameters:

layers (dict) – Layer mapping obtained from the measurement order of the pattern.

Returns:

pos – dictionary of node positions.

Return type:

dict

place_edge_paths(flow: Mapping[int, AbstractSet[int]], pos: Mapping[int, _Point]) tuple[dict[_Edge, list[_Point]], dict[_Edge, list[_Point]]][source]

Return the path of edges and gflow arrows.

Parameters:
  • flow (dict) – flow mapping (including gflow or any correction flow)

  • pos (dict) – dictionary of node positions.

Returns:

  • edge_path (dict) – dictionary of edge paths.

  • arrow_path (dict) – dictionary of arrow paths.

place_edge_paths_without_structure(pos: Mapping[int, _Point]) dict[_Edge, list[_Point]][source]

Return the path of edges.

Parameters:

pos (dict) – dictionary of node positions.

Returns:

edge_path – dictionary of edge paths.

Return type:

dict

place_flow(flow: CausalFlow[AbstractPlanarMeasurement]) dict[int, _Point][source]

Return the position of nodes based on the flow.

Parameters:
  • f (dict) – flow mapping.

  • l_k (dict) – Layer mapping.

Returns:

pos – dictionary of node positions.

Return type:

dict

place_gflow(flow: GFlow[AbstractPlanarMeasurement]) dict[int, _Point][source]

Return the position of nodes based on the gflow.

Parameters:
  • g (dict) – gflow mapping.

  • l_k (dict) – Layer mapping.

Returns:

pos – dictionary of node positions.

Return type:

dict

place_without_structure() dict[int, _Point][source]

Return the position of nodes based on the graph.

Returns:

pos – dictionary of node positions.

Return type:

dict

Returns:

pos – dictionary of node positions.

Return type:

dict

visualize(show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, show_loop: bool = True, node_distance: tuple[float, float] = (1, 1), figsize: tuple[int, int] | None = None, filename: Path | None = None) None[source]

Visualize the graph with flow or gflow structure.

If there exists a flow structure, then the graph is visualized with the flow structure. If flow structure is not found and there exists a gflow structure, then the graph is visualized with the gflow structure. If neither flow nor gflow structure is found, then the graph is visualized without any structure.

Parameters:
  • show_pauli_measurement (bool) – If True, the nodes with Pauli measurement angles are colored light blue.

  • show_local_clifford (bool) – If True, indexes of the local Clifford operator are displayed adjacent to the nodes.

  • show_measurement_planes (bool) – If True, the measurement planes are displayed adjacent to the nodes.

  • show_loop (bool) – whether or not to show loops for graphs with gflow. defaulted to True.

  • node_distance (tuple) – Distance multiplication factor between nodes for x and y directions.

  • figsize (tuple) – Figure size of the plot.

  • filename (Path | None) – If not None, filename of the png file to save the plot. If None, the plot is not saved. Default in None.

visualize_from_pattern(pattern: Pattern, show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, show_loop: bool = True, node_distance: tuple[float, float] = (1, 1), figsize: tuple[int, int] | None = None, filename: Path | None = None) None[source]

Visualize the graph with flow or gflow structure found from the given pattern.

If pattern sequence is consistent with flow structure, then the graph is visualized with the flow structure. If it is not consistent with flow structure and consistent with gflow structure, then the graph is visualized with the gflow structure. If neither flow nor gflow structure is found, then the graph is visualized with all correction flows.

Parameters:
  • pattern (Pattern) – pattern to be visualized

  • show_pauli_measurement (bool) – If True, the nodes with Pauli measurement angles are colored light blue.

  • show_local_clifford (bool) – If True, indexes of the local Clifford operator are displayed adjacent to the nodes.

  • show_measurement_planes (bool) – If True, the measurement planes are displayed adjacent to the nodes.

  • show_loop (bool) – whether or not to show loops for graphs with gflow. defaulted to True.

  • node_distance (tuple) – Distance multiplication factor between nodes for x and y directions.

  • figsize (tuple) – Figure size of the plot.

  • filename (Path | None) – If not None, filename of the png file to save the plot. If None, the plot is not saved. Default in None.

visualize_graph(pos: Mapping[int, _Point], place_paths: Callable[[Mapping[int, _Point]], tuple[Mapping[_Edge, Sequence[_Point]], Mapping[_Edge, Sequence[_Point]] | None]], l_k: Mapping[int, int] | None, corrections: tuple[Mapping[int, AbstractSet[int]], Mapping[int, AbstractSet[int]]] | None, show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, show_loop: bool = True, node_distance: tuple[float, float] = (1, 1), figsize: _Point | None = None, filename: Path | None = None) None[source]

Visualizes the graph.

Nodes are colored based on their role (input, output, or other) and edges are depicted as arrows or dashed lines depending on whether they are in the flow mapping. Vertical dashed lines separate different layers of the graph. This function does not return anything but plots the graph using matplotlib’s pyplot.

Parameters:
  • pos (Mapping[int, _Point]) – Node positions.

  • place_paths (Callable[) – [Mapping[int, _Point]], tuple[Mapping[_Edge, Sequence[_Point]], Mapping[_Edge, Sequence[_Point]] | None]

  • ] – Given scaled node positions, return the mapping of edge paths and the mapping of arrow paths.

  • l_k (Mapping[int, int] | None) – Layer mapping if any.

  • corrections (tuple[Mapping[int, AbstractSet[int]], Mapping[int, AbstractSet[int]]] | None) – X and Z corrections if any.

  • show_pauli_measurement (bool) – If True, the nodes with Pauli measurement angles are colored light blue.

  • show_local_clifford (bool) – If True, indexes of the local Clifford operator are displayed adjacent to the nodes.

  • show_measurement_planes (bool) – If True, the measurement planes are displayed adjacent to the nodes.

  • show_loop (bool) – whether or not to show loops for graphs with gflow. defaulted to True.

  • node_distance (tuple) – Distance multiplication factor between nodes for x and y directions.

  • figsize (tuple) – Figure size of the plot.

  • filename (Path | None) – If not None, filename of the png file to save the plot. If None, the plot is not saved. Default in None.