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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Empty outputs layer removed from flow's partial order.
- Flow well-formedness check does not trigger false negative for flows on open graphs without outputs.

- #535, #559: Added a padding beneath the measurement-order arrow when visualizing open graphs with layers, keeping both the arrow and its label inside the visualization box.

### Changed

- #452: Use `uv` for dependency management
Expand Down
7 changes: 6 additions & 1 deletion graphix/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,13 @@ def _draw_layers(self, plot_lims: PlotLims) -> PlotLims:
)

# Update plot_lims to take into account label
trans = base + offset
padding = mtransforms.ScaledTranslation(0, -8 / 72, fig.dpi_scale_trans)

trans = base + offset + padding
_, ydisp = trans.transform((0, plot_lims.ymin))

# inverted transformation depends on the current plot limits
self._set_plot_lims(plot_lims)
return replace(plot_lims, ymin=base.inverted().transform((0, ydisp))[1])

def _draw_measurements_labels(self) -> None:
Expand Down
Binary file modified tests/baseline/test_causal_flow_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/baseline/test_draw_graph_linear_graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_draw_graph_reference_False.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_draw_graph_reference_True.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_gflow_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_og_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_pauli_flow_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/baseline/test_xzcorr_draw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import networkx as nx
import pytest

from graphix import Circuit, Pattern, command
from graphix import Circuit, Pattern, Plane, command
from graphix.fundamentals import ANGLE_PI
from graphix.measurements import Measurement
from graphix.opengraph import OpenGraph, OpenGraphError
Expand Down Expand Up @@ -265,3 +265,18 @@ def test_draw_graph_reference(flow_and_not_pauli_presimulate: bool) -> Figure:
flow_from_pattern=flow_and_not_pauli_presimulate, node_distance=(1, 1), measurement_labels=True, legend=False
)
return plt.gcf()


@pytest.mark.usefixtures("mock_plot")
@pytest.mark.mpl_image_compare
def test_draw_graph_linear_graph() -> Figure:
# See https://github.com/TeamGraphix/graphix/issues/535
og = OpenGraph(
graph=nx.Graph([(0, 1), (1, 2), (2, 3)]),
input_nodes=[0],
output_nodes=[3],
measurements=dict.fromkeys(range(3), Plane.XY),
)
flow = og.extract_causal_flow()
flow.draw(legend=False)
return plt.gcf()
Loading