@@ -144,7 +144,7 @@ def _value_equality_values_(self) -> Any:
144
144
return tuple (self ._diag_angles_radians )
145
145
146
146
def _decompose_for_basis (
147
- self , index : int , bit_flip : int , theta : float , qubits : Sequence ['cirq.Qid' ]
147
+ self , index : int , bit_flip : int , theta : value . TParamVal , qubits : Sequence ['cirq.Qid' ]
148
148
) -> Iterator [Union ['cirq.ZPowGate' , 'cirq.CXPowGate' ]]:
149
149
if index == 0 :
150
150
return []
@@ -166,7 +166,7 @@ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
166
166
│ │ │ │
167
167
2: ───Rz(1)───@───────────@───────────────────────@───────────────────────@───────────
168
168
169
- where the angles in Rz gates are corresponding to the fast-walsh-Hadamard transfrom
169
+ where the angles in Rz gates are corresponding to the fast-walsh-Hadamard transform
170
170
of diagonal_angles in the Gray Code order.
171
171
172
172
For n qubits decomposition looks similar but with 2^n-1 Rz gates and 2^n-2 CNOT gates.
@@ -176,19 +176,20 @@ def _decompose_(self, qubits: Sequence['cirq.Qid']) -> 'cirq.OP_TREE':
176
176
ancillas." New Journal of Physics 16.3 (2014): 033040.
177
177
https://iopscience.iop.org/article/10.1088/1367-2630/16/3/033040/meta
178
178
"""
179
- if protocols .is_parameterized (self ):
180
- return NotImplemented
181
-
182
179
n = self ._num_qubits_ ()
183
180
hat_angles = _fast_walsh_hadamard_transform (self ._diag_angles_radians ) / (2 ** n )
184
181
185
182
# There is one global phase shift between unitary matrix of the diagonal gate and the
186
183
# decomposed gates. On its own it is not physically observable. However, if using this
187
184
# diagonal gate for sub-system like controlled gate, it is no longer equivalent. Hence,
188
185
# we add global phase.
189
- decomposed_circ : List [Any ] = [
190
- global_phase_op .global_phase_operation (np .exp (1j * hat_angles [0 ]))
191
- ]
186
+ # Global phase is ignored for parameterized gates as `cirq.GlobalPhaseGate` expects a
187
+ # scalar value.
188
+ decomposed_circ : List [Any ] = (
189
+ [global_phase_op .global_phase_operation (np .exp (1j * hat_angles [0 ]))]
190
+ if not protocols .is_parameterized (hat_angles [0 ])
191
+ else []
192
+ )
192
193
for i , bit_flip in _gen_gray_code (n ):
193
194
decomposed_circ .extend (self ._decompose_for_basis (i , bit_flip , - hat_angles [i ], qubits ))
194
195
return decomposed_circ
0 commit comments