Update merging of Conditional block in greedy_pauli_optimisation - #2014
Merged
Merged
Conversation
yao-cqc
marked this pull request as ready for review
September 2, 2025 15:42
yao-cqc
approved these changes
Sep 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The circuit:
Is incorrectly optimised by
greedy_pauli_optimisation. This is because the conditionalRygate is considered commuting with theRxgate, and then the conditionalCZgate is merged into the same "block" as theRygate. This block is incorrectly considered as commuting with theRxgate, and later at construction the result is that theCZgate is commuted ahead of theRxgate, producing an incorrect circuit.The fix I've added is to only allowing commuting of non-conditional gates forward. This is because we can only incorrectly produce non-commuting blocks by merging gates into a block, which only happens with conditional cases.
This leads to a test regression in this circuit:
where the Rotation gates are no longer correctly cancelled (but everything else is).
My opinion is that safe forward-merging of conditional blocks will take serious code changes, and that cases where identical Pauli exponentials are not merged through conditional circuits are a) unlikely to be common in circuits, and b) the Pauli exponentials will still be "close" in the PauliGraph, meaning regularly they may just appear as adjacent rotations in a final circuit that can be compiled out using a pass like
RemoveRedundancies.Related issues
Please mention any github issues addressed by this PR.
Checklist