Repository navigation
Add a PauliRotationGate - #8424
Acciaccatura wants to merge 18 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8424 +/- ##
==========================================
- Coverage 99.58% 99.58% -0.01%
==========================================
Files 1137 1139 +2
Lines 105261 105448 +187
==========================================
+ Hits 104826 105012 +186
- Misses 435 436 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
PauliRotation operationPauliRotationGate and PauliRotation operation
|
Hello, thanks for looking into this! A note on the design before I do a full review:
|
|
@arettig hey - thanks for the notes!
I think you're right: the new operation does not add any new value that |
arettig
left a comment
There was a problem hiding this comment.
Looks great, thank you! See below for some suggested changes.
Additionally, can you update the title now that the operation has been removed.
| TypeError: If `dense_pauli_string` is not a `cirq.DensePauliString` or a string. | ||
| """ | ||
| if not isinstance(dense_pauli_string, dps.DensePauliString): | ||
| dense_pauli_string = dps.DensePauliString(dense_pauli_string) |
There was a problem hiding this comment.
Calling the constructor with a MutableDensePauliString will treat it as an iterable of Pauli gates which drops the coefficient when converting to a DensePauliString. I suggest changing the constructor parameter type to BaseDensePauliString and simply calling .frozen() on it when setting the property here.
There was a problem hiding this comment.
sure - done! I left in parameters to optionally initialize the underlying DensePauliString with however, just to make code possibly a little cleaner. let me know what your thoughts are!
| if self._is_parameterized_(): | ||
| raise ValueError("PauliRotationGate should not be parameterized.") | ||
| angle = complex(self._angle()) | ||
| if not self._has_real_angle(): |
There was a problem hiding this comment.
The angle can be checked in the constructor, as it is done in PauliSumExponential, so you don't have to worry about it throughout the rest of the implementation.
There was a problem hiding this comment.
I think this would make DensePauliString unparameterizable, since you can't do these checks on scipy.Symbol, and I think PauliSumExponential has the same issue with PauliString in its check? is that all right?
| assert cirq.resolve_parameters(gate, {'t': 0.5}) == cirq.PauliRotationGate('XZ', 0.5) | ||
| coefficient_gate = cirq.PauliRotationGate(cirq.DensePauliString('XZ', coefficient=t)) | ||
| assert cirq.is_parameterized(coefficient_gate) | ||
| assert cirq.parameter_names(coefficient_gate) == {'t'} |
There was a problem hiding this comment.
nit: maybe add one more test case with both fields parameterized just for completeness?
There was a problem hiding this comment.
makes sense, added! but as per this comment, this possibly wouldn't be applicable anymore if we were to implement that change. wdyt?
PauliRotationGate and PauliRotation operationPauliRotationGate
this PR:
PauliRotationGategate, which represents the operationPauliRotationGate and PauliRotation
the specs for
PauliRotationGateare that:DensePauliStringor any input thatDensePauliStringmay take in, to define what string it will be rotating.PauliStringPhasor, and uses global phase shifts when the suppliedDensePauliStringonly consists ofI's.Alternatives
alternatively, I considered updating the functionality for
PauliSumExponentialto do this, but I think this would be tricky for a number of reasons:PauliSumExponentialdepends on take inPauliString.PauliString, in its documentation, specifies that it drops identity gates, meaning the behavior of classes using it to also drop identity is WAI. changing this may break things.DensePauliString, we would need to updatePauliSumExponentialandPauliSumto work withDensePauliStringor maintain qubits, which might make things more confusing.happy to discuss alternatives!
closes #6598.