We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
ValueError for PhasedXPowGate with integer phase_exponent
`PhasedXPowGate._circuit_diagram_info_` contains a format string that throws a `ValueError` when `phase_exponent` is an `int`.  I know the type annotation specifies `float` but mypy allows int.

```
c = cirq.Circuit.from_ops(
    cirq.PhasedXPowGate(phase_exponent=1)(cirq.LineQubit(0)),
)
print(c)
```
Output:
```
...
~/docs/cirq/cirq/ops/phased_x_gate.py in _circuit_diagram_info_(self, args)
    154         else:
    155             s = 'PhasedX({{:.{}}})'.format(args.precision).format(
--> 156                 self.phase_exponent)
    157         return protocols.CircuitDiagramInfo(
    158             wire_symbols=(s,),

ValueError: Precision not allowed in integer format specifier
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cirq/ops/phased_x_gate.py`
Content:
```
1 # Copyright 2018 The Cirq Developers
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     https://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """An `XPowGate` conjugated by `ZPowGate`s."""
16 from typing import Union, Sequence, Tuple, Optional, cast
17 
18 import math
19 import numpy as np
20 import sympy
21 
22 import cirq
23 from cirq import value, protocols
24 from cirq._compat import proper_repr
25 from cirq.ops import gate_features, raw_types, op_tree, common_gates
26 from cirq.type_workarounds import NotImplementedType
27 
28 
29 @value.value_equality(manual_cls=True)
30 class PhasedXPowGate(gate_features.SingleQubitGate):
31     """A gate equivalent to the circuit ───Z^-p───X^t───Z^p───."""
32 
33     def __init__(self,
34                  *,
35                  phase_exponent: Union[float, sympy.Symbol],
36                  exponent: Union[float, sympy.Symbol] = 1.0,
37                  global_shift: float = 0.0) -> None:
38         """
39         Args:
40             phase_exponent: The exponent on the Z gates conjugating the X gate.
41             exponent: The exponent on the X gate conjugated by Zs.
42             global_shift: How much to shift the operation's eigenvalues at
43                 exponent=1.
44         """
45         self._phase_exponent = value.canonicalize_half_turns(phase_exponent)
46         self._exponent = exponent
47         self._global_shift = global_shift
48 
49     def _qasm_(self,
50                args: protocols.QasmArgs,
51                qubits: Tuple[raw_types.Qid, ...]) -> Optional[str]:
52         if cirq.is_parameterized(self):
53             return None
54 
55         args.validate_version('2.0')
56 
57         e = cast(float, value.canonicalize_half_turns(self._exponent))
58         p = cast(float, self.phase_exponent)
59         epsilon = 10**-args.precision
60 
61         if abs(e + 0.5) <= epsilon:
62             return args.format('u2({0:half_turns}, {1:half_turns}) {2};\n',
63                                p + 0.5, -p - 0.5, qubits[0])
64 
65         if abs(e - 0.5) <= epsilon:
66             return args.format('u2({0:half_turns}, {1:half_turns}) {2};\n',
67                                p - 0.5, -p + 0.5, qubits[0])
68 
69         return args.format(
70             'u3({0:half_turns}, {1:half_turns}, {2:half_turns}) {3};\n',
71             -e, p + 0.5, -p - 0.5, qubits[0])
72 
73     def _decompose_(self, qubits: Sequence[raw_types.Qid]
74                           ) -> op_tree.OP_TREE:
75         assert len(qubits) == 1
76         q = qubits[0]
77         z = cirq.Z(q)**self._phase_exponent
78         x = cirq.X(q)**self._exponent
79         if protocols.is_parameterized(z):
80             return NotImplemented
81         return z**-1, x, z
82 
83     @property
84     def exponent(self) -> Union[float, sympy.Symbol]:
85         """The exponent on the central X gate conjugated by the Z gates."""
86         return self._exponent
87 
88     @property
89     def phase_exponent(self) -> Union[float, sympy.Symbol]:
90         """The exponent on the Z gates conjugating the X gate."""
91         return self._phase_exponent
92 
93     def __pow__(self, exponent: Union[float, sympy.Symbol]) -> 'PhasedXPowGate':
94         new_exponent = protocols.mul(self._exponent, exponent, NotImplemented)
95         if new_exponent is NotImplemented:
96             return NotImplemented
97         return PhasedXPowGate(phase_exponent=self._phase_exponent,
98                               exponent=new_exponent,
99                               global_shift=self._global_shift)
100 
101     def _trace_distance_bound_(self) -> Optional[float]:
102         if self._is_parameterized_():
103             return None
104         return abs(np.sin(self._exponent * 0.5 * np.pi))
105 
106     def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:
107         """See `cirq.SupportsUnitary`."""
108         if self._is_parameterized_():
109             return NotImplemented
110         z = protocols.unitary(cirq.Z**self._phase_exponent)
111         x = protocols.unitary(cirq.X**self._exponent)
112         p = np.exp(1j * np.pi * self._global_shift * self._exponent)
113         return np.dot(np.dot(z, x), np.conj(z)) * p
114 
115     def _pauli_expansion_(self) -> value.LinearDict[str]:
116         if self._is_parameterized_():
117             return NotImplemented
118         phase_angle = np.pi * self._phase_exponent / 2
119         angle = np.pi * self._exponent / 2
120         phase = 1j**(2 * self._exponent * (self._global_shift + 0.5))
121         return value.LinearDict({
122             'I': phase * np.cos(angle),
123             'X': -1j * phase * np.sin(angle) * np.cos(2 * phase_angle),
124             'Y': -1j * phase * np.sin(angle) * np.sin(2 * phase_angle),
125         })
126 
127     def _is_parameterized_(self) -> bool:
128         """See `cirq.SupportsParameterization`."""
129         return (protocols.is_parameterized(self._exponent) or
130                 protocols.is_parameterized(self._phase_exponent))
131 
132     def _resolve_parameters_(self, param_resolver) -> 'PhasedXPowGate':
133         """See `cirq.SupportsParameterization`."""
134         return PhasedXPowGate(
135             phase_exponent=param_resolver.value_of(self._phase_exponent),
136             exponent=param_resolver.value_of(self._exponent),
137             global_shift=self._global_shift)
138 
139     def _phase_by_(self, phase_turns, qubit_index):
140         """See `cirq.SupportsPhase`."""
141         assert qubit_index == 0
142         return PhasedXPowGate(
143             exponent=self._exponent,
144             phase_exponent=self._phase_exponent + phase_turns * 2,
145             global_shift=self._global_shift)
146 
147     def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs
148                                ) -> protocols.CircuitDiagramInfo:
149         """See `cirq.SupportsCircuitDiagramInfo`."""
150 
151         if (isinstance(self.phase_exponent, sympy.Symbol) or
152                 args.precision is None):
153             s = 'PhasedX({})'.format(self.phase_exponent)
154         else:
155             s = 'PhasedX({{:.{}}})'.format(args.precision).format(
156                 self.phase_exponent)
157         return protocols.CircuitDiagramInfo(
158             wire_symbols=(s,),
159             exponent=value.canonicalize_half_turns(self._exponent))
160 
161     def __str__(self):
162         info = protocols.circuit_diagram_info(self)
163         if info.exponent == 1:
164             return info.wire_symbols[0]
165         return '{}^{}'.format(info.wire_symbols[0], info.exponent)
166 
167     def __repr__(self):
168         args = ['phase_exponent={}'.format(proper_repr(self.phase_exponent))]
169         if self.exponent != 1:
170             args.append('exponent={}'.format(proper_repr(self.exponent)))
171         if self._global_shift != 0:
172             args.append('global_shift={!r}'.format(self._global_shift))
173         return 'cirq.PhasedXPowGate({})'.format(', '.join(args))
174 
175     def _period(self):
176         exponents = [self._global_shift, 1 + self._global_shift]
177         real_periods = [abs(2/e) for e in exponents if e != 0]
178         int_periods = [int(np.round(e)) for e in real_periods]
179         if any(i != r for i, r in zip(real_periods, int_periods)):
180             return None
181         if len(int_periods) == 1:
182             return int_periods[0]
183         return int_periods[0] * int_periods[1] / math.gcd(*int_periods)
184 
185     @property
186     def _canonical_exponent(self):
187         period = self._period()
188         if not period or isinstance(self._exponent, sympy.Symbol):
189             return self._exponent
190 
191         return self._exponent % period
192 
193     def _value_equality_values_cls_(self):
194         if self.phase_exponent == 0:
195             return common_gates.XPowGate
196         if self.phase_exponent == 0.5:
197             return common_gates.YPowGate
198         return PhasedXPowGate
199 
200     def _value_equality_values_(self):
201         if self.phase_exponent == 0:
202             return common_gates.XPowGate(
203                 exponent=self._exponent,
204                 global_shift=self._global_shift)._value_equality_values_()
205         if self.phase_exponent == 0.5:
206             return common_gates.YPowGate(
207                 exponent=self._exponent,
208                 global_shift=self._global_shift)._value_equality_values_()
209         return self.phase_exponent, self._canonical_exponent, self._global_shift
210
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cirq/ops/phased_x_gate.py b/cirq/ops/phased_x_gate.py
--- a/cirq/ops/phased_x_gate.py
+++ b/cirq/ops/phased_x_gate.py
@@ -152,7 +152,7 @@
                 args.precision is None):
             s = 'PhasedX({})'.format(self.phase_exponent)
         else:
-            s = 'PhasedX({{:.{}}})'.format(args.precision).format(
+            s = 'PhasedX({{:.{}f}})'.format(args.precision).format(
                 self.phase_exponent)
         return protocols.CircuitDiagramInfo(
             wire_symbols=(s,),

{"golden_diff": "diff --git a/cirq/ops/phased_x_gate.py b/cirq/ops/phased_x_gate.py\n--- a/cirq/ops/phased_x_gate.py\n+++ b/cirq/ops/phased_x_gate.py\n@@ -152,7 +152,7 @@\n                 args.precision is None):\n             s = 'PhasedX({})'.format(self.phase_exponent)\n         else:\n-            s = 'PhasedX({{:.{}}})'.format(args.precision).format(\n+            s = 'PhasedX({{:.{}f}})'.format(args.precision).format(\n                 self.phase_exponent)\n         return protocols.CircuitDiagramInfo(\n             wire_symbols=(s,),\n", "issue": "ValueError for PhasedXPowGate with integer phase_exponent\n`PhasedXPowGate._circuit_diagram_info_` contains a format string that throws a `ValueError` when `phase_exponent` is an `int`.  I know the type annotation specifies `float` but mypy allows int.\r\n\r\n```\r\nc = cirq.Circuit.from_ops(\r\n    cirq.PhasedXPowGate(phase_exponent=1)(cirq.LineQubit(0)),\r\n)\r\nprint(c)\r\n```\r\nOutput:\r\n```\r\n...\r\n~/docs/cirq/cirq/ops/phased_x_gate.py in _circuit_diagram_info_(self, args)\r\n    154         else:\r\n    155             s = 'PhasedX({{:.{}}})'.format(args.precision).format(\r\n--> 156                 self.phase_exponent)\r\n    157         return protocols.CircuitDiagramInfo(\r\n    158             wire_symbols=(s,),\r\n\r\nValueError: Precision not allowed in integer format specifier\r\n```\n", "before_files": [{"content": "# Copyright 2018 The Cirq Developers\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"An `XPowGate` conjugated by `ZPowGate`s.\"\"\"\nfrom typing import Union, Sequence, Tuple, Optional, cast\n\nimport math\nimport numpy as np\nimport sympy\n\nimport cirq\nfrom cirq import value, protocols\nfrom cirq._compat import proper_repr\nfrom cirq.ops import gate_features, raw_types, op_tree, common_gates\nfrom cirq.type_workarounds import NotImplementedType\n\n\n@value.value_equality(manual_cls=True)\nclass PhasedXPowGate(gate_features.SingleQubitGate):\n    \"\"\"A gate equivalent to the circuit \u2500\u2500\u2500Z^-p\u2500\u2500\u2500X^t\u2500\u2500\u2500Z^p\u2500\u2500\u2500.\"\"\"\n\n    def __init__(self,\n                 *,\n                 phase_exponent: Union[float, sympy.Symbol],\n                 exponent: Union[float, sympy.Symbol] = 1.0,\n                 global_shift: float = 0.0) -> None:\n        \"\"\"\n        Args:\n            phase_exponent: The exponent on the Z gates conjugating the X gate.\n            exponent: The exponent on the X gate conjugated by Zs.\n            global_shift: How much to shift the operation's eigenvalues at\n                exponent=1.\n        \"\"\"\n        self._phase_exponent = value.canonicalize_half_turns(phase_exponent)\n        self._exponent = exponent\n        self._global_shift = global_shift\n\n    def _qasm_(self,\n               args: protocols.QasmArgs,\n               qubits: Tuple[raw_types.Qid, ...]) -> Optional[str]:\n        if cirq.is_parameterized(self):\n            return None\n\n        args.validate_version('2.0')\n\n        e = cast(float, value.canonicalize_half_turns(self._exponent))\n        p = cast(float, self.phase_exponent)\n        epsilon = 10**-args.precision\n\n        if abs(e + 0.5) <= epsilon:\n            return args.format('u2({0:half_turns}, {1:half_turns}) {2};\\n',\n                               p + 0.5, -p - 0.5, qubits[0])\n\n        if abs(e - 0.5) <= epsilon:\n            return args.format('u2({0:half_turns}, {1:half_turns}) {2};\\n',\n                               p - 0.5, -p + 0.5, qubits[0])\n\n        return args.format(\n            'u3({0:half_turns}, {1:half_turns}, {2:half_turns}) {3};\\n',\n            -e, p + 0.5, -p - 0.5, qubits[0])\n\n    def _decompose_(self, qubits: Sequence[raw_types.Qid]\n                          ) -> op_tree.OP_TREE:\n        assert len(qubits) == 1\n        q = qubits[0]\n        z = cirq.Z(q)**self._phase_exponent\n        x = cirq.X(q)**self._exponent\n        if protocols.is_parameterized(z):\n            return NotImplemented\n        return z**-1, x, z\n\n    @property\n    def exponent(self) -> Union[float, sympy.Symbol]:\n        \"\"\"The exponent on the central X gate conjugated by the Z gates.\"\"\"\n        return self._exponent\n\n    @property\n    def phase_exponent(self) -> Union[float, sympy.Symbol]:\n        \"\"\"The exponent on the Z gates conjugating the X gate.\"\"\"\n        return self._phase_exponent\n\n    def __pow__(self, exponent: Union[float, sympy.Symbol]) -> 'PhasedXPowGate':\n        new_exponent = protocols.mul(self._exponent, exponent, NotImplemented)\n        if new_exponent is NotImplemented:\n            return NotImplemented\n        return PhasedXPowGate(phase_exponent=self._phase_exponent,\n                              exponent=new_exponent,\n                              global_shift=self._global_shift)\n\n    def _trace_distance_bound_(self) -> Optional[float]:\n        if self._is_parameterized_():\n            return None\n        return abs(np.sin(self._exponent * 0.5 * np.pi))\n\n    def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:\n        \"\"\"See `cirq.SupportsUnitary`.\"\"\"\n        if self._is_parameterized_():\n            return NotImplemented\n        z = protocols.unitary(cirq.Z**self._phase_exponent)\n        x = protocols.unitary(cirq.X**self._exponent)\n        p = np.exp(1j * np.pi * self._global_shift * self._exponent)\n        return np.dot(np.dot(z, x), np.conj(z)) * p\n\n    def _pauli_expansion_(self) -> value.LinearDict[str]:\n        if self._is_parameterized_():\n            return NotImplemented\n        phase_angle = np.pi * self._phase_exponent / 2\n        angle = np.pi * self._exponent / 2\n        phase = 1j**(2 * self._exponent * (self._global_shift + 0.5))\n        return value.LinearDict({\n            'I': phase * np.cos(angle),\n            'X': -1j * phase * np.sin(angle) * np.cos(2 * phase_angle),\n            'Y': -1j * phase * np.sin(angle) * np.sin(2 * phase_angle),\n        })\n\n    def _is_parameterized_(self) -> bool:\n        \"\"\"See `cirq.SupportsParameterization`.\"\"\"\n        return (protocols.is_parameterized(self._exponent) or\n                protocols.is_parameterized(self._phase_exponent))\n\n    def _resolve_parameters_(self, param_resolver) -> 'PhasedXPowGate':\n        \"\"\"See `cirq.SupportsParameterization`.\"\"\"\n        return PhasedXPowGate(\n            phase_exponent=param_resolver.value_of(self._phase_exponent),\n            exponent=param_resolver.value_of(self._exponent),\n            global_shift=self._global_shift)\n\n    def _phase_by_(self, phase_turns, qubit_index):\n        \"\"\"See `cirq.SupportsPhase`.\"\"\"\n        assert qubit_index == 0\n        return PhasedXPowGate(\n            exponent=self._exponent,\n            phase_exponent=self._phase_exponent + phase_turns * 2,\n            global_shift=self._global_shift)\n\n    def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs\n                               ) -> protocols.CircuitDiagramInfo:\n        \"\"\"See `cirq.SupportsCircuitDiagramInfo`.\"\"\"\n\n        if (isinstance(self.phase_exponent, sympy.Symbol) or\n                args.precision is None):\n            s = 'PhasedX({})'.format(self.phase_exponent)\n        else:\n            s = 'PhasedX({{:.{}}})'.format(args.precision).format(\n                self.phase_exponent)\n        return protocols.CircuitDiagramInfo(\n            wire_symbols=(s,),\n            exponent=value.canonicalize_half_turns(self._exponent))\n\n    def __str__(self):\n        info = protocols.circuit_diagram_info(self)\n        if info.exponent == 1:\n            return info.wire_symbols[0]\n        return '{}^{}'.format(info.wire_symbols[0], info.exponent)\n\n    def __repr__(self):\n        args = ['phase_exponent={}'.format(proper_repr(self.phase_exponent))]\n        if self.exponent != 1:\n            args.append('exponent={}'.format(proper_repr(self.exponent)))\n        if self._global_shift != 0:\n            args.append('global_shift={!r}'.format(self._global_shift))\n        return 'cirq.PhasedXPowGate({})'.format(', '.join(args))\n\n    def _period(self):\n        exponents = [self._global_shift, 1 + self._global_shift]\n        real_periods = [abs(2/e) for e in exponents if e != 0]\n        int_periods = [int(np.round(e)) for e in real_periods]\n        if any(i != r for i, r in zip(real_periods, int_periods)):\n            return None\n        if len(int_periods) == 1:\n            return int_periods[0]\n        return int_periods[0] * int_periods[1] / math.gcd(*int_periods)\n\n    @property\n    def _canonical_exponent(self):\n        period = self._period()\n        if not period or isinstance(self._exponent, sympy.Symbol):\n            return self._exponent\n\n        return self._exponent % period\n\n    def _value_equality_values_cls_(self):\n        if self.phase_exponent == 0:\n            return common_gates.XPowGate\n        if self.phase_exponent == 0.5:\n            return common_gates.YPowGate\n        return PhasedXPowGate\n\n    def _value_equality_values_(self):\n        if self.phase_exponent == 0:\n            return common_gates.XPowGate(\n                exponent=self._exponent,\n                global_shift=self._global_shift)._value_equality_values_()\n        if self.phase_exponent == 0.5:\n            return common_gates.YPowGate(\n                exponent=self._exponent,\n                global_shift=self._global_shift)._value_equality_values_()\n        return self.phase_exponent, self._canonical_exponent, self._global_shift\n", "path": "cirq/ops/phased_x_gate.py"}], "after_files": [{"content": "# Copyright 2018 The Cirq Developers\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     https://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"An `XPowGate` conjugated by `ZPowGate`s.\"\"\"\nfrom typing import Union, Sequence, Tuple, Optional, cast\n\nimport math\nimport numpy as np\nimport sympy\n\nimport cirq\nfrom cirq import value, protocols\nfrom cirq._compat import proper_repr\nfrom cirq.ops import gate_features, raw_types, op_tree, common_gates\nfrom cirq.type_workarounds import NotImplementedType\n\n\n@value.value_equality(manual_cls=True)\nclass PhasedXPowGate(gate_features.SingleQubitGate):\n    \"\"\"A gate equivalent to the circuit \u2500\u2500\u2500Z^-p\u2500\u2500\u2500X^t\u2500\u2500\u2500Z^p\u2500\u2500\u2500.\"\"\"\n\n    def __init__(self,\n                 *,\n                 phase_exponent: Union[float, sympy.Symbol],\n                 exponent: Union[float, sympy.Symbol] = 1.0,\n                 global_shift: float = 0.0) -> None:\n        \"\"\"\n        Args:\n            phase_exponent: The exponent on the Z gates conjugating the X gate.\n            exponent: The exponent on the X gate conjugated by Zs.\n            global_shift: How much to shift the operation's eigenvalues at\n                exponent=1.\n        \"\"\"\n        self._phase_exponent = value.canonicalize_half_turns(phase_exponent)\n        self._exponent = exponent\n        self._global_shift = global_shift\n\n    def _qasm_(self,\n               args: protocols.QasmArgs,\n               qubits: Tuple[raw_types.Qid, ...]) -> Optional[str]:\n        if cirq.is_parameterized(self):\n            return None\n\n        args.validate_version('2.0')\n\n        e = cast(float, value.canonicalize_half_turns(self._exponent))\n        p = cast(float, self.phase_exponent)\n        epsilon = 10**-args.precision\n\n        if abs(e + 0.5) <= epsilon:\n            return args.format('u2({0:half_turns}, {1:half_turns}) {2};\\n',\n                               p + 0.5, -p - 0.5, qubits[0])\n\n        if abs(e - 0.5) <= epsilon:\n            return args.format('u2({0:half_turns}, {1:half_turns}) {2};\\n',\n                               p - 0.5, -p + 0.5, qubits[0])\n\n        return args.format(\n            'u3({0:half_turns}, {1:half_turns}, {2:half_turns}) {3};\\n',\n            -e, p + 0.5, -p - 0.5, qubits[0])\n\n    def _decompose_(self, qubits: Sequence[raw_types.Qid]\n                          ) -> op_tree.OP_TREE:\n        assert len(qubits) == 1\n        q = qubits[0]\n        z = cirq.Z(q)**self._phase_exponent\n        x = cirq.X(q)**self._exponent\n        if protocols.is_parameterized(z):\n            return NotImplemented\n        return z**-1, x, z\n\n    @property\n    def exponent(self) -> Union[float, sympy.Symbol]:\n        \"\"\"The exponent on the central X gate conjugated by the Z gates.\"\"\"\n        return self._exponent\n\n    @property\n    def phase_exponent(self) -> Union[float, sympy.Symbol]:\n        \"\"\"The exponent on the Z gates conjugating the X gate.\"\"\"\n        return self._phase_exponent\n\n    def __pow__(self, exponent: Union[float, sympy.Symbol]) -> 'PhasedXPowGate':\n        new_exponent = protocols.mul(self._exponent, exponent, NotImplemented)\n        if new_exponent is NotImplemented:\n            return NotImplemented\n        return PhasedXPowGate(phase_exponent=self._phase_exponent,\n                              exponent=new_exponent,\n                              global_shift=self._global_shift)\n\n    def _trace_distance_bound_(self) -> Optional[float]:\n        if self._is_parameterized_():\n            return None\n        return abs(np.sin(self._exponent * 0.5 * np.pi))\n\n    def _unitary_(self) -> Union[np.ndarray, NotImplementedType]:\n        \"\"\"See `cirq.SupportsUnitary`.\"\"\"\n        if self._is_parameterized_():\n            return NotImplemented\n        z = protocols.unitary(cirq.Z**self._phase_exponent)\n        x = protocols.unitary(cirq.X**self._exponent)\n        p = np.exp(1j * np.pi * self._global_shift * self._exponent)\n        return np.dot(np.dot(z, x), np.conj(z)) * p\n\n    def _pauli_expansion_(self) -> value.LinearDict[str]:\n        if self._is_parameterized_():\n            return NotImplemented\n        phase_angle = np.pi * self._phase_exponent / 2\n        angle = np.pi * self._exponent / 2\n        phase = 1j**(2 * self._exponent * (self._global_shift + 0.5))\n        return value.LinearDict({\n            'I': phase * np.cos(angle),\n            'X': -1j * phase * np.sin(angle) * np.cos(2 * phase_angle),\n            'Y': -1j * phase * np.sin(angle) * np.sin(2 * phase_angle),\n        })\n\n    def _is_parameterized_(self) -> bool:\n        \"\"\"See `cirq.SupportsParameterization`.\"\"\"\n        return (protocols.is_parameterized(self._exponent) or\n                protocols.is_parameterized(self._phase_exponent))\n\n    def _resolve_parameters_(self, param_resolver) -> 'PhasedXPowGate':\n        \"\"\"See `cirq.SupportsParameterization`.\"\"\"\n        return PhasedXPowGate(\n            phase_exponent=param_resolver.value_of(self._phase_exponent),\n            exponent=param_resolver.value_of(self._exponent),\n            global_shift=self._global_shift)\n\n    def _phase_by_(self, phase_turns, qubit_index):\n        \"\"\"See `cirq.SupportsPhase`.\"\"\"\n        assert qubit_index == 0\n        return PhasedXPowGate(\n            exponent=self._exponent,\n            phase_exponent=self._phase_exponent + phase_turns * 2,\n            global_shift=self._global_shift)\n\n    def _circuit_diagram_info_(self, args: protocols.CircuitDiagramInfoArgs\n                               ) -> protocols.CircuitDiagramInfo:\n        \"\"\"See `cirq.SupportsCircuitDiagramInfo`.\"\"\"\n\n        if (isinstance(self.phase_exponent, sympy.Symbol) or\n                args.precision is None):\n            s = 'PhasedX({})'.format(self.phase_exponent)\n        else:\n            s = 'PhasedX({{:.{}f}})'.format(args.precision).format(\n                self.phase_exponent)\n        return protocols.CircuitDiagramInfo(\n            wire_symbols=(s,),\n            exponent=value.canonicalize_half_turns(self._exponent))\n\n    def __str__(self):\n        info = protocols.circuit_diagram_info(self)\n        if info.exponent == 1:\n            return info.wire_symbols[0]\n        return '{}^{}'.format(info.wire_symbols[0], info.exponent)\n\n    def __repr__(self):\n        args = ['phase_exponent={}'.format(proper_repr(self.phase_exponent))]\n        if self.exponent != 1:\n            args.append('exponent={}'.format(proper_repr(self.exponent)))\n        if self._global_shift != 0:\n            args.append('global_shift={!r}'.format(self._global_shift))\n        return 'cirq.PhasedXPowGate({})'.format(', '.join(args))\n\n    def _period(self):\n        exponents = [self._global_shift, 1 + self._global_shift]\n        real_periods = [abs(2/e) for e in exponents if e != 0]\n        int_periods = [int(np.round(e)) for e in real_periods]\n        if any(i != r for i, r in zip(real_periods, int_periods)):\n            return None\n        if len(int_periods) == 1:\n            return int_periods[0]\n        return int_periods[0] * int_periods[1] / math.gcd(*int_periods)\n\n    @property\n    def _canonical_exponent(self):\n        period = self._period()\n        if not period or isinstance(self._exponent, sympy.Symbol):\n            return self._exponent\n\n        return self._exponent % period\n\n    def _value_equality_values_cls_(self):\n        if self.phase_exponent == 0:\n            return common_gates.XPowGate\n        if self.phase_exponent == 0.5:\n            return common_gates.YPowGate\n        return PhasedXPowGate\n\n    def _value_equality_values_(self):\n        if self.phase_exponent == 0:\n            return common_gates.XPowGate(\n                exponent=self._exponent,\n                global_shift=self._global_shift)._value_equality_values_()\n        if self.phase_exponent == 0.5:\n            return common_gates.YPowGate(\n                exponent=self._exponent,\n                global_shift=self._global_shift)._value_equality_values_()\n        return self.phase_exponent, self._canonical_exponent, self._global_shift\n", "path": "cirq/ops/phased_x_gate.py"}]}