def test_cx_coherent_error_matrix(self): CX = np.array([[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]]) U = cx_error_matrix(0., 0.).dot(CX) target = CX self.assertAlmostEqual(norm(U - target), 0.0, places=10, msg="identity error matrix") U = cx_error_matrix(np.pi / 2., 0.).dot(CX) target = np.array([[1, 0, 1j, 0], [0, -1j, 0, 1], [1j, 0, 1, 0], [0, 1, 0, -1j]]) / np.sqrt(2) self.assertAlmostEqual(norm(U - target), 0.0, places=10) U = cx_error_matrix(0.03, -0.04) self.assertAlmostEqual(norm(U.dot(U.conj().T) - np.eye(4)), 0.0, places=10, msg="Test error matrix is unitary")