Skip to content

Fixes mypy failure with latest mypy 1.16.0 #944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, 2024.
# (C) Copyright IBM 2022, 2025.
#
# 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 @@ -233,7 +233,9 @@ def _run_unique(
gradient.imag = results[partial_sum_n + n // 2 : partial_sum_n + n]

else:
gradient = np.real(results[partial_sum_n : partial_sum_n + n])
gradient = np.real(
results[partial_sum_n : partial_sum_n + n]
) # type: ignore[assignment, unused-ignore]
partial_sum_n += n
gradients.append(gradient)

Expand Down
20 changes: 12 additions & 8 deletions qiskit_machine_learning/neural_networks/effective_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,20 @@ def __init__(
"""

# Store arguments
self._weight_samples = None
self._input_samples = None
self._num_weight_samples = 1
self._num_input_samples = 1
self._weight_samples = np.asarray([0.25])
self._input_samples = np.asarray([0.5])
self._num_weight_samples = len(self._weight_samples)
self._num_input_samples = len(self._input_samples)
self._model = qnn

# Define weight samples and input samples
self.weight_samples = weight_samples # type: ignore
# input setter uses self._model
self.input_samples = input_samples # type: ignore
# Setup things for weight and input samples via setters that deal
# with the union of types that can be passed so that the private
# vars above that have just been set with temp values of right types
# to establish typing, get the right values per what was passed.
# Note, the samples ones above had been set to None but this results
# in errors when checking using mypy 1.16.0
self.weight_samples = weight_samples
self.input_samples = input_samples

@property
def weight_samples(self) -> np.ndarray:
Expand Down
4 changes: 2 additions & 2 deletions qiskit_machine_learning/variational_algorithm.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 2019, 2024.
# (C) Copyright IBM 2019, 2025.
#
# 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 @@ -91,7 +91,7 @@ def optimal_value(self) -> float | None:
return self._optimal_value

@optimal_value.setter
def optimal_value(self, value: int) -> None:
def optimal_value(self, value: float) -> None:
"""Sets optimal value"""
self._optimal_value = value

Expand Down