Ejemplo n.º 1
0
 def _equal_up_to_global_phase_(
         self,
         other: Any,
         atol: Union[int, float] = 1e-8) -> Union[NotImplementedType, bool]:
     return protocols.equal_up_to_global_phase(self.sub_operation,
                                               other,
                                               atol=atol)
Ejemplo n.º 2
0
 def _equal_up_to_global_phase_(
     self, other: Any, atol: Union[int, float] = 1e-8
 ) -> Union[NotImplementedType, bool]:
     if not isinstance(other, type(self)):
         return NotImplemented
     if self._group_interchangeable_qubits() != other._group_interchangeable_qubits():
         return False
     return protocols.equal_up_to_global_phase(self.gate, other.gate, atol=atol)
Ejemplo n.º 3
0
    def _predicate(self, gate: raw_types.Gate) -> bool:
        """Checks whether `cirq.Gate` instance `gate` belongs to this GateFamily.

        The default predicate depends on the gate family initialization type:
            a) Instance Family: `cirq.equal_up_to_global_phase(gate, self.gate)`
                                 if self._ignore_global_phase else `gate == self.gate`.
            b) Type Family: `isinstance(gate, self.gate)`.

        Args:
            gate: `cirq.Gate` instance which should be checked for containment.
        """
        if isinstance(self.gate, raw_types.Gate):
            return (protocols.equal_up_to_global_phase(gate, self.gate)
                    if self._ignore_global_phase else gate == self._gate)
        return isinstance(gate, self.gate)