Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- #386, #433: Added `Statevec.fidelity` and `Statevec.isclose` methods for pure-state fidelity computation and equality check up to global phase.
- #387, #444: Improved `Pattern.draw_graph` visualization: MBQC literature node shapes (squares for inputs, filled/empty circles for measured/output), solid gray edges, measurement order arrow, `show_measurements` and `show_legend` parameters.

### Fixed

Expand Down
10 changes: 5 additions & 5 deletions examples/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
pattern = circuit.transpile().pattern
# note that this visualization is not always consistent with the correction set of pattern,
# since we find the correction sets with flow-finding algorithms.
pattern.draw_graph(flow_from_pattern=False, show_measurement_planes=True)
pattern.draw_graph(flow_from_pattern=False, show_measurements=True)

# %%
# next, show the gflow:
pattern.remove_input_nodes()
pattern.perform_pauli_measurements()
pattern.draw_graph(flow_from_pattern=False, show_measurement_planes=True, node_distance=(1, 0.6))
pattern.draw_graph(flow_from_pattern=False, show_measurements=True, node_distance=(1, 0.6))


# %%
Expand All @@ -49,7 +49,7 @@
#

# node_distance argument specifies the scale of the node arrangement in x and y directions.
pattern.draw_graph(flow_from_pattern=True, show_measurement_planes=True, node_distance=(0.7, 0.6))
pattern.draw_graph(flow_from_pattern=True, show_measurements=True, node_distance=(0.7, 0.6))

# %%
# Instead of the measurement planes, we can show the local Clifford of the resource graph.
Expand All @@ -75,7 +75,7 @@
measurements = {node: Measurement.XY(0) for node in graph.nodes() if node not in outputs}
og = OpenGraph(graph, inputs, outputs, measurements)
vis = GraphVisualizer(og)
vis.visualize(show_measurement_planes=True)
vis.visualize(show_measurements=True)

# %%

Expand All @@ -91,6 +91,6 @@
}
og = OpenGraph(graph, inputs, outputs, measurements)
vis = GraphVisualizer(og)
vis.visualize(show_measurement_planes=True)
vis.visualize(show_measurements=True)

# %%
20 changes: 14 additions & 6 deletions graphix/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,24 +1437,30 @@ def draw_graph(
flow_from_pattern: bool = True,
show_pauli_measurement: bool = True,
show_local_clifford: bool = False,
show_measurement_planes: bool = False,
show_measurements: bool = False,
show_legend: bool = False,
show_loop: bool = True,
node_distance: tuple[float, float] = (1, 1),
figsize: tuple[int, int] | None = None,
filename: Path | None = None,
) -> None:
"""Visualize the underlying graph of the pattern with flow or gflow structure.

Nodes are drawn following MBQC literature conventions: inputs as squares,
measured nodes as filled circles, and outputs as empty circles.

Parameters
----------
flow_from_pattern : bool
If True, the command sequence of the pattern is used to derive flow or gflow structure. If False, only the underlying graph is used.
show_pauli_measurement : bool
If True, the nodes with Pauli measurement angles are colored light blue.
If True, Pauli-measured nodes are filled with blue instead of black.
show_local_clifford : bool
If True, indexes of the local Clifford operator are displayed adjacent to the nodes.
show_measurement_planes : bool
If True, measurement planes are displayed adjacent to the nodes.
show_measurements : bool
If True, measurement labels are displayed adjacent to the nodes.
show_legend : bool
If True, a legend is displayed indicating node types and edge meanings.
show_loop : bool
whether or not to show loops for graphs with gflow. defaulted to True.
node_distance : tuple
Expand All @@ -1475,7 +1481,8 @@ def draw_graph(
pattern=self.copy(),
show_pauli_measurement=show_pauli_measurement,
show_local_clifford=show_local_clifford,
show_measurement_planes=show_measurement_planes,
show_measurements=show_measurements,
show_legend=show_legend,
show_loop=show_loop,
node_distance=node_distance,
figsize=figsize,
Expand All @@ -1485,7 +1492,8 @@ def draw_graph(
vis.visualize(
show_pauli_measurement=show_pauli_measurement,
show_local_clifford=show_local_clifford,
show_measurement_planes=show_measurement_planes,
show_measurements=show_measurements,
show_legend=show_legend,
show_loop=show_loop,
node_distance=node_distance,
figsize=figsize,
Expand Down
Loading