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
7 changes: 6 additions & 1 deletion graphix/flow/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,13 +1378,18 @@ 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]
Expand Down
21 changes: 21 additions & 0 deletions tests/test_empty_graph_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from __future__ import annotations

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.

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
15 changes: 15 additions & 0 deletions tests/test_issue_531.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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()
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()
Loading