Skip to content

Conversation

@matulni
Copy link
Contributor

@matulni matulni commented Dec 9, 2025

This PR introduces some tooling to extract a causal flow and a generalised flow from a pattern without running the extraction algorithms on the underlying open graph.

It directly addresses #306 and additionally solves #367.

Description of changes

  • We introduce the following methods:

    • graphix.optimization.StandardizedPattern.extract_partial_order_layers

      • Constructs a partial order layering from the dependency domains of $M$, $X$ and $Z$ commands. The layering follows the convention of the partial_order_layers attribute of :class: PauliFlow and :class: XZCorrections objects :
        • Nodes in the same layer can be measured simultaneously.
        • Nodes in layer i must be measured after nodes in layer i + 1.
        • All output nodes (if any) are in the first layer.
        • There cannot be any empty layers.
    • graphix.optimization.StandardizedPattern.extract_causal_flow

      • Attempts to extract a causal flow from a standardized pattern. The algorithm goes as follows:
        • The correction function is constructed by reading out $X$ and $M$ commands. In particular, a command $X_j^i$ implies $c(i) = j$ in the correction function. Analogously, a command $M_j^{s=i}$ also contributes $c(i) = j$ to the correction function.
        • A partial order of the pattern is extracted with graphix.optimization.StandardizedPattern.extract_partial_order_layers.
        • A CausalFlow is constructed combining these you objects.
        • The wellformedness of the CausalFlow object is checked.
    • graphix.optimization.StandardizedPattern.extract_gflow

      • Attempts to extract a gflow from a standardized pattern. The algorithm is similar to that of the causal flow, but in addition we allow $c(i) = i$ if the node $i$ is measured in planes $XZ$ or $YZ$.
    • graphix.optimization.StandardizedPattern.extract_opengraph

      • Extracts an open graph from a standardized pattern.
    • graphix.pattern.Pattern.extract_partial_order_layers, graphix.pattern.Pattern.extract_causal_flow and graphix.pattern.Pattern.extract_gflow

      • Wrappers which standardize the pattern and call the corresponding extraction routine.
  • We introduce the a new module graphix.flow._partial_order.py with the function :func: compute_topological_generations.

    • This function was used in the algebraic Pauli-flow finding routine and is now used to extract the partial order from the pattern.

    • In the future, we should drop the dependency of graphix.flow.core on nx.DiGraph objects and replace :func: graphix.flow.core._dag_to_partial_order_layers with this function.

  • Dependencies of the module graphix.visualization.py on graphix.gflow.py are removed where possible, but the new flow API is not fully exploited. This is out of the scope of this PR.

@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 98.73418% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.91%. Comparing base (feb0a07) to head (b177d34).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
graphix/optimization.py 97.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #393      +/-   ##
==========================================
- Coverage   86.10%   84.91%   -1.19%     
==========================================
  Files          45       46       +1     
  Lines        6576     6637      +61     
==========================================
- Hits         5662     5636      -26     
- Misses        914     1001      +87     

☔ View full report in Codecov by Sentry.
📢 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
Copy link
Contributor Author

matulni commented Dec 10, 2025

CI is failing on the visualization example with Pauli presimulation. Should pass when #392 is merged.

meas_order = None
if not self._pauli_preprocessed:
meas_order = self.get_measurement_order_from_flow()
cf = self.extract_opengraph().find_causal_flow()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this change preserves bug #157, but I think fixing it would be outside the scope of this PR. Ideally, we would like cf = self.try_extract_causal_flow(), but this may cause some regressions: minimize_space will be correct in the sense that it will preserve runnability, but in some examples the minimized pattern may use more space than the current heuristics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree, thanks for the remark.

@matulni
Copy link
Contributor Author

matulni commented Jan 5, 2026

Thanks a lot for the detailed review, @thierry-martinez. I applied all suggestions in 596ec4b and 975f7aa. I think it's ready for another round!

This commit updates the baseline while TeamGraphix#392 is not merged.
Copy link
Collaborator

@thierry-martinez thierry-martinez left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@mgarnier59 mgarnier59 left a comment

Choose a reason for hiding this comment

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

Looks good, nothing to add. Thanks!

@matulni matulni merged commit b055431 into TeamGraphix:master Jan 6, 2026
21 checks passed
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