Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conjugated_by of PauliString. #7065

Merged
merged 3 commits into from
Feb 27, 2025
Merged

Conversation

babacry
Copy link
Collaborator

@babacry babacry commented Feb 13, 2025

Rewrite PauliString.conjugated_by.

Context: previous conjugated_by relies on decompose_into_cliffords which crashes in for some cliffords: #6946.

Followup: note pass_operations_over() and inplace_after() still rely on _decompose_into_cliffords_ and _pass_operation_over_, I will clean them up in the followup PRs. (tried to clean them up in the same pr, but too many nit updates are needed in both the class itself and the tests)

@CirqBot CirqBot added the size: M 50< lines changed <250 label Feb 13, 2025
def _has_stabilizer_effect_(self) -> Optional[bool]:
if self._is_parameterized_():
return None
return self.exponent % 1 == 0
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ISwapPow gate need to have _has_stabilizer_effect_ method just like SwapPowGate, fix it here, otherwise, unit tests would fail in pauli_string_test.py.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.15%. Comparing base (16231fc) to head (9f5e35d).
Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7065      +/-   ##
==========================================
- Coverage   98.17%   98.15%   -0.02%     
==========================================
  Files        1089     1089              
  Lines       95177    95253      +76     
==========================================
+ Hits        93438    93494      +56     
- Misses       1739     1759      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@babacry babacry force-pushed the conj branch 5 times, most recently from 77f1722 to a39e761 Compare February 21, 2025 08:20
@babacry babacry marked this pull request as ready for review February 21, 2025 08:37
@babacry babacry requested review from vtomole and a team as code owners February 21, 2025 08:37
@babacry babacry self-assigned this Feb 24, 2025
@NoureldinYosri NoureldinYosri self-assigned this Feb 26, 2025
Copy link
Collaborator

@NoureldinYosri NoureldinYosri left a comment

Choose a reason for hiding this comment

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

@babacry overall looks good%nits

@@ -377,7 +377,10 @@ def __init__(self, *, _clifford_tableau: qis.CliffordTableau) -> None:
# ZI [ 0 0 | 1 0 | 1 ]
# IZ [ 1 0 | 1 1 | 0 ]
# Take the third row as example: this means the ZI gate after the this gate,
# more precisely the conjugate transformation of ZI by this gate, becomes -ZI.
# more precisely the conjugate transformation of ZI by this gate, becomes -ZI:
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this needed?

Copy link
Collaborator Author

@babacry babacry Feb 26, 2025

Choose a reason for hiding this comment

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

Conjugation definitions are not uniform in Cirq, it turns out the conjugation definition here is opposite with the conjugation definition in PauliString.conjugated_by.

Here, in CliffordGate, in terms of matrix conjugation it is $C P C^{\dagger}$, in circuit, it is ---C^{-1}----P-----C.

In PauliString, the definition in terms of matrix conjugation is $C^{\dagger} P C$, in circuit, it is -----C----P------C^{-1}.

Thus I added comments here to clarify the difference.

@babacry
Copy link
Collaborator Author

babacry commented Feb 27, 2025

Thanks Nour for the inputs! Updated. PTAL.

@NoureldinYosri NoureldinYosri added this pull request to the merge queue Feb 27, 2025
Merged via the queue into quantumlib:main with commit 22ed25e Feb 27, 2025
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants