-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Hey Nour @NoureldinYosri , could you help take a look at this PR? This is the last pr in fixing #6946. |
There was a problem hiding this 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
cirq-core/cirq/ops/pauli_string.py
Outdated
flattened_ops = list(op_tree.flatten_to_ops(ops)) | ||
|
||
for op in flattened_ops[::-1]: | ||
conjugated: cirq.DensePauliString = dense_pauli_string.DensePauliString( |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea! updated.
Thanks @NoureldinYosri for the review! Comments applied, could you help take another look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall LGTM%style
cirq-core/cirq/ops/pauli_string.py
Outdated
pauli = self.get(cast(TKey, q), None) | ||
match pauli: | ||
case pauli_gates.X: | ||
conjugated *= tableau.destabilizers()[qid] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
cirq-core/cirq/ops/pauli_string.py
Outdated
tableau = gate_in_clifford.clifford_tableau.inverse() | ||
|
||
for qid, q in enumerate(op.qubits): | ||
pauli = self.get(cast(TKey, q), None) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"
b44fb0c
to
c3a6ead
Compare
Hey Nour @NoureldinYosri , done addressing the comments, thanks for another round of iteration, could you help take another look? thanks! |
cirq-core/cirq/ops/pauli_string.py
Outdated
@@ -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 |
There was a problem hiding this comment.
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
C^dagger P C | |
C^\dagger P C |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM%nit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @babacry
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.