Skip to content

Commit

Permalink
Update black (#173)
Browse files Browse the repository at this point in the history
Co-authored-by: Elena Peña Tapia <[email protected]>
  • Loading branch information
woodsp-ibm and ElePT authored May 6, 2024
1 parent 0bdd2dc commit 7f2c579
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 28 deletions.
10 changes: 6 additions & 4 deletions qiskit_algorithms/amplitude_estimators/ae_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions qiskit_algorithms/amplitude_estimators/estimation_problem.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"""
Expand Down
3 changes: 2 additions & 1 deletion qiskit_algorithms/gradients/reverse/bind.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -17,6 +17,7 @@

from qiskit.circuit import QuantumCircuit, Parameter


# pylint: disable=inconsistent-return-statements
def bind(
circuits: QuantumCircuit | Iterable[QuantumCircuit],
Expand Down
9 changes: 5 additions & 4 deletions qiskit_algorithms/minimum_eigensolvers/sampling_vqe.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion qiskit_algorithms/optimizers/aqgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
9 changes: 4 additions & 5 deletions qiskit_algorithms/optimizers/gradient_descent.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions qiskit_algorithms/optimizers/optimizer_utils/learning_rate.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions qiskit_algorithms/state_fidelities/base_state_fidelity.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions test/optimizers/test_optimizer_aqgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f2c579

Please sign in to comment.