Skip to content

Commit bbe62be

Browse files
committed
Initial ruff pass
Fixed remaining ruff errors
1 parent da7cab8 commit bbe62be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+108
-104
lines changed

docs/tutorials/01_algorithms_introduction.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
"source": [
323323
"def callback(**kwargs):\n",
324324
" if kwargs[\"count\"] == 0:\n",
325-
" print(f\"Callback function has been called!\")"
325+
" print(\"Callback function has been called!\")"
326326
]
327327
},
328328
{

docs/tutorials/05_qaoa.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@
208208
],
209209
"source": [
210210
"from qiskit.primitives import StatevectorSampler\n",
211-
"from qiskit.quantum_info import Pauli\n",
212211
"from qiskit.result import QuasiDistribution\n",
213212
"\n",
214213
"from qiskit_algorithms import QAOA\n",
@@ -375,7 +374,7 @@
375374
"source": [
376375
"def callback(**kwargs):\n",
377376
" if kwargs[\"count\"] == 0:\n",
378-
" print(f\"Callback function has been called!\")"
377+
" print(\"Callback function has been called!\")"
379378
]
380379
},
381380
{

docs/tutorials/06_grover.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@
747747
"source": [
748748
"def callback(**kwargs):\n",
749749
" if kwargs[\"count\"] == 0:\n",
750-
" print(f\"Callback function has been called!\")"
750+
" print(\"Callback function has been called!\")"
751751
]
752752
},
753753
{

docs/tutorials/10_pvqd.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@
692692
},
693693
{
694694
"cell_type": "code",
695-
"execution_count": 10,
695+
"execution_count": null,
696696
"metadata": {},
697697
"outputs": [],
698698
"source": [
@@ -701,7 +701,6 @@
701701
"\n",
702702
"def exact(final_time, timestep, hamiltonian, initial_state):\n",
703703
" \"\"\"Get the exact values for energy and the observable.\"\"\"\n",
704-
" O = observable.to_matrix()\n",
705704
" H = hamiltonian.to_matrix()\n",
706705
"\n",
707706
" energ, magn = [], [] # list of energies and magnetizations evaluated at timesteps timestep\n",

qiskit_algorithms/amplitude_amplifiers/amplification_problem.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from __future__ import annotations
1515

1616
from collections.abc import Callable
17-
from typing import Any, List, cast
17+
from typing import Any, cast
1818

1919
from qiskit.circuit import QuantumCircuit, Gate
2020
from qiskit.circuit.library import GroverOperator
@@ -177,10 +177,10 @@ def is_good_state(self) -> Callable[[str], bool]:
177177
return self._is_good_state # returns None if no is_good_state arg has been set
178178
elif isinstance(self._is_good_state, list):
179179
if all(isinstance(good_bitstr, str) for good_bitstr in self._is_good_state):
180-
return lambda bitstr: bitstr in cast(List[str], self._is_good_state)
180+
return lambda bitstr: bitstr in cast(list[str], self._is_good_state)
181181
else:
182182
return lambda bitstr: all(
183-
bitstr[good_index] == "1" for good_index in cast(List[int], self._is_good_state)
183+
bitstr[good_index] == "1" for good_index in cast(list[int], self._is_good_state)
184184
)
185185

186186
return lambda bitstr: bitstr in cast(Statevector, self._is_good_state).probabilities_dict()

qiskit_algorithms/amplitude_amplifiers/amplitude_amplifier.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2021, 2023.
3+
# (C) Copyright IBM 2021, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -24,7 +24,7 @@ class AmplitudeAmplifier(ABC):
2424
"""The interface for amplification algorithms."""
2525

2626
@abstractmethod
27-
def amplify(self, amplification_problem: AmplificationProblem) -> "AmplitudeAmplifierResult":
27+
def amplify(self, amplification_problem: AmplificationProblem) -> AmplitudeAmplifierResult:
2828
"""Run the amplification algorithm.
2929
3030
Args:

qiskit_algorithms/amplitude_amplifiers/grover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def sampler(self, sampler: BaseSamplerV2) -> None:
192192
"""
193193
self._sampler = sampler
194194

195-
def amplify(self, amplification_problem: AmplificationProblem) -> "GroverResult":
195+
def amplify(self, amplification_problem: AmplificationProblem) -> GroverResult:
196196
"""Run the Grover algorithm.
197197
198198
Args:

qiskit_algorithms/amplitude_estimators/ae.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _evaluate_count_results(self, counts) -> tuple[dict[float, float], dict[int,
228228

229229
@staticmethod
230230
def compute_mle(
231-
result: "AmplitudeEstimationResult", apply_post_processing: bool = False
231+
result: AmplitudeEstimationResult, apply_post_processing: bool = False
232232
) -> float:
233233
"""Compute the Maximum Likelihood Estimator (MLE).
234234
@@ -285,7 +285,7 @@ def loglikelihood(a):
285285

286286
return a_opt
287287

288-
def estimate(self, estimation_problem: EstimationProblem) -> "AmplitudeEstimationResult":
288+
def estimate(self, estimation_problem: EstimationProblem) -> AmplitudeEstimationResult:
289289
"""Run the amplitude estimation algorithm on provided estimation problem.
290290
291291
Args:
@@ -379,7 +379,7 @@ def estimate(self, estimation_problem: EstimationProblem) -> "AmplitudeEstimatio
379379

380380
@staticmethod
381381
def compute_confidence_interval(
382-
result: "AmplitudeEstimationResult",
382+
result: AmplitudeEstimationResult,
383383
alpha: float = 0.05,
384384
kind: str = "likelihood_ratio",
385385
) -> tuple[float, float]:

qiskit_algorithms/amplitude_estimators/amplitude_estimator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2018, 2023.
3+
# (C) Copyright IBM 2018, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -24,7 +24,7 @@ class AmplitudeEstimator(ABC):
2424
"""The Amplitude Estimation interface."""
2525

2626
@abstractmethod
27-
def estimate(self, estimation_problem: EstimationProblem) -> "AmplitudeEstimatorResult":
27+
def estimate(self, estimation_problem: EstimationProblem) -> AmplitudeEstimatorResult:
2828
"""Run the amplitude estimation algorithm.
2929
3030
Args:

qiskit_algorithms/amplitude_estimators/estimation_problem.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This code is part of a Qiskit project.
22
#
3-
# (C) Copyright IBM 2020, 2024.
3+
# (C) Copyright IBM 2020, 2025.
44
#
55
# This code is licensed under the Apache License, Version 2.0. You may
66
# obtain a copy of this license in the LICENSE.txt file in the root directory
@@ -202,7 +202,7 @@ def grover_operator(self, grover_operator: QuantumCircuit | None) -> None:
202202
"""
203203
self._grover_operator = grover_operator
204204

205-
def rescale(self, scaling_factor: float) -> "EstimationProblem":
205+
def rescale(self, scaling_factor: float) -> EstimationProblem:
206206
"""Rescale the good state amplitude in the estimation problem.
207207
208208
Args:

0 commit comments

Comments
 (0)