Example #1
0
        def _apply_channel_(self, args: cirq.ApplyChannelArgs):
            zero_left = cirq.slice_for_qubits_equal_to(args.left_axes, 0)
            one_left = cirq.slice_for_qubits_equal_to(args.left_axes, 1)
            zero_right = cirq.slice_for_qubits_equal_to(args.right_axes, 0)
            one_right = cirq.slice_for_qubits_equal_to(args.right_axes, 1)
            args.out_buffer[:] = 0
            np.copyto(dst=args.auxiliary_buffer0, src=args.target_tensor)
            for krauss_op in [
                    np.sqrt(0.5) * np.eye(2, dtype=np.complex128),
                    np.sqrt(0.5) * x
            ]:
                np.copyto(dst=args.target_tensor, src=args.auxiliary_buffer0)
                cirq.apply_matrix_to_slices(args.target_tensor,
                                            krauss_op, [zero_left, one_left],
                                            out=args.auxiliary_buffer1)

                cirq.apply_matrix_to_slices(args.auxiliary_buffer1,
                                            np.conjugate(krauss_op),
                                            [zero_right, one_right],
                                            out=args.target_tensor)
                args.out_buffer += args.target_tensor
            return args.out_buffer
Example #2
0
 def _apply_channel_(self, args: cirq.ApplyChannelArgs):
     args.target_tensor = 0.5 * args.target_tensor + 0.5 * np.dot(
         np.dot(x, args.target_tensor), x)
     return args.target_tensor