Transpiler from MBQC+LC into pure MBQC#515
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
matulni
left a comment
There was a problem hiding this comment.
Thanks! I made some comments
…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.
matulni
left a comment
There was a problem hiding this comment.
Thanks LGTM! I made some small comments only
| if f is None: | ||
| # Suggested in issue #519 | ||
| f = {node: i for i, node in enumerate(sorted(self.extract_nodes()))} |
There was a problem hiding this comment.
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
intforf, and donode: i + fin 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-injectivef. This is tricky iffis aCallable, 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.
There was a problem hiding this comment.
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
startthat 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 optionalpreservesargument for nodes that should not be remapped, and an optionalavoidsargument 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.
--------- Co-authored-by: matulni <m.uldemolins@gmail.com>
--------- Co-authored-by: matulni <m.uldemolins@gmail.com>
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.reindexandCommand.reindex: implements the renumbering step of pattern composition.