From 7e4c201773b554120aab7d0c2206c7343f214d90 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Wed, 10 Jun 2026 15:43:25 +0200 Subject: [PATCH 01/15] Fix #531: Allow empty graphs in check_well_formed --- graphix/flow/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/graphix/flow/core.py b/graphix/flow/core.py index fa674c3fd..6e48071b7 100644 --- a/graphix/flow/core.py +++ b/graphix/flow/core.py @@ -1378,13 +1378,20 @@ def _check_flow_general_properties(flow: PauliFlow[_AM_co]) -> None: - The nodes in the partial order are the nodes in the open graph. - The first layer of the partial order layers is :math:`O`, the output nodes of the open graph. This is guaranteed because open graphs without outputs do not have flow. """ + if len(flow.og.graph.nodes) == 0: + + return + + if not _check_correction_function_domain(flow.og, flow.correction_function): raise FlowGenericError(FlowGenericErrorReason.IncorrectCorrectionFunctionDomain) if not _check_correction_function_image(flow.og, flow.correction_function): raise FlowGenericError(FlowGenericErrorReason.IncorrectCorrectionFunctionImage) - if len(flow.partial_order_layers) == 0: + if len(flow.partial_order_layers) == 0 and len(flow.og.graph.nodes) > 0: + if not flow.og.graph: + return raise PartialOrderError(PartialOrderErrorReason.Empty) first_layer = flow.partial_order_layers[0] From c3967010b465247868d0449985074bddf68d94a0 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 10:21:43 +0200 Subject: [PATCH 02/15] Fix formatting with ruff --- graphix/flow/core.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/graphix/flow/core.py b/graphix/flow/core.py index 6e48071b7..20c90207b 100644 --- a/graphix/flow/core.py +++ b/graphix/flow/core.py @@ -1379,10 +1379,8 @@ def _check_flow_general_properties(flow: PauliFlow[_AM_co]) -> None: - The first layer of the partial order layers is :math:`O`, the output nodes of the open graph. This is guaranteed because open graphs without outputs do not have flow. """ if len(flow.og.graph.nodes) == 0: - return - if not _check_correction_function_domain(flow.og, flow.correction_function): raise FlowGenericError(FlowGenericErrorReason.IncorrectCorrectionFunctionDomain) From 03f214a6a692d10c66f8e51cb4d24dfdc4292b6b Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 10:46:24 +0200 Subject: [PATCH 03/15] Add test for issue #531: empty graph well-formedness --- tests/test_empty_graph_fix.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/test_empty_graph_fix.py diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py new file mode 100644 index 000000000..0220fb5ec --- /dev/null +++ b/tests/test_empty_graph_fix.py @@ -0,0 +1,21 @@ +""" +Test for issue #531: Allow empty graphs in check_well_formed +""" +import networkx as nx +from graphix.opengraph import OpenGraph + + +def test_empty_graph_well_formed(): + """ + Test that empty graphs pass the well-formedness check. + This is a regression test for issue #531. + """ + og = OpenGraph( + graph=nx.Graph(), + input_nodes=[], + output_nodes=[], + measurements={} + ) + pf = og.extract_causal_flow() + pf.check_well_formed() + assert True From adfbbc580fa1248226e5223780c58f0eaa6104c5 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 15:42:36 +0200 Subject: [PATCH 04/15] fix: format test_empty_graph_fix.py --- tests/test_empty_graph_fix.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 0220fb5ec..956ef6170 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -1,6 +1,7 @@ """ Test for issue #531: Allow empty graphs in check_well_formed """ + import networkx as nx from graphix.opengraph import OpenGraph @@ -10,12 +11,7 @@ def test_empty_graph_well_formed(): Test that empty graphs pass the well-formedness check. This is a regression test for issue #531. """ - og = OpenGraph( - graph=nx.Graph(), - input_nodes=[], - output_nodes=[], - measurements={} - ) + og = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) pf = og.extract_causal_flow() pf.check_well_formed() assert True From 831dce7b794efb17e19a7f42cdb15d1fe16e8a22 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 16:07:46 +0200 Subject: [PATCH 05/15] fix: add type annotations to test_empty_graph_fix.py --- tests/test_empty_graph_fix.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 956ef6170..a3127b327 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -6,12 +6,12 @@ from graphix.opengraph import OpenGraph -def test_empty_graph_well_formed(): +def test_empty_graph_well_formed() -> None: """ Test that empty graphs pass the well-formedness check. This is a regression test for issue #531. """ - og = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) + og: OpenGraph = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) pf = og.extract_causal_flow() pf.check_well_formed() assert True From 9de31eafd60c484f5edc6aad4d2f0963f77b4498 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 20:30:34 +0200 Subject: [PATCH 06/15] fix: resolve all lint errors in test_empty_graph_fix.py --- tests/test_empty_graph_fix.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index a3127b327..f76a1b084 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -1,14 +1,13 @@ -""" -Test for issue #531: Allow empty graphs in check_well_formed -""" +from __future__ import annotations import networkx as nx + from graphix.opengraph import OpenGraph def test_empty_graph_well_formed() -> None: - """ - Test that empty graphs pass the well-formedness check. + """Test that empty graphs pass the well-formedness check. + This is a regression test for issue #531. """ og: OpenGraph = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) From 8a78182af971166e689e2f4b515146fc9868e3f8 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 22:58:29 +0200 Subject: [PATCH 07/15] fix: specify generic type argument Any for OpenGraph to pass mypy --- tests/test_empty_graph_fix.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index f76a1b084..570be4817 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -1,3 +1,4 @@ +from typing import Any from __future__ import annotations import networkx as nx @@ -10,7 +11,7 @@ def test_empty_graph_well_formed() -> None: This is a regression test for issue #531. """ - og: OpenGraph = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) + og: OpenGraph[Any] = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) pf = og.extract_causal_flow() pf.check_well_formed() assert True From a89d19b52f6bdfc1385955535adbcb0013fc36f7 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 23:09:44 +0200 Subject: [PATCH 08/15] fix: resolve ruff linting, docstring and import sorting requirements --- tests/test_empty_graph_fix.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 570be4817..04987ee7a 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -1,16 +1,15 @@ -from typing import Any +"""Test empty graph fix.""" from __future__ import annotations +from typing import Any + import networkx as nx from graphix.opengraph import OpenGraph def test_empty_graph_well_formed() -> None: - """Test that empty graphs pass the well-formedness check. - This is a regression test for issue #531. - """ og: OpenGraph[Any] = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) pf = og.extract_causal_flow() pf.check_well_formed() From 065a20ec3f93317d1fa56deff994d7f9b93634e5 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 23:16:53 +0200 Subject: [PATCH 09/15] fix: comply with ruff docstring and import sorting rules --- tests/test_empty_graph_fix.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 04987ee7a..602a6685e 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -1,4 +1,5 @@ """Test empty graph fix.""" + from __future__ import annotations from typing import Any From e90509a14ed031d0f2a7df64922596d9bf3e0fd5 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Thu, 11 Jun 2026 23:59:25 +0200 Subject: [PATCH 10/15] fix: generic type hint for opengraph strictly applied --- tests/test_empty_graph_fix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 602a6685e..59ec02fb5 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -6,7 +6,7 @@ import networkx as nx -from graphix.opengraph import OpenGraph +from graphix.opengraph import OpenGraph[Any] def test_empty_graph_well_formed() -> None: From b4f8fc7293131f5501951de741317ad5a9b3da57 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Fri, 12 Jun 2026 00:13:05 +0200 Subject: [PATCH 11/15] fix: correct opengraph import syntax error --- tests/test_empty_graph_fix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 59ec02fb5..602a6685e 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -6,7 +6,7 @@ import networkx as nx -from graphix.opengraph import OpenGraph[Any] +from graphix.opengraph import OpenGraph def test_empty_graph_well_formed() -> None: From df9cd74a4e8abe6e81c8b870aabeaeff5396d58a Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Fri, 12 Jun 2026 09:24:29 +0200 Subject: [PATCH 12/15] chore: trigger CI rebuild From eb341fddd83a73b33880690b3dd5cdeb1c19b264 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Fri, 12 Jun 2026 09:49:59 +0200 Subject: [PATCH 13/15] fix: add type argument to OpenGraph --- tests/test_empty_graph_fix.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_empty_graph_fix.py b/tests/test_empty_graph_fix.py index 602a6685e..e56f43fc4 100644 --- a/tests/test_empty_graph_fix.py +++ b/tests/test_empty_graph_fix.py @@ -1,17 +1,21 @@ -"""Test empty graph fix.""" - from __future__ import annotations -from typing import Any +from typing import TYPE_CHECKING import networkx as nx from graphix.opengraph import OpenGraph +if TYPE_CHECKING: + from graphix.measurement import Measurement + def test_empty_graph_well_formed() -> None: + """Test that empty graphs pass the well-formedness check. - og: OpenGraph[Any] = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) + This is a regression test for issue #531. + """ + og: OpenGraph[Measurement] = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) pf = og.extract_causal_flow() pf.check_well_formed() assert True From a86e53917d852fc47cf0d9e76fb2f54317285f69 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Sat, 13 Jun 2026 21:00:48 +0200 Subject: [PATCH 14/15] Fix #531: Allow empty graphs in check_well_formed + add test --- tests/test_issue_531.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/test_issue_531.py diff --git a/tests/test_issue_531.py b/tests/test_issue_531.py new file mode 100644 index 000000000..fe90cbc31 --- /dev/null +++ b/tests/test_issue_531.py @@ -0,0 +1,12 @@ + +import networkx as nx +from graphix.opengraph import OpenGraph + +def test_empty_graph(): + og = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) + pf = og.extract_causal_flow() + pf.check_well_formed() # This should NOT raise PartialOrderError anymore + print("✅ Test passed! Empty graph is now well-formed.") + +if __name__ == "__main__": + test_empty_graph() From a9533925978cf105a7debc9de44a234c07e83883 Mon Sep 17 00:00:00 2001 From: Araz Mehdi Date: Mon, 15 Jun 2026 03:35:17 +0200 Subject: [PATCH 15/15] fix: add missing future annotations and sort imports for #531 --- tests/test_issue_531.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_issue_531.py b/tests/test_issue_531.py index fe90cbc31..2755cca54 100644 --- a/tests/test_issue_531.py +++ b/tests/test_issue_531.py @@ -1,7 +1,10 @@ +from __future__ import annotations import networkx as nx + from graphix.opengraph import OpenGraph + def test_empty_graph(): og = OpenGraph(graph=nx.Graph(), input_nodes=[], output_nodes=[], measurements={}) pf = og.extract_causal_flow()