Skip to content

Add methods XZCorrections to CausalFlow and GFlow#505

Open
matulni wants to merge 8 commits into
TeamGraphix:masterfrom
matulni:corr_to_flow
Open

Add methods XZCorrections to CausalFlow and GFlow#505
matulni wants to merge 8 commits into
TeamGraphix:masterfrom
matulni:corr_to_flow

Conversation

@matulni
Copy link
Copy Markdown
Contributor

@matulni matulni commented May 12, 2026

This commit introduces two new methods XZCorrections.to_causal_flow and XZCorrections.to_gflow which subsume StandardizedPattern.extract_causal_flow and StandardizedPattern.extract_gflow. The latter are removed.

Methods Pattern.extract_causal_flow and Pattern.extract_gflow now proceed by extracting the xz-corrections and performing the conversion to flow of these objects.

The flow extraction routines becomes significantly clearer, and the API is now closer to MBQC theory. The performance regression is negligible: on a open graph with 5188 nodes (extracted from a random circuit), pattern to gflow conversion takes 0.029s after the new commit vs 0.027s before. For comparison, extracting the gflow on the underlying open graph with the $O(N^3)$ algorithm takes 1.731s

Additionally, to comply with mypy new methods XZCorrections.to_bloch and XZCorrections.downcast_bloch are added.

These changes help making issue #432 more concrete.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 90.90909% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.58%. Comparing base (7c88182) to head (fdd93e9).

Files with missing lines Patch % Lines
graphix/pattern.py 81.81% 2 Missing ⚠️
graphix/flow/core.py 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #505      +/-   ##
==========================================
- Coverage   89.65%   89.58%   -0.07%     
==========================================
  Files          48       48              
  Lines        7015     7001      -14     
==========================================
- Hits         6289     6272      -17     
- Misses        726      729       +3     

☔ 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.

Copy link
Copy Markdown
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! Just one minor remark.

Comment thread graphix/pattern.py Outdated
Comment on lines +1509 to +1514
xz_corrections = self.extract_xzcorrections()
try:
flow = pattern_std.extract_causal_flow()
except FlowError:
flow = xz_corrections.downcast_bloch().to_causal_flow()
except (FlowError, TypeError):
try:
flow = pattern_std.extract_gflow()
flow = xz_corrections.downcast_bloch().to_gflow()
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.

downcast_bloch could be called just one time.

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.

Thanks for the quick review!
Suggestion implemented in 0ddcb03

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.

2 participants