Visualization tool

graphix.visualization module

This 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: Graph, v_in: list[int], v_out: list[int], meas_plane: Optional[dict[int, str]] = None, meas_angles: Optional[dict[int, float]] = None, local_clifford: Optional[dict[int, int]] = 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: Graph, v_in: list[int], v_out: list[int], meas_plane: Optional[dict[int, str]] = None, meas_angles: Optional[dict[int, float]] = None, local_clifford: Optional[dict[int, int]] = None)[source]
Parameters
  • G (networkx.graph.Graph object) – networkx graph

  • 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.

get_edge_path(flow: dict[int, int | set[int]], pos: dict[int, tuple[float, float]]) dict[int, list][source]

Returns 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.

get_edge_path_wo_structure(pos: dict[int, tuple[float, float]]) dict[int, list][source]

Returns the path of edges.

Parameters

pos (dict) – dictionary of node positions.

Returns

edge_path – dictionary of edge paths.

Return type

dict

get_figsize(l_k: dict[int, int], pos: Optional[dict[int, tuple[float, float]]] = None, node_distance: tuple[int, int] = (1, 1)) tuple[int, int][source]

Returns 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

get_pos_all_correction(layers: dict[int, int]) dict[int, tuple[float, float]][source]

Returns 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

get_pos_from_flow(f: dict[int, int], l_k: dict[int, int]) dict[int, tuple[float, float]][source]

Returns 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

get_pos_from_gflow(g: dict[int, set[int]], l_k: dict[int, int]) dict[int, tuple[float, float]][source]

Returns 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

get_pos_wo_structure() dict[int, tuple[float, float]][source]

Returns 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[int, int] = (1, 1), figsize: Optional[tuple[int, int]] = None, save: bool = False, filename: Optional[str] = None)[source]

Visualizes 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.

  • save (bool) – If True, the plot is saved as a png file.

  • filename (str) – Filename of the saved plot.

visualize_all_correction(layers: dict[int, int], xflow: dict[int, set[int]], zflow: dict[int, set[int]], show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, node_distance: tuple[int, int] = (1, 1), figsize: Optional[tuple[int, int]] = None, save: bool = False, filename: Optional[str] = None)[source]

visualizes the graph of pattern with all correction flows.

Nodes are colored based on their role (input, output, or other) and edges of graph are depicted as dashed lines. Xflow is depicted as red arrows and Zflow is depicted as blue arrows. The function does not return anything but plots the graph using matplotlib’s pyplot.

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

  • xflow (dict) – Dictionary for x correction of the pattern.

  • zflow (dict) – Dictionary for z correction of the pattern.

  • 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.

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

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

  • save (bool) – If True, the plot is saved as a png file.

  • filename (str) – Filename of the saved plot.

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[int, int] = (1, 1), figsize: tuple[int, int] | None = None, save: bool = False, filename: str | None = None)[source]

Visualizes 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.

  • save (bool) – If True, the plot is saved as a png file.

  • filename (str) – Filename of the saved plot.

visualize_w_flow(f: dict[int, set[int]], l_k: dict[int, int], show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, node_distance: tuple[int, int] = (1, 1), figsize: Optional[tuple[int, int]] = None, save: bool = False, filename: Optional[str] = None)[source]

visualizes the graph with flow structure.

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
  • f (dict) – flow mapping.

  • l_k (dict) – Layer mapping.

  • 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.

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

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

  • save (bool) – If True, the plot is saved.

  • filename (str) – Filename of the saved plot.

visualize_w_gflow(g: dict[int, set[int]], l_k: dict[int, int], show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, show_loop: bool = True, node_distance: tuple[int, int] = (1, 1), figsize: Optional[tuple[int, int]] = None, save: bool = False, filename: Optional[str] = None)[source]

visualizes the graph with flow structure.

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
  • g (dict) – gflow mapping.

  • l_k (dict) – Layer mapping.

  • 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.

  • save (bool) – If True, the plot is saved as a png file.

  • filename (str) – Filename of the saved plot.

visualize_wo_structure(show_pauli_measurement: bool = True, show_local_clifford: bool = False, show_measurement_planes: bool = False, node_distance: tuple[int, int] = (1, 1), figsize: Optional[tuple[int, int]] = None, save: bool = False, filename: Optional[str] = None)[source]

visualizes the graph without flow or gflow.

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
  • 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.

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

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

  • save (bool) – If True, the plot is saved as a png file.

  • filename (str) – Filename of the saved plot.