def extrapolate_effect(self, factor: Union[float, value.Symbol] ) -> 'SingleQubitMatrixGate': if isinstance(factor, value.Symbol): raise TypeError('SingleQubitMatrixGate cannot be parameterized.') e = cast(float, factor) new_mat = linalg.map_eigenvalues(self.matrix(), lambda b: b**e) return SingleQubitMatrixGate(new_mat)
def recompose_kak(g, a, v, b) -> np.ndarray: a1, a0 = a x, y, z = v b1, b0 = b xx = linalg.kron(X, X) yy = linalg.kron(Y, Y) zz = linalg.kron(Z, Z) a = linalg.kron(a1, a0) m = linalg.map_eigenvalues(xx * x + yy * y + zz * z, lambda e: np.exp(1j * e)) b = linalg.kron(b1, b0) return linalg.dot(a, m, b) * g
def __pow__(self, exponent: Any) -> 'SingleQubitMatrixGate': if not isinstance(exponent, (int, float)): return NotImplemented e = cast(float, exponent) new_mat = linalg.map_eigenvalues(self._matrix, lambda b: b**e) return SingleQubitMatrixGate(new_mat)
def extrapolate_effect(self, factor: float): new_mat = linalg.map_eigenvalues(self.matrix(), lambda e: e**factor) return SingleQubitMatrixGate(new_mat)
]) * np.sqrt(0.5)), (1, 1, np.array([ [1, 0, 0, -1j], [0, 1, -1j, 0], [0, -1j, 1, 0], [-1j, 0, 0, 1], ]) * np.sqrt(0.5)), (1, 1, np.array([ [1, 0, 0, 1j], [0, 1, -1j, 0], [0, -1j, 1, 0], [1j, 0, 0, 1], ]) * np.sqrt(0.5)), (1.5, 3, linalg.map_eigenvalues(ops.SWAP.matrix(), lambda e: e**0.5)), (2, 2, ops.SWAP.matrix().dot(ops.CZ.matrix())), (3, 3, ops.SWAP.matrix()), (3, 3, np.array([ [0, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0], [1, 0, 0, 0j], ])), ] + [(1, 2, _random_single_partial_cz_effect()) for _ in range(10)] + [(2, 2, _random_double_full_cz_effect()) for _ in range(10)] + [(2, 3, _random_double_partial_cz_effect()) for _ in range(10)] + [(3, 3, testing.random_unitary(4)) for _ in range(10)])
def test_map_eigenvalues_raise(matrix, exponent, desired): exp_mapped = linalg.map_eigenvalues(matrix, lambda e: complex(e)**exponent) assert np.allclose(desired, exp_mapped)
def test_map_eigenvalues_identity(matrix): identity_mapped = linalg.map_eigenvalues(matrix, lambda e: e) assert np.allclose(matrix, identity_mapped)
def _unitary_power(matrix: np.ndarray, power: float) -> np.ndarray: return map_eigenvalues(matrix, lambda e: e**power)