-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Document dimension of X/ZPowGate #5648
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,30 @@ class XPowGate(eigen_gate.EigenGate): | |
def __init__( | ||
self, *, exponent: value.TParamVal = 1.0, global_shift: float = 0.0, dimension: int = 2 | ||
): | ||
"""Initialize an XPowGate. | ||
|
||
Args: | ||
exponent: The t in gate**t. Determines how much the eigenvalues of | ||
the gate are scaled by. For example, eigenvectors phased by -1 | ||
when `gate**1` is applied will gain a relative phase of | ||
e^{i pi exponent} when `gate**exponent` is applied (relative to | ||
eigenvectors unaffected by `gate**1`). | ||
global_shift: Offsets the eigenvalues of the gate at exponent=1. | ||
In effect, this controls a global phase factor on the gate's | ||
unitary matrix. The factor is: | ||
|
||
exp(i * pi * global_shift * exponent) | ||
|
||
For example, `cirq.X**t` uses a `global_shift` of 0 but | ||
`cirq.rx(t)` uses a `global_shift` of -0.5, which is why | ||
`cirq.unitary(cirq.rx(pi))` equals -iX instead of X. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider updating the formula on line 75 above to account for global shift. Then you can refer to whatever letter you choose to use for global shift in the formula from the description of the argument here. This is what you effectively do on line 98 for exponent=t. The benefit of this is that it allows the reader to unambiguously identify the gate they will get for given arguments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, assuming I understood you correctly. PTAL There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's exactly it! :-) I haven't checked that the math is correct. Might be worth calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (To be clear: I think we do this in unit tests, but doing it manually would give you an opportunity to compare the output against the math in the comment.) |
||
dimension: Qudit dimension of this gate. For qu*b*its (the default), | ||
this is set to 2. | ||
|
||
Raises: | ||
ValueError: If the supplied exponent is a complex number with an | ||
imaginary component. | ||
""" | ||
super().__init__(exponent=exponent, global_shift=global_shift) | ||
self._dimension = dimension | ||
|
||
|
@@ -523,6 +547,30 @@ class ZPowGate(eigen_gate.EigenGate): | |
def __init__( | ||
self, *, exponent: value.TParamVal = 1.0, global_shift: float = 0.0, dimension: int = 2 | ||
): | ||
"""Initialize a ZPowGate. | ||
|
||
Args: | ||
exponent: The t in gate**t. Determines how much the eigenvalues of | ||
the gate are scaled by. For example, eigenvectors phased by -1 | ||
when `gate**1` is applied will gain a relative phase of | ||
e^{i pi exponent} when `gate**exponent` is applied (relative to | ||
eigenvectors unaffected by `gate**1`). | ||
global_shift: Offsets the eigenvalues of the gate at exponent=1. | ||
In effect, this controls a global phase factor on the gate's | ||
unitary matrix. The factor is: | ||
|
||
exp(i * pi * global_shift * exponent) | ||
|
||
For example, `cirq.X**t` uses a `global_shift` of 0 but | ||
`cirq.rx(t)` uses a `global_shift` of -0.5, which is why | ||
`cirq.unitary(cirq.rx(pi))` equals -iX instead of X. | ||
dimension: Qudit dimension of this gate. For qu*b*its (the default), | ||
this is set to 2. | ||
|
||
Raises: | ||
ValueError: If the supplied exponent is a complex number with an | ||
imaginary component. | ||
""" | ||
super().__init__(exponent=exponent, global_shift=global_shift) | ||
self._dimension = dimension | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.
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.
s/scaled/phased/
The word "scaled" suggests a possible change to absolute value (which does not change - all eigenvalues of a unitary gate have unit absolute value).
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.
Done, although this phrasing is copied from EigenGate. I'll update it there as well.