def kraus( targets: QubitSetInput, matrices: Iterable[np.array], display_name: str = "KR" ) -> Iterable[Instruction]: """Registers this function into the circuit class. Args: targets (Qubit, int, or iterable of Qubit / int): Target qubit(s) matrices (Iterable[np.array]): Matrices that define a general noise channel. Returns: Iterable[Instruction]: `Iterable` of Kraus instructions. Examples: >>> K0 = np.eye(4) * sqrt(0.9) >>> K1 = np.kron([[1., 0.],[0., 1.]], [[0., 1.],[1., 0.]]) * sqrt(0.1) >>> circ = Circuit().kraus(0, matrices=[K0, K1]) """ if 2 ** len(targets) != matrices[0].shape[0]: raise ValueError( "Dimensions of the supplied Kraus matrices are incompatible with the targets" ) return Instruction( Noise.Kraus(matrices=matrices, display_name=display_name), target=targets )
def noise_2qubit(): E0 = np.sqrt(0.8) * np.eye(4) E1 = np.sqrt(0.2) * np.kron(np.array([[0, 1], [1, 0]]), np.array([[0, 1], [1, 0]])) return Noise.Kraus(matrices=[E0, E1])