def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs ) -> Optional[np.ndarray]: if cirq.is_parameterized(self): return None am = cirq.unitary(cirq.Rx(-np.pi * self.exponent * self.weights[0])) bm = cirq.unitary(cirq.Rx(-np.pi * self.exponent * self.weights[1])) cm = cirq.unitary(cirq.Rx(-np.pi * self.exponent * self.weights[2])) a1 = args.subspace_index(0b1001) b1 = args.subspace_index(0b0101) c1 = args.subspace_index(0b0011) a2 = args.subspace_index(0b0110) b2 = args.subspace_index(0b1010) c2 = args.subspace_index(0b1100) cirq.apply_matrix_to_slices(args.target_tensor, am, slices=[a1, a2], out=args.available_buffer) cirq.apply_matrix_to_slices(args.available_buffer, bm, slices=[b1, b2], out=args.target_tensor) return cirq.apply_matrix_to_slices(args.target_tensor, cm, slices=[c1, c2], out=args.available_buffer)
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Optional[np.ndarray]: if cirq.is_parameterized(self): return NotImplemented am, bm, cm = (la.expm(-1j * self.exponent * np.array([[0, w], [w.conjugate(), 0]])) for w in self.weights) a1 = args.subspace_index(0b1001) b1 = args.subspace_index(0b0101) c1 = args.subspace_index(0b0011) a2 = args.subspace_index(0b0110) b2 = args.subspace_index(0b1010) c2 = args.subspace_index(0b1100) cirq.apply_matrix_to_slices(args.target_tensor, am, slices=[a1, a2], out=args.available_buffer) cirq.apply_matrix_to_slices(args.available_buffer, bm, slices=[b1, b2], out=args.target_tensor) return cirq.apply_matrix_to_slices(args.target_tensor, cm, slices=[c1, c2], out=args.available_buffer)
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> Optional[np.ndarray]: if self.exponent != 1: return None oi = args.subspace_index(0b01) io = args.subspace_index(0b10) ii = args.subspace_index(0b11) args.available_buffer[oi] = args.target_tensor[oi] args.target_tensor[oi] = args.target_tensor[io] args.target_tensor[io] = args.available_buffer[oi] args.target_tensor[ii] *= -1 return args.target_tensor
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)
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)
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
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
def _apply_unitary_(self, args: cirq.ApplyUnitaryArgs) -> np.ndarray: one = args.subspace_index(1) args.target_tensor[one] *= -1 return args.target_tensor
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