-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Support arbitrary exponents when exporting X/Y/ZPowGate to quirk url #2513
Conversation
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.
This PR doesn't pass automated checks.
cirq/contrib/quirk/quirk_gate.py
Outdated
|
||
if gate.global_shift == -0.5: | ||
return QuirkOp({'id': 'R{d}}ft', 'arg': f'{gate.exponent:.4f}pi'}) |
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.
nit: By comparing to l.138, it seems you may have meant ^ instead of second }, i.e. 'R{d}^ft'.
What's "ft"?
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.
Removed the extra }.
ft is an abbreviation of "function of t".
cirq/contrib/quirk/quirk_gate.py
Outdated
if e is None: | ||
return None | ||
return QuirkOp('X' + e) | ||
def xyz_to_known(axis: str, gate: ops.EigenGate) -> QuirkOp: |
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.
Optional nit: "to_known" is weird, because it lacks a noun. How about "xyz_to_quirk_op"? Any ideas for better names for these functions?
(Applies to other functions below, too.)
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.
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, only minor and optional comments.
if e is None: | ||
return None | ||
return QuirkOp('X' + e) | ||
def xyz_to_quirk_op(axis: str, gate: ops.EigenGate) -> QuirkOp: |
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.
Optional: Signature of this function makes it appear that it is appropriate to use it for general EigenGates, not just Pauli-PowGates. It's easy to remedy this by taking global_shift and exponent as arguments in place of the gate.
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.
Acknowledged, but this is a private method not exposed to users.
cirq/contrib/quirk/quirk_gate.py
Outdated
@@ -54,9 +57,35 @@ def same_half_turns(a1: float, a2: float, atol=0.0001) -> bool: | |||
return abs(d) < atol | |||
|
|||
|
|||
def angle_to_exponent_key(t: Union[float, sympy.Symbol]) -> Optional[str]: | |||
def _is_supported_formula(formula: sympy.Basic): |
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.
-> bool
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.
cirq/contrib/quirk/quirk_gate.py
Outdated
return False | ||
|
||
|
||
def _val_to_quirk_formula(t: Union[float, sympy.Basic]) -> Optional[str]: |
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.
-> str
(None
is never returned.)
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.
|
||
def _val_to_quirk_formula(t: Union[float, sympy.Basic]) -> Optional[str]: | ||
if isinstance(t, sympy.Basic): | ||
if not set(t.free_symbols) <= {sympy.Symbol('t')}: |
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.
Optional: This conditional is part of our validation logic, so it fits better in _is_supported_formula
. I understand you've placed it here to generate more informative exceptions. An alternative that gives you both is a function _check_formula_supported
that doesn't return anything but raises an exception on unsupported formulas. Up to you.
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.
Acknowledged.
@@ -12,6 +12,7 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
|||
import numpy as np |
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.
pylint wants this gone
Automerge cancelled: A status check is failing. |
No description provided.