Skip to content

Transpiler from MBQC+LC into pure MBQC#515

Open
thierry-martinez wants to merge 15 commits into
TeamGraphix:masterfrom
thierry-martinez:transpiling-local-cliffords
Open

Transpiler from MBQC+LC into pure MBQC#515
thierry-martinez wants to merge 15 commits into
TeamGraphix:masterfrom
thierry-martinez:transpiling-local-cliffords

Conversation

@thierry-martinez
Copy link
Copy Markdown
Collaborator

@thierry-martinez thierry-martinez commented May 26, 2026

This commit implements:

  • Clifford.to_opengraph: returns an equivalent MBQC pattern (i.e., without local Clifford corrections) for a given single-qubit Clifford gate.

  • remove_local_clifford_commands: transpiles an MBQC+LC pattern into an equivalent pure MBQC pattern by eliminating all local-Clifford commands.

  • Pattern.reindex and Command.reindex: implements the renumbering step of pattern composition.

This commit implements:

- `Clifford.to_pattern`: returns an equivalent MBQC pattern (i.e.,
  without local Clifford corrections) for a given single-qubit Clifford
  gate.

- `remove_local_clifford_commands`: transpiles an MBQC+LC pattern into
  an equivalent pure MBQC pattern by eliminating all local-Clifford
  commands.

- `Pattern.reindex` and `Command.reindex`: implements the renumbering
  step of pattern composition.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.03%. Comparing base (fcdb8f4) to head (4da58c8).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #515      +/-   ##
==========================================
+ Coverage   88.85%   89.03%   +0.17%     
==========================================
  Files          49       49              
  Lines        7135     7241     +106     
==========================================
+ Hits         6340     6447     +107     
+ Misses        795      794       -1     

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

Copy link
Copy Markdown
Contributor

@matulni matulni left a comment

Choose a reason for hiding this comment

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

Thanks! I made some comments

Comment thread graphix/command.py Outdated
Comment thread graphix/optimization.py
Comment thread graphix/optimization.py
Comment thread graphix/optimization.py Outdated
Comment thread graphix/optimization.py
Comment thread graphix/optimization.py
Comment thread tests/test_optimization.py
Comment thread graphix/_db.py
…tion (fix TeamGraphix#519)

This commit makes `Pattern.reindex` accept mappings in addition to
functions. When no mapping is supplied, nodes are re-indexed
consecutively, starting at 0, implementing the suggestion of TeamGraphix#519.

Re-indexing is now performed in place by default, with an optional
`copy` parameter to return a fresh pattern instead.
Copy link
Copy Markdown
Contributor

@matulni matulni left a comment

Choose a reason for hiding this comment

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

Thanks LGTM! I made some small comments only

Comment thread graphix/pattern.py Outdated
Comment on lines +192 to +194
if f is None:
# Suggested in issue #519
f = {node: i for i, node in enumerate(sorted(self.extract_nodes()))}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have two suggestions:

  • Allow to pass a positive integer, so that fresh node labels are generated starting from the passed integer instead of always 0. We just have to accept an int for f, and do node: i + f in the dict comprehension.
  • Decouple the remapping of nodes (managed by f) from assigning sequential labels to nodes starting from a given integer. The goal would be to combine both possibilities: remap some nodes and assign fresh sequential labels to other nodes starting from a given integer. In other words, support non-injective f. This is tricky if f is a Callable, so maybe it's outside the scope of this PR.

The motivation for both suggestions if to offload the work done by compose to this new method.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This goes a bit beyond the scope of this PR, but it fits something I wanted to implement, so I've proposed a change. I hope you'll agree to review it in the context of this PR.

In commit f138a93 I introduced a new method Pattern.node_mapping that addresses your suggestions:

  • The method has an optional argument start that lets you choose the starting index for fresh nodes.
  • It also accepts an optional initial mapping, which fixes the new indices for a subset of nodes, and an optional preserves argument for nodes that should not be remapped, and an optional avoids argument for indices that should not be used for fresh nodes.

Providing this functionality in a separate method is useful because it gives users a convenient way to obtain the actual mapping as well as the re-indexed pattern. This feels more natural than returning a pair, which is what compose currently does.

Comment thread tests/test_db.py Outdated
Comment thread tests/test_command.py Outdated
thierry-martinez and others added 4 commits June 4, 2026 09:58
---------

Co-authored-by: matulni <m.uldemolins@gmail.com>
---------

Co-authored-by: matulni <m.uldemolins@gmail.com>
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