Ejemplo n.º 1
0
    def _apply_unitary_(
            self, args: cirq.ApplyUnitaryArgs
    ) -> Union[np.ndarray, NotImplementedType]:
        if self.exponent != 1 or cirq.is_parameterized(self):
            # coverage: ignore
            return NotImplemented

        zero = cirq.slice_for_qubits_equal_to(args.axes, 0)
        one = cirq.slice_for_qubits_equal_to(args.axes, 1)
        c = np.exp(1j * np.pi * self.phase_exponent)

        args.target_tensor[one] *= c
        args.available_buffer[zero] = args.target_tensor[one]
        args.available_buffer[one] = args.target_tensor[zero]
        args.available_buffer[one] *= c

        return args.available_buffer
Ejemplo n.º 2
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs
                     ) -> Optional[np.ndarray]:
     if cirq.is_parameterized(self):
         return None
     inner_matrix = cirq.unitary(cirq.rx(-2 * np.pi * self.exponent))
     a = args.subspace_index(0b0011)
     b = args.subspace_index(0b1100)
     return cirq.apply_matrix_to_slices(args.target_tensor,
                                        inner_matrix,
                                        slices=[a, b],
                                        out=args.available_buffer)
Ejemplo n.º 3
0
 def _apply_unitary_(self,
                     args: cirq.ApplyUnitaryArgs) -> Optional[np.ndarray]:
     if cirq.is_parameterized(self):
         return None
     inner_matrix = cirq.unitary(cirq.Ry(-self.exponent * np.pi))
     oi = args.subspace_index(0b01)
     io = args.subspace_index(0b10)
     return cirq.apply_matrix_to_slices(args.target_tensor,
                                        inner_matrix,
                                        slices=[oi, io],
                                        out=args.available_buffer)
Ejemplo n.º 4
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
     i = args.subspace_index(1)
     args.target_tensor[i] *= self.power * 2
     return args.target_tensor
Ejemplo n.º 5
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
     o = args.subspace_index(0)
     i = args.subspace_index(1)
     args.available_buffer[o] = args.target_tensor[i]
     args.available_buffer[i] = args.target_tensor[o]
     return args.available_buffer
Ejemplo n.º 6
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
     args.available_buffer[0] = args.target_tensor[1]
     args.available_buffer[1] = args.target_tensor[0]
     return args.available_buffer
Ejemplo n.º 7
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
     one = args.subspace_index(1)
     args.target_tensor[one] *= -1
     return args.target_tensor
Ejemplo n.º 8
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray:
     zero = args.subspace_index(0)
     one = args.subspace_index(1)
     args.available_buffer[zero] = args.target_tensor[zero]
     args.available_buffer[one] = -args.target_tensor[one]
     return args.available_buffer
Ejemplo n.º 9
0
 def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs):
     args.target_tensor[0], args.target_tensor[1] = (
         args.target_tensor[1],
         args.target_tensor[0],
     )
     return args.target_tensor