@@ -60,35 +60,37 @@ class PhaseGradientUnitary(GateWithRegisters):
6060
6161 bitsize : int
6262 exponent : float = 1
63- controlled : bool = False
63+ is_controlled : bool = False
6464 eps : float = 1e-10
6565
6666 @cached_property
6767 def signature (self ) -> 'Signature' :
6868 return (
6969 Signature .build_from_dtypes (ctrl = QBit (), phase_grad = QFxp (self .bitsize , self .bitsize ))
70- if self .controlled
70+ if self .is_controlled
7171 else Signature .build_from_dtypes (phase_grad = QFxp (self .bitsize , self .bitsize ))
7272 )
7373
7474 def decompose_from_registers (
7575 self , * , context : cirq .DecompositionContext , ** quregs : NDArray [cirq .Qid ] # type: ignore[type-var]
7676 ) -> cirq .OP_TREE :
7777 ctrl = quregs .get ('ctrl' , ())
78- gate = CZPowGate if self .controlled else ZPowGate
78+ gate = CZPowGate if self .is_controlled else ZPowGate
7979 for i , q in enumerate (quregs ['phase_grad' ]):
8080 yield gate (exponent = self .exponent / 2 ** i , eps = self .eps / self .bitsize ).on (* ctrl , q )
8181
8282 def _circuit_diagram_info_ (self , args : cirq .CircuitDiagramInfoArgs ) -> cirq .CircuitDiagramInfo :
83- wire_symbols = ['@' ] * self .controlled + [
83+ wire_symbols = ['@' ] * self .is_controlled + [
8484 f'Z^{ self .exponent } /{ 2 ** (i + 1 )} ' for i in range (self .bitsize )
8585 ]
8686 return cirq .CircuitDiagramInfo (wire_symbols = wire_symbols )
8787
8888 def __pow__ (self , power ):
8989 if power == 1 :
9090 return self
91- return PhaseGradientUnitary (self .bitsize , self .exponent * power , self .controlled , self .eps )
91+ return PhaseGradientUnitary (
92+ self .bitsize , self .exponent * power , self .is_controlled , self .eps
93+ )
9294
9395
9496@attrs .frozen
@@ -135,7 +137,7 @@ def decompose_from_registers(
135137
136138
137139@attrs .frozen
138- class AddIntoPhaseGrad (GateWithRegisters , cirq .ArithmeticGate ):
140+ class AddIntoPhaseGrad (GateWithRegisters , cirq .ArithmeticGate ): # type: ignore[misc]
139141 r"""Quantum-quantum addition into a phase gradient register using $b_{phase} - 2$ Toffolis
140142
141143 $$
@@ -149,9 +151,9 @@ class AddIntoPhaseGrad(GateWithRegisters, cirq.ArithmeticGate):
149151 shifted before adding to the phase gradient register.
150152 sign: Whether the input register x should be added or subtracted from the phase gradient
151153 register.
152- controlled : Whether to control this bloq with a ctrl register. When controlled =None, this bloq
153- is not controlled. When controlled =0, this bloq is active when the ctrl register is 0. When
154- controlled =1, this bloq is active when the ctrl register is 1.
154+ controlled_by : Whether to control this bloq with a ctrl register. When controlled_by =None, this bloq
155+ is not controlled. When controlled_by =0, this bloq is active when the ctrl register is 0. When
156+ controlled_by =1, this bloq is active when the ctrl register is 1.
155157
156158 Registers:
157159 - ctrl: Control THRU register
@@ -167,7 +169,7 @@ class AddIntoPhaseGrad(GateWithRegisters, cirq.ArithmeticGate):
167169 phase_bitsize : 'SymbolicInt'
168170 right_shift : int = 0
169171 sign : int = + 1
170- controlled : Optional [int ] = None
172+ controlled_by : Optional [int ] = None
171173
172174 def pretty_name (self ) -> str :
173175 sign = '+' if self .sign > 0 else '-'
@@ -181,7 +183,7 @@ def signature(self) -> 'Signature':
181183 x = QFxp (self .x_bitsize , self .x_bitsize , signed = False ),
182184 phase_grad = QFxp (self .phase_bitsize , self .phase_bitsize , signed = False ),
183185 )
184- if self .controlled is not None
186+ if self .controlled_by is not None
185187 else Signature .build_from_dtypes (
186188 x = QFxp (self .x_bitsize , self .x_bitsize , signed = False ),
187189 phase_grad = QFxp (self .phase_bitsize , self .phase_bitsize , signed = False ),
@@ -195,7 +197,9 @@ def phase_dtype(self) -> QFxp:
195197 def registers (self ) -> Sequence [Union [int , Sequence [int ]]]:
196198 if isinstance (self .phase_bitsize , sympy .Expr ):
197199 raise ValueError (f'Symbolic phase { self .phase_bitsize } not supported' )
198- if self .controlled is not None :
200+ if isinstance (self .x_bitsize , sympy .Expr ):
201+ raise ValueError (f'Symbolic bitsize { self .x_bitsize } not supported' )
202+ if self .controlled_by is not None :
199203 return [2 ], [2 ] * self .x_bitsize , [2 ] * self .phase_bitsize
200204 return [2 ] * self .x_bitsize , [2 ] * self .phase_bitsize
201205
@@ -210,7 +214,7 @@ def scaled_val(self, x: int) -> int:
210214 return int (x_fxp .astype (float ) * 2 ** self .phase_bitsize )
211215
212216 def apply (self , * args ) -> Union [int , Iterable [int ]]:
213- if self .controlled is not None :
217+ if self .controlled_by is not None :
214218 ctrl , x , phase_grad = args
215219 out = self .on_classical_vals (ctrl = ctrl , x = x , phase_grad = phase_grad )
216220 return out ['ctrl' ], out ['x' ], out ['phase_grad' ]
@@ -221,9 +225,9 @@ def apply(self, *args) -> Union[int, Iterable[int]]:
221225
222226 def on_classical_vals (self , ** kwargs ) -> Dict [str , 'ClassicalValT' ]:
223227 x , phase_grad = kwargs ['x' ], kwargs ['phase_grad' ]
224- if self .controlled is not None :
228+ if self .controlled_by is not None :
225229 ctrl = kwargs ['ctrl' ]
226- if ctrl == self .controlled :
230+ if ctrl == self .controlled_by :
227231 phase_grad_out = (phase_grad + self .sign * self .scaled_val (x )) % (
228232 2 ** self .phase_bitsize
229233 )
@@ -236,7 +240,7 @@ def on_classical_vals(self, **kwargs) -> Dict[str, 'ClassicalValT']:
236240
237241 def build_call_graph (self , ssa : 'SympySymbolAllocator' ) -> Set ['BloqCountT' ]:
238242 num_toffoli = self .phase_bitsize - 2
239- if self .controlled is not None :
243+ if self .controlled_by is not None :
240244 return {(Toffoli (), 2 * num_toffoli )}
241245
242246 return {(Toffoli (), num_toffoli )}
@@ -251,7 +255,7 @@ def adjoint(self) -> 'Bloq':
251255 self .phase_bitsize ,
252256 self .right_shift ,
253257 sign = - 1 * self .sign ,
254- controlled = self .controlled ,
258+ controlled_by = self .controlled_by ,
255259 )
256260
257261 def __pow__ (self , power ):
0 commit comments