Skip to content

Support for extended causal flows - #651

Open
matulni wants to merge 22 commits into
TeamGraphix:masterfrom
matulni:ecf
Open

matulni wants to merge 22 commits into
TeamGraphix:masterfrom
matulni:ecf

Conversation

@matulni

@matulni matulni commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

This PR addresses #613 and introduces support for extended causal flows as defined in arXiv:2608.13035.
The new class ExtendedCausalFlow inherits from GFlow and is the parent of CausalFlow. It comes with the following tooling:

  • Extraction algorithm from open graphs
  • Conversion from XZCorrections
  • Conversion to XZCorrections (via inheritance)
  • Wrapper method to derive an extended causal flow compatible from a pattern.
  • Well-formedness checks

Space-minimization heuristic causal_flow is replaced by extended_causal_flow which is more general, optimal, and equally costly.
Further, because extended causal flows are more general than causal flows, and the extraction algorithm has the same complexity in both cases, Pattern.draw and OpenGraph.to_pattern are updated to look for an extended causal flow instead.

thierry-martinez and others added 13 commits November 12, 2026 11:58
…eck_well_formed

- Add numpy-style docstrings to find_cflow, find_ecflow and _find_flow, and
  make _find_flow copy yz_candidates instead of mutating the caller's set.
- Fix stale ExtendedCausalFlow/CausalFlow docstrings: ExtendedCausalFlow
  derives from GFlow and labels measurements by plane (no Pauli labelling),
  CausalFlow derives from ExtendedCausalFlow and no longer overrides
  to_xzcorrections. Restore a causal-flow-specific
  CausalFlow.check_well_formed docstring and document _check_xzplane and
  _check_yzplane.
- Fix return types (_AM_co -> _PM_co), add Raises sections, and update
  references in XZCorrections.to_extendedcausalflow,
  OpenGraph.to_extendedcausalflow(_or_none) and
  SpaceMinimizationHeuristics.extended_causal_flow.
- Add ExtendedCausalFlow cases to TestIncorrectFlows (XZPlane, YZ input,
  domain, C0, C1, CYZ, C2, C3, incomplete order) and a CausalFlow case on an
  open graph with YZ measurements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…imization

- Simplify the yz_candidates description in _find_flow.
- Explain why CausalFlow.check_well_formed is overridden.
- Test XZCorrections.to_extendedcausalflow on an open graph with a
  YZ-measured node (round trip through XZ-corrections).
- Test that the extended_causal_flow space minimization heuristic applies,
  is optimal and preserves semantics on a pattern without causal flow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Update extended causal flow docstrings and test ExtendedCausalFlow.check_well_formed

See merge request muldemol/graphix!2
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.11650% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.01%. Comparing base (2ea9bf3) to head (242467b).

Files with missing lines Patch % Lines
graphix/flow/exceptions.py 69.23% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #651      +/-   ##
==========================================
+ Coverage   89.98%   90.01%   +0.02%     
==========================================
  Files          49       49              
  Lines        8447     8499      +52     
==========================================
+ Hits         7601     7650      +49     
- Misses        846      849       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@matulni

matulni commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

Commits bb2fb2c, 6f8d4f8 and 726caf8 address meeting suggestions

@thierry-martinez thierry-martinez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for extracting this!

Comment thread graphix/flow/core.py Outdated
Comment on lines +1588 to +1597
Specific properties of causal flows:
- Correction sets have one element only (C0),
- :math:`i \sim c(i)` (C1),
- :math:`i \prec c(i)` (C2),
- :math:`\forall k \in N_G(c(i)) \setminus \{i\}, i \prec k` (C3),
where :math:`i \in O^c`, :math:`c` is the correction function and :math:`\prec` denotes the partial order.

Causal flows are defined on open graphs with XY measurements only.

See Definition 2 in Ref. [1].

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That involves a lot of duplication, even in the documentation, just to specialize the docstring. I would rather describe the specific properties of causal flows in the class docstring and remove the method override.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Commit 1efec45 refactors the dcostrings so that all flow definitions are in the class docstrings and check_well_formed methods are minimal. To ensure consistency, docstrings in other flow classes are modified.

Comment thread graphix/pattern.py
-----
See notes in :meth:`to_causalflow`.
"""
return self.to_xzcorrections().downcast_bloch().to_extendedcausalflow()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we cover this line in tests?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests in 89595b6

matulni and others added 6 commits November 19, 2026 11:47
- State the definition of each flow (Pauli flow, gflow, extended causal
  flow, causal flow) in the Notes section of its class docstring. The
  general properties shared by all flows are stated once, in PauliFlow,
  and referenced from the subclasses.
- Shorten check_well_formed and check_flow_properties docstrings to say
  that they check flow validity and to refer to the class docstring for
  the definition.
- Remove CausalFlow.check_well_formed, which was overridden only for its
  docstring.
- Point the Focused* class docstrings to the flow and focus definitions,
  fix broken :meth: roles and the reason documented in
  CausalFlow._check_yzplane (YZPlane).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants