Skip to content

Improve method Pattern.draw_graph #387

@matulni

Description

@matulni

This issue qualifies for UnitaryDESIGN 2026! It consists of two related but independent tasks.

Context

Graphix offers the possibility to graphically represent an MBQC pattern by calling :func: graphix.Pattern.draw_graph. This method produces a plot of the underlying open graph resource state of the pattern and its flow (when it exists). Example:

>>> p = Pattern(input_nodes=[1], cmds=[N(0), N(2), N(3), N(4), N(5), N(6), N(7), E((0, 1)), E((0, 3)), E((1, 4)), E((3, 4)), E((3, 2)), E((3, 6)), E((4, 7)), E((2, 5)), M(0, Plane.XZ, 0.1), Z(2, {0}), Z(6, {0}), Z(7, {0}), X(4, {0}), X(7, {0}), M(1, angle=0.1), Z(5, {1}), Z(7, {1}), X(2, {1}), X(4, {1}), M(3), X(6, {3}), M(4, angle=0.1), X(7, {4}), M(5, Plane.YZ, 0.1), Z(2, {5})])
>>> p.draw_graph(flow_from_pattern=False, show_measurement_planes=True)

Output:

Image

The output plot contains the following information:

  • Nodes and edges of the underlying open graph resource state. Nodes (circles) represent qubits and edges (thin dashed lines) represent the application of an entanglement command ($CZ$ gate) between the linked nodes.
  • Qubit number (as node labels).
  • Input qubits (red-border nodes). In the example, node 1.
  • Output qubits (grey nodes). In the example, nodes {2, 6, 7}.
  • The measurement label of non-ouptut nodes (text label). There exist 6 possible measurement labels: XY, XZ, YZ, X, Y and Z (although some of these are not currently implemented in the draw_graph method).
  • Pauli-measured nodes (blue nodes), which are nodes measured along the X, Y or Z axes. In the example, node 3.
  • Correction function of the pattern's flow (indicated with arrows from a measured node to its correcting nodes). In the example node 0 is corrected by nodes {0, 3, 4, 7}, node 1 is corrected by nodes {2, 4}, etc.
  • Pattern's execution order (partial order of the pattern's flow). This is represented as a partition of the graph's nodes in layers, such that nodes in the same layer can be measured simultaneously. Layers are separated by a dashed vertical line and labelled with an integer, e.g., L: 2.
    Left-most layer must be measured first and right-most nodes are the output nodes (not measured). In the example, nodes {0, 1} are in layer 2, nodes {3, 4, 5} are in layer 1 and nodes {2, 6, 7} are in layer 0.

(Some of these features are optional, see the docstrings for additional information).

Task A (No coding required!)

Propose an alternative and conceptually new way of representing patterns. To be successful new representation must

  • Contain all the information listed above.
  • Be suitable for a scientific publication.
  • Be readable for those with red-green color blindness.
  • Not suffer the same limitations as the current representation (detailed in Task B).

Task B

We identified several limitations in the existing visualization tool that we list below. Your task is to address all or some of them.

  1. Layers are separated with vertical dashed lines which make the image cramped. It's confusing that graph edges are also represented with dashed lines. Ideally,

    • Layers should not hinder the graph readability.
    • The pattern's execution order (i.e., that nodes are measured from left to right, and nodes in the same layer can be measured simultaneously) should be visually explicit (e.g., by adding an arrow).
  2. The representation of the open graph does not comply with the usual choice in the literature (e.g., see [1, 2]) where:

    • Inputs are represented as squares.
    • Measured nodes (non-output nodes) are solid.
    • Output nodes are empty circles.
  3. It should be possible to display the measurement angles (in units of $\pi$, see graphix.pretty_print) as a label, together with the measurement plane. These labels should always be legible, e.g., by ensuring that they never overlap with graph edges.

  4. It should be possible to optionally add a legend to the figure indicating all the visual information in the graph (inputs, outputs, Pauli measurements, meaning of the arrows).

New methods should have the appropriate docstrings and unit tests.

References

[1] Browne et al., NJP 9, 250 (2007).

[2] Mitosek and Backens, 2024 (arXiv:2410.23439).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions