diff --git a/src/qibo/quantum_info/entropies.py b/src/qibo/quantum_info/entropies.py index f859e07567..be3eaaec21 100644 --- a/src/qibo/quantum_info/entropies.py +++ b/src/qibo/quantum_info/entropies.py @@ -783,9 +783,7 @@ def renyi_entropy(state, alpha: Union[float, int], base: float = 2, backend=None if alpha == np.inf: return ( -1 - * backend.np.log2( - backend.calculate_matrix_norm(state, order=2) - ) + * backend.np.log2(backend.calculate_matrix_norm(state, order=2)) / np.log2(base) ) @@ -892,9 +890,7 @@ def relative_renyi_entropy( new_target = matrix_power(target, 0.5, backend=backend) log = backend.np.log2( - backend.calculate_matrix_norm( - new_state @ new_target, order=1 - ) + backend.calculate_matrix_norm(new_state @ new_target, order=1) ) return -2 * log / np.log2(base) diff --git a/src/qibo/quantum_info/metrics.py b/src/qibo/quantum_info/metrics.py index 2bd97a595c..6ba3997583 100644 --- a/src/qibo/quantum_info/metrics.py +++ b/src/qibo/quantum_info/metrics.py @@ -929,9 +929,7 @@ def _check_hermitian(matrix, backend=None): """ backend = _check_backend(backend) - norm = backend.calculate_matrix_norm( - backend.np.conj(matrix).T - matrix, order=2 - ) + norm = backend.calculate_matrix_norm(backend.np.conj(matrix).T - matrix, order=2) hermitian = bool(float(norm) <= PRECISION_TOL) diff --git a/src/qibo/quantum_info/superoperator_transformations.py b/src/qibo/quantum_info/superoperator_transformations.py index de3d1e4c53..2f38caf1c7 100644 --- a/src/qibo/quantum_info/superoperator_transformations.py +++ b/src/qibo/quantum_info/superoperator_transformations.py @@ -2132,9 +2132,7 @@ def function(x0, operators): for prob, oper in zip(x0, operators): operator = operator + prob * oper - return float( - backend.calculate_matrix_norm(target - operator, order=2) - ) + return float(backend.calculate_matrix_norm(target - operator, order=2)) # initial parameters as flat distribution x0 = [1.0 / (len(kraus_ops) + 1)] * len(kraus_ops) diff --git a/src/qibo/transpiler/unitary_decompositions.py b/src/qibo/transpiler/unitary_decompositions.py index 02668fa7b2..b31560373b 100644 --- a/src/qibo/transpiler/unitary_decompositions.py +++ b/src/qibo/transpiler/unitary_decompositions.py @@ -97,9 +97,7 @@ def calculate_single_qubit_unitaries(psi, backend=None): """ psi_magic = backend.np.matmul(backend.np.conj(backend.cast(magic_basis)).T, psi) if ( - backend.np.real( - backend.calculate_matrix_norm(backend.np.imag(psi_magic)) - ) + backend.np.real(backend.calculate_matrix_norm(backend.np.imag(psi_magic))) > 1e-6 ): # pragma: no cover raise_error(NotImplementedError, "Given state is not real in the magic basis.") diff --git a/tests/test_gates_channels.py b/tests/test_gates_channels.py index 13bb6a3923..a16a3f5441 100644 --- a/tests/test_gates_channels.py +++ b/tests/test_gates_channels.py @@ -383,11 +383,7 @@ def test_thermal_relaxation_channel(backend, t_1, t_2, time, excpop): target_state = backend.cast(target_state, dtype=target_state.dtype) backend.assert_allclose( - float( - backend.calculate_matrix_norm( - final_state - target_state, order=2 - ) - ) + float(backend.calculate_matrix_norm(final_state - target_state, order=2)) < PRECISION_TOL, True, ) diff --git a/tests/test_quantum_info_entropies.py b/tests/test_quantum_info_entropies.py index 6fe04d756d..9eff0e01fe 100644 --- a/tests/test_quantum_info_entropies.py +++ b/tests/test_quantum_info_entropies.py @@ -687,9 +687,7 @@ def test_relative_renyi_entropy(backend, alpha, base, state_flag, target_flag): new_target = matrix_power(target_outer, 0.5, backend=backend) log = backend.np.log2( - backend.calculate_matrix_norm( - new_state @ new_target, order=1 - ) + backend.calculate_matrix_norm(new_state @ new_target, order=1) ) log = -2 * log / np.log2(base) diff --git a/tests/test_quantum_info_random.py b/tests/test_quantum_info_random.py index 84c4216353..30573897bb 100644 --- a/tests/test_quantum_info_random.py +++ b/tests/test_quantum_info_random.py @@ -112,18 +112,14 @@ def test_random_hermitian(backend): dims = 4 matrix = random_hermitian(dims, backend=backend) matrix_dagger = backend.np.conj(matrix).T - norm = float( - backend.calculate_matrix_norm(matrix - matrix_dagger, order=2) - ) + norm = float(backend.calculate_matrix_norm(matrix - matrix_dagger, order=2)) backend.assert_allclose(norm < PRECISION_TOL, True) # test if function returns semidefinite Hermitian operator dims = 4 matrix = random_hermitian(dims, semidefinite=True, backend=backend) matrix_dagger = backend.np.conj(matrix).T - norm = float( - backend.calculate_matrix_norm(matrix - matrix_dagger, order=2) - ) + norm = float(backend.calculate_matrix_norm(matrix - matrix_dagger, order=2)) backend.assert_allclose(norm < PRECISION_TOL, True) eigenvalues = np.linalg.eigvalsh(backend.to_numpy(matrix)) @@ -134,9 +130,7 @@ def test_random_hermitian(backend): dims = 4 matrix = random_hermitian(dims, normalize=True, backend=backend) matrix_dagger = backend.np.conj(matrix).T - norm = float( - backend.calculate_matrix_norm(matrix - matrix_dagger, order=2) - ) + norm = float(backend.calculate_matrix_norm(matrix - matrix_dagger, order=2)) backend.assert_allclose(norm < PRECISION_TOL, True) eigenvalues = np.linalg.eigvalsh(backend.to_numpy(matrix)) @@ -183,11 +177,7 @@ def test_random_unitary(backend, measure): if backend.name == "pytorch" else np.linalg.inv(matrix) ) - norm = float( - backend.calculate_matrix_norm( - matrix_inv - matrix_dagger, order=2 - ) - ) + norm = float(backend.calculate_matrix_norm(matrix_inv - matrix_dagger, order=2)) backend.assert_allclose(norm < PRECISION_TOL, True) @@ -283,9 +273,7 @@ def test_random_density_matrix(backend, dims, pure, metric, basis, normalize): test = random_density_matrix(dims=dims, normalize=True) else: norm_function = ( - backend.calculate_matrix_norm - if basis is None - else backend.calculate_norm + backend.calculate_matrix_norm if basis is None else backend.calculate_norm ) state = random_density_matrix( dims, @@ -423,9 +411,7 @@ def test_pauli_single(backend): backend.assert_allclose( np.abs( - backend.to_numpy( - backend.calculate_matrix_norm(matrix - result, order=2) - ) + backend.to_numpy(backend.calculate_matrix_norm(matrix - result, order=2)) ) < PRECISION_TOL, True, @@ -465,20 +451,14 @@ def test_random_pauli( if subset is None: backend.assert_allclose( float( - backend.calculate_matrix_norm( - matrix - result_complete_set, order=2 - ) + backend.calculate_matrix_norm(matrix - result_complete_set, order=2) ) < PRECISION_TOL, True, ) else: backend.assert_allclose( - float( - backend.calculate_matrix_norm( - matrix - result_subset, order=2 - ) - ) + float(backend.calculate_matrix_norm(matrix - result_subset, order=2)) < PRECISION_TOL, True, ) @@ -490,20 +470,14 @@ def test_random_pauli( if subset is None: backend.assert_allclose( float( - backend.calculate_matrix_norm( - matrix - result_complete_set, order=2 - ) + backend.calculate_matrix_norm(matrix - result_complete_set, order=2) ) < PRECISION_TOL, True, ) else: backend.assert_allclose( - float( - backend.calculate_matrix_norm( - matrix - result_subset, order=2 - ) - ) + float(backend.calculate_matrix_norm(matrix - result_subset, order=2)) < PRECISION_TOL, True, )