Skip to content

Commit

Permalink
Fix type signature of act_on implementations (#4867)
Browse files Browse the repository at this point in the history
These are only ever called via reflection, but still the type should be as per this PR. @95-martin-orion
  • Loading branch information
daxfohl authored Jan 21, 2022
1 parent ee9bd68 commit 1be9468
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cirq-core/cirq/circuits/circuit_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def mapped_op(self, deep: bool = False) -> 'cirq.CircuitOperation':
def _decompose_(self) -> Iterator['cirq.Operation']:
return self.mapped_circuit(deep=False).all_operations()

def _act_on_(self, args: 'cirq.ActOnArgs') -> bool:
def _act_on_(self, args: 'cirq.OperationTarget') -> bool:
for op in self._decompose_():
protocols.act_on(op, args)
return True
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/classically_controlled_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _json_dict_(self) -> Dict[str, Any]:
'sub_operation': self._sub_operation,
}

def _act_on_(self, args: 'cirq.ActOnArgs') -> bool:
def _act_on_(self, args: 'cirq.OperationTarget') -> bool:
if all(c.resolve(args.log_of_measurement_results) for c in self._conditions):
protocols.act_on(self._sub_operation, args)
return True
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/gate_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def _measurement_key_objs_(self) -> Optional[AbstractSet['cirq.MeasurementKey']]
return getter()
return NotImplemented

def _act_on_(self, args: 'cirq.ActOnArgs'):
def _act_on_(self, args: 'cirq.OperationTarget'):
getter = getattr(self.gate, '_act_on_', None)
if getter is not None:
return getter(args, self.qubits)
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
if len(self._qid_shape) != num_qubits:
raise ValueError('len(qid_shape) != num_qubits')

def _act_on_(self, args: 'cirq.ActOnArgs', qubits: Sequence['cirq.Qid']):
def _act_on_(self, args: 'cirq.OperationTarget', qubits: Sequence['cirq.Qid']):
return True

def _qid_shape_(self) -> Tuple[int, ...]:
Expand Down
2 changes: 1 addition & 1 deletion cirq-core/cirq/ops/raw_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ def _is_parameterized_(self) -> bool:
protocols.is_parameterized(tag) for tag in self.tags
)

def _act_on_(self, args: 'cirq.ActOnArgs') -> bool:
def _act_on_(self, args: 'cirq.OperationTarget') -> bool:
sub = getattr(self.sub_operation, "_act_on_", None)
if sub is not None:
return sub(args)
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/protocols/act_on_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SupportsActOn(Protocol):
"""An object that explicitly specifies how to act on simulator states."""

@doc_private
def _act_on_(self, args: 'cirq.ActOnArgs') -> Union[NotImplementedType, bool]:
def _act_on_(self, args: 'cirq.OperationTarget') -> Union[NotImplementedType, bool]:
"""Applies an action to the given argument, if it is a supported type.
For example, unitary operations can implement an `_act_on_` method that
Expand Down Expand Up @@ -60,7 +60,7 @@ class SupportsActOnQubits(Protocol):
@doc_private
def _act_on_(
self,
args: 'cirq.ActOnArgs',
args: 'cirq.OperationTarget',
qubits: Sequence['cirq.Qid'],
) -> Union[NotImplementedType, bool]:
"""Applies an action to the given argument, if it is a supported type.
Expand Down
4 changes: 2 additions & 2 deletions cirq-core/cirq/testing/consistent_act_on_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class GoodGate(cirq.SingleQubitGate):
def _unitary_(self):
return np.array([[0, 1], [1, 0]])

def _act_on_(self, args: 'cirq.ActOnArgs', qubits: Sequence['cirq.Qid']):
def _act_on_(self, args: 'cirq.OperationTarget', qubits: Sequence['cirq.Qid']):
if isinstance(args, cirq.ActOnCliffordTableauArgs):
tableau = args.tableau
q = args.qubit_map[qubits[0]]
Expand All @@ -37,7 +37,7 @@ class BadGate(cirq.SingleQubitGate):
def _unitary_(self):
return np.array([[0, 1j], [1, 0]])

def _act_on_(self, args: 'cirq.ActOnArgs', qubits: Sequence['cirq.Qid']):
def _act_on_(self, args: 'cirq.OperationTarget', qubits: Sequence['cirq.Qid']):
if isinstance(args, cirq.ActOnCliffordTableauArgs):
tableau = args.tableau
q = args.qubit_map[qubits[0]]
Expand Down

0 comments on commit 1be9468

Please sign in to comment.