From 7f2c5799bd518e0f68a22d1ad75283e87b38db0b Mon Sep 17 00:00:00 2001 From: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> Date: Mon, 6 May 2024 02:56:12 -0400 Subject: [PATCH] Update black (#173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com> --- qiskit_algorithms/amplitude_estimators/ae_utils.py | 10 ++++++---- .../amplitude_estimators/estimation_problem.py | 8 ++++---- qiskit_algorithms/gradients/reverse/bind.py | 3 ++- qiskit_algorithms/minimum_eigensolvers/sampling_vqe.py | 9 +++++---- qiskit_algorithms/optimizers/aqgd.py | 2 +- qiskit_algorithms/optimizers/gradient_descent.py | 9 ++++----- .../optimizers/optimizer_utils/learning_rate.py | 9 ++++----- .../state_fidelities/base_state_fidelity.py | 6 +++--- requirements-dev.txt | 2 +- test/optimizers/test_optimizer_aqgd.py | 1 + 10 files changed, 31 insertions(+), 28 deletions(-) diff --git a/qiskit_algorithms/amplitude_estimators/ae_utils.py b/qiskit_algorithms/amplitude_estimators/ae_utils.py index 85ebf998..6a601f43 100644 --- a/qiskit_algorithms/amplitude_estimators/ae_utils.py +++ b/qiskit_algorithms/amplitude_estimators/ae_utils.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2018, 2023. +# (C) Copyright IBM 2018, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -203,9 +203,11 @@ def pdf_a(x, p, m): # 0 and 1, respectively pr = np.array( [ - _pdf_a_single_angle(xi, p, m, _alpha) + _pdf_a_single_angle(xi, p, m, _beta) - if (xi not in [0, 1]) - else _pdf_a_single_angle(xi, p, m, _alpha) + ( + _pdf_a_single_angle(xi, p, m, _alpha) + _pdf_a_single_angle(xi, p, m, _beta) + if (xi not in [0, 1]) + else _pdf_a_single_angle(xi, p, m, _alpha) + ) for xi in x ] ).flatten() diff --git a/qiskit_algorithms/amplitude_estimators/estimation_problem.py b/qiskit_algorithms/amplitude_estimators/estimation_problem.py index 7bdd3afe..39ac0a2d 100644 --- a/qiskit_algorithms/amplitude_estimators/estimation_problem.py +++ b/qiskit_algorithms/amplitude_estimators/estimation_problem.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2020, 2023. +# (C) Copyright IBM 2020, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -36,9 +36,9 @@ def __init__( state_preparation: QuantumCircuit, objective_qubits: int | list[int], grover_operator: QuantumCircuit | None = None, - post_processing: Callable[[list[float]], list[float]] - | Callable[[float], float] - | None = None, + post_processing: ( + Callable[[list[float]], list[float]] | Callable[[float], float] | None + ) = None, is_good_state: Callable[[str], bool] | None = None, ) -> None: r""" diff --git a/qiskit_algorithms/gradients/reverse/bind.py b/qiskit_algorithms/gradients/reverse/bind.py index 146b35a6..e9c2be14 100644 --- a/qiskit_algorithms/gradients/reverse/bind.py +++ b/qiskit_algorithms/gradients/reverse/bind.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -17,6 +17,7 @@ from qiskit.circuit import QuantumCircuit, Parameter + # pylint: disable=inconsistent-return-statements def bind( circuits: QuantumCircuit | Iterable[QuantumCircuit], diff --git a/qiskit_algorithms/minimum_eigensolvers/sampling_vqe.py b/qiskit_algorithms/minimum_eigensolvers/sampling_vqe.py index 02bdbbdc..3d007452 100644 --- a/qiskit_algorithms/minimum_eigensolvers/sampling_vqe.py +++ b/qiskit_algorithms/minimum_eigensolvers/sampling_vqe.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -266,9 +266,10 @@ def _get_evaluate_energy( operator: BaseOperator, ansatz: QuantumCircuit, return_best_measurement: bool = False, - ) -> Callable[[np.ndarray], np.ndarray | float] | tuple[ - Callable[[np.ndarray], np.ndarray | float], dict[str, Any] - ]: + ) -> ( + Callable[[np.ndarray], np.ndarray | float] + | tuple[Callable[[np.ndarray], np.ndarray | float], dict[str, Any]] + ): """Returns a function handle to evaluate the energy at given parameters. This is the objective function to be passed to the optimizer that is used for evaluation. diff --git a/qiskit_algorithms/optimizers/aqgd.py b/qiskit_algorithms/optimizers/aqgd.py index 43f68540..f821fd5d 100644 --- a/qiskit_algorithms/optimizers/aqgd.py +++ b/qiskit_algorithms/optimizers/aqgd.py @@ -325,7 +325,7 @@ def minimize( logger.info("Initial Params: %s", params) epoch = 0 converged = False - for (eta, mom_coeff) in zip(self._eta, self._momenta_coeff): + for eta, mom_coeff in zip(self._eta, self._momenta_coeff): logger.info("Epoch: %4d | Stepsize: %6.4f | Momentum: %6.4f", epoch, eta, mom_coeff) sum_max_iters = sum(self._maxiter[0 : epoch + 1]) diff --git a/qiskit_algorithms/optimizers/gradient_descent.py b/qiskit_algorithms/optimizers/gradient_descent.py index d9561b19..0f79abb1 100644 --- a/qiskit_algorithms/optimizers/gradient_descent.py +++ b/qiskit_algorithms/optimizers/gradient_descent.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2021, 2023. +# (C) Copyright IBM 2021, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -177,10 +177,9 @@ def grad(x): def __init__( self, maxiter: int = 100, - learning_rate: float - | list[float] - | np.ndarray - | Callable[[], Generator[float, None, None]] = 0.01, + learning_rate: ( + float | list[float] | np.ndarray | Callable[[], Generator[float, None, None]] + ) = 0.01, tol: float = 1e-7, callback: CALLBACK | None = None, perturbation: float | None = None, diff --git a/qiskit_algorithms/optimizers/optimizer_utils/learning_rate.py b/qiskit_algorithms/optimizers/optimizer_utils/learning_rate.py index 3cb07077..a9c15949 100644 --- a/qiskit_algorithms/optimizers/optimizer_utils/learning_rate.py +++ b/qiskit_algorithms/optimizers/optimizer_utils/learning_rate.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2021, 2023. +# (C) Copyright IBM 2021, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -29,10 +29,9 @@ class LearningRate(Generator): def __init__( self, - learning_rate: float - | list[float] - | np.ndarray - | Callable[[], Generator[float, None, None]], + learning_rate: ( + float | list[float] | np.ndarray | Callable[[], Generator[float, None, None]] + ), ): """ Args: diff --git a/qiskit_algorithms/state_fidelities/base_state_fidelity.py b/qiskit_algorithms/state_fidelities/base_state_fidelity.py index 4ca041ed..5c1199c4 100644 --- a/qiskit_algorithms/state_fidelities/base_state_fidelity.py +++ b/qiskit_algorithms/state_fidelities/base_state_fidelity.py @@ -1,6 +1,6 @@ # This code is part of a Qiskit project. # -# (C) Copyright IBM 2022, 2023. +# (C) Copyright IBM 2022, 2024. # # This code is licensed under the Apache License, Version 2.0. You may # obtain a copy of this license in the LICENSE.txt file in the root directory @@ -171,7 +171,7 @@ def _construct_circuits( ) circuits = [] - for (circuit_1, circuit_2) in zip(circuits_1, circuits_2): + for circuit_1, circuit_2 in zip(circuits_1, circuits_2): # Use the same key for circuits as qiskit.primitives use. circuit = self._circuit_cache.get((_circuit_key(circuit_1), _circuit_key(circuit_2))) @@ -230,7 +230,7 @@ def _construct_value_list( elif len(values_1[0]) == 0: values = list(values_2) else: - for (val_1, val_2) in zip(values_1, values_2): + for val_1, val_2 in zip(values_1, values_2): # the `+` operation concatenates the lists # and then this new list gets appended to the values list values.append(val_1 + val_2) diff --git a/requirements-dev.txt b/requirements-dev.txt index 5dd72b40..de2bf625 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1,7 @@ coverage>=4.4.0,<7.0 matplotlib>=3.3 jupyter -black[jupyter]~=22.0 +black[jupyter]~=24.1 pylint>=2.15.0 stestr>=2.0.0 pylatexenc>=1.4 diff --git a/test/optimizers/test_optimizer_aqgd.py b/test/optimizers/test_optimizer_aqgd.py index abb2da3b..a2d4a1f0 100644 --- a/test/optimizers/test_optimizer_aqgd.py +++ b/test/optimizers/test_optimizer_aqgd.py @@ -114,6 +114,7 @@ def test_max_grouped_evals_parallelizable(self, max_grouped_evals): def test_max_grouped_evals_non_parallelizable(self): """Tests max_grouped_evals for an objective function that cannot be parallelized""" + # Define the objective function (toy example for functionality) def quadratic_objective(x: np.ndarray) -> float: # Check if only a single point as parameters is passed