Skip to content

Fix mutable_pauli_string.inplace_after() and inplace_before() #7507

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

Merged
merged 6 commits into from
Aug 5, 2025

Conversation

babacry
Copy link
Collaborator

@babacry babacry commented Jul 18, 2025

Similar to the fix for PauliString.after() #7065, this is the fix for MutablePauliString.

Also deleted the culprit _decompose_into_cliffords helper function that was used by PauliString.after() and MutablePauliString.inplace_after().

Issue: #6946.

@github-actions github-actions bot added the size: M 50< lines changed <250 label Jul 18, 2025
Copy link

codecov bot commented Jul 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.50%. Comparing base (17c4e95) to head (2e748fb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7507      +/-   ##
==========================================
- Coverage   97.54%   97.50%   -0.05%     
==========================================
  Files        1101     1101              
  Lines       99430    99411      -19     
==========================================
- Hits        96993    96928      -65     
- Misses       2437     2483      +46     

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@babacry babacry marked this pull request as ready for review July 18, 2025 21:40
@babacry babacry requested review from vtomole and a team as code owners July 18, 2025 21:40
@babacry babacry requested a review from viathor July 18, 2025 21:40
@babacry
Copy link
Collaborator Author

babacry commented Jul 18, 2025

Hey Nour @NoureldinYosri , could you help take a look at this PR? This is the last pr in fixing #6946.

@babacry babacry requested a review from NoureldinYosri July 18, 2025 21:48
@NoureldinYosri NoureldinYosri self-assigned this Jul 18, 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.

overall looks good ... but you can use a simpler logic to construct the conjugated object

flattened_ops = list(op_tree.flatten_to_ops(ops))

for op in flattened_ops[::-1]:
conjugated: cirq.DensePauliString = dense_pauli_string.DensePauliString(
Copy link
Collaborator

@NoureldinYosri NoureldinYosri Jul 18, 2025

Choose a reason for hiding this comment

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

maybe conjugates = self.dense(self.qubits) * dense_pauli_string.DensePauliString('I'*len(self.qubits)) should do the trick? ... no need for the logic below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea! updated.

@pavoljuhas pavoljuhas added the priority/after-1.6 Leave for after the Cirq 1.6 release label Jul 22, 2025
@babacry babacry requested a review from NoureldinYosri July 22, 2025 23:21
@babacry
Copy link
Collaborator Author

babacry commented Jul 22, 2025

Thanks @NoureldinYosri for the review! Comments applied, could you help take another look?

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.

overall LGTM%style

pauli = self.get(cast(TKey, q), None)
match pauli:
case pauli_gates.X:
conjugated *= tableau.destabilizers()[qid]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you wrote this logic before, no? if so can you do some refactoring

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, some logic can be refactored out, done.

tableau = gate_in_clifford.clifford_tableau.inverse()

for qid, q in enumerate(op.qubits):
pauli = self.get(cast(TKey, q), None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is this cast needed here and below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mypy complained: error: Argument 1 to "pop" of "dict" has incompatible type "Qid"; expected "TKey"

@babacry babacry force-pushed the inplace_after branch 3 times, most recently from b44fb0c to c3a6ead Compare July 31, 2025 22:41
@babacry babacry requested a review from NoureldinYosri July 31, 2025 22:50
@babacry
Copy link
Collaborator Author

babacry commented Jul 31, 2025

Hey Nour @NoureldinYosri , done addressing the comments, thanks for another round of iteration, could you help take another look? thanks!

@@ -903,7 +902,7 @@ def conjugated_by(self, clifford: cirq.OP_TREE) -> PauliString:
The product-of-Paulis $P$ conjugated by the Clifford operation $C$ is

$$
C^\dagger P C
C^dagger P C
Copy link
Collaborator

Choose a reason for hiding this comment

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

why this change? this will break the latex

Suggested change
C^dagger P C
C^\dagger P C

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, it was accidentally deleted. Fixed.

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.

LGTM%nit

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.

thanks @babacry

@NoureldinYosri NoureldinYosri added this pull request to the merge queue Aug 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 5, 2025
@babacry babacry added this pull request to the merge queue Aug 5, 2025
Merged via the queue into quantumlib:main with commit 574595f Aug 5, 2025
35 checks passed
@babacry babacry deleted the inplace_after branch August 5, 2025 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/after-1.6 Leave for after the Cirq 1.6 release size: M 50< lines changed <250
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants