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, v_in, v_out)[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

__init__(G, v_in, v_out)[source]

G: networkx graph v_in: list of input nodes v_out: list of output nodes

check_path(path)[source]

if there is an acute angle in the path, merge points

static control_point(start, end, node_pos, distance=0.6)[source]

Generate a control point to bend the edge around a node.

static edge_intersects_node(start, end, node_pos, buffer=0.2)[source]

Determine if an edge intersects a node.

get_edge_path(fg, pos)[source]

Returns the path of edges.

Parameters
  • fg (dict) – flow or gflow mapping.

  • pos (dict) – dictionary of node positions.

Returns

edge_path – dictionary of edge paths.

Return type

dict

get_figsize(l_k)[source]

Returns the figure size of the graph.

Parameters

l_k (dict) – Layer mapping.

Returns

figsize – figure size of the graph.

Return type

tuple

get_pos_from_flow(f, l_k)[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, l_k)[source]

Returns the position of nodes based on the gflow.

Returns

pos – dictionary of node positions.

Return type

dict

visualize(angles=None, local_clifford=None, figsize=None, save=False, filename=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
  • angles (dict) – Measurement angles for each nodes on the graph (unit of pi), except output nodes. If not None, the nodes with Pauli measurement angles are colored light blue.

  • local_clifford (dict) – Indexes of local clifford operations for each nodes. If not None, indexes of the local Clifford operator are displayed adjacent to the nodes.

  • 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, l_k, angles=None, local_clifford=None, figsize=None, save=False, filename=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.

  • angles (dict) – Measurement angles for each nodes on the graph (unit of pi), except output nodes. If not None, the nodes with Pauli measurement angles are colored light blue.

  • local_clifford (dict) – Indexes of local clifford operations for each nodes. If not None, indexes of the local Clifford operator are displayed adjacent to the nodes.

  • 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_gflow(g, l_k, angles=None, local_clifford=None, figsize=None, save=False, filename=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.

  • angles (dict) – Measurement angles for each nodes on the graph (unit of pi), except output nodes. If not None, the nodes with Pauli measurement angles are colored light blue.

  • local_clifford (dict) – Indexes of local clifford operations for each nodes. If not None, indexes of the local Clifford operator are displayed adjacent to the nodes.

  • 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(angles=None, local_clifford=None, save=False, filename=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
  • f (dict) – flow mapping.

  • l_k (dict) – Layer mapping.

  • angles (dict) – Measurement angles for each nodes on the graph (unit of pi), except output nodes. If not None, the nodes with Pauli measurement angles are colored light blue.

  • local_clifford (dict) – Indexes of local clifford operations for each nodes. If not None, indexes of the local Clifford operator are displayed adjacent to the nodes.

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