Skip to content

Commit 1d03d4f

Browse files
oscar-wallisedoaltamuraFrancescaSchiavOkuyanBogadeclanmillar
authored
Prep-ing for 0.8 (#53)
* Migrating `qiskit_algorithms` (qiskit-community#817) * Update README.md * Generalize the Einstein summation signature * Add reno * Update Copyright * Rename and add test * Update Copyright * Add docstring for `test_get_einsum_signature` * Correct spelling * Disable spellcheck for comments * Add `docstring` in pylint dict * Delete example in docstring * Add Einstein in pylint dict * Add full use case in einsum dict * Spelling and type ignore * Spelling and type ignore * Spelling and type ignore * Spelling and type ignore * Spelling and type ignore * Remove for loop in einsum function and remove Literal arguments (1/2) * Remove for loop in einsum function and remove Literal arguments (1/2) * Remove for loop in einsum function and remove Literal arguments (2/2) * Update RuntimeError msg * Update RuntimeError msg - line too long * Trigger CI * Merge algos, globals.random to fix * Fixed `algorithms_globals` * Import /tests and run CI locally * Fix copyrights and some spellings * Ignore mypy in 8 instances * Merge spell dicts * Black reformatting * Black reformatting * Add reno * Lint sanitize * Pylint * Pylint * Pylint * Pylint * Fix relative imports in tutorials * Fix relative imports in tutorials * Remove algorithms from Jupyter magic methods * Temporarily disable "Run stable tutorials" tests * Change the docstrings with imports from qiskit_algorithms * Styling * Update qiskit_machine_learning/optimizers/gradient_descent.py Co-authored-by: Declan Millar <[email protected]> * Update qiskit_machine_learning/optimizers/optimizer_utils/learning_rate.py Co-authored-by: Declan Millar <[email protected]> * Add more tests for utils * Add more tests for optimizers: adam, bobyqa, gsls and imfil * Fix random seed for volatile optimizers * Fix random seed for volatile optimizers * Add more tests * Pylint dict * Activate scikit-quant-0.8.2 * Remove scikit-quant methods * Remove scikit-quant methods (2) * Edit the release notes and Qiskit version 1+ * Edit the release notes and Qiskit version 1+ * Add Qiskit 1.0 upgrade in reno * Add Qiskit 1.0 upgrade in reno * Add Qiskit 1.0 upgrade in reno * Apply line breaks * Restructure line breaks --------- Co-authored-by: FrancescaSchiav <[email protected]> Co-authored-by: M. Emre Sahin <[email protected]> Co-authored-by: Declan Millar <[email protected]> * Revamp readme pt2 (qiskit-community#822) * Restructure README.md --------- Co-authored-by: Steve Wood <[email protected]> * Fix lint errors due to Pylint 3.3.0 update in CI (qiskit-community#833) * disable=too-many-positional-arguments * Transfer pylint rc to toml * Transfer pylint rc to toml * Remove Python 3.8 from CI (qiskit-community#824) (qiskit-community#826) * Remove Python 3.8 in CI (qiskit-community#824) * Correct `tmp` dirs (qiskit-community#818) * Correct unit py version (qiskit-community#818) * Add reno (qiskit-community#818) * Finalze removal of py38 (qiskit-community#818) * Spelling * Remove duplicate tmp folder * Updated the release note * Bump min pyversion in toml * Remove ipython constraints * Update reno * Reestablish latest Pytorch and Numpy (qiskit-community#818) (qiskit-community#827) * Reestablish latest Pytorch and Numpy (qiskit-community#818) * Keep pinned Numpy * Keep pinned Numpy * Fix numpy min version * Fix RawFeatureVector for failing test case (qiskit-community#838) * Alter RawFeatureVector normalization * Alter RawFeatureVector normalization * Release nbconvert constraints (qiskit-community#842) * Remove redundant MacOS 14 image in CI (qiskit-community#841) * Remove redundant MacOS 14 image * Update with macos-latest-large * Revert "Update with macos-latest-large" This reverts commit 14f945e. * Update with macos-latest-large * Update v2 (#54) * bugfix for V1 * formatting --------- Co-authored-by: oscar-wallis <[email protected]> --------- Co-authored-by: Edoardo Altamura <[email protected]> Co-authored-by: FrancescaSchiav <[email protected]> Co-authored-by: M. Emre Sahin <[email protected]> Co-authored-by: Declan Millar <[email protected]> Co-authored-by: Steve Wood <[email protected]>
1 parent 9a6574b commit 1d03d4f

File tree

6 files changed

+15
-7
lines changed

6 files changed

+15
-7
lines changed

constraints.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
numpy>=1.20
1+
numpy>=1.20

qiskit_machine_learning/circuit/library/raw_feature_vector.py

+3-2
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, 2023.
3+
# (C) Copyright IBM 2020, 2024.
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
@@ -176,7 +176,8 @@ def _define(self):
176176
raise QiskitError("Cannot define a ParameterizedInitialize with unbound parameters")
177177

178178
# normalize
179-
normalized = np.array(cleaned_params) / np.linalg.norm(cleaned_params)
179+
norm = np.linalg.norm(cleaned_params)
180+
normalized = cleaned_params if np.isclose(norm, 1) else cleaned_params / norm
180181

181182
circuit = QuantumCircuit(self.num_qubits)
182183
circuit.initialize(normalized, range(self.num_qubits))

qiskit_machine_learning/gradients/base/base_sampler_gradient.py

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(
6161
self._default_options = Options()
6262
self._pass_manager = pass_manager
6363
self._len_quasi_dist = len_quasi_dist
64+
6465
if options is not None:
6566
self._default_options.update_options(**options)
6667
self._gradient_circuit_cache: dict[tuple, GradientCircuit] = {}

qiskit_machine_learning/neural_networks/estimator_qnn.py

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
EstimatorGradientResult,
3232
ParamShiftEstimatorGradient,
3333
)
34+
3435
from ..circuit.library import QNNCircuit
3536
from ..exceptions import QiskitMachineLearningError
3637

@@ -323,9 +324,11 @@ def _backward(
323324
job = None
324325

325326
if self._input_gradients:
327+
326328
job = self.gradient.run(
327329
circuits, observables, param_values
328330
) # type: ignore[arg-type]
331+
329332
elif len(parameter_values[0]) > self._num_inputs:
330333
params = [self._circuit.parameters[self._num_inputs :]] * num_circuits
331334
job = self.gradient.run(

qiskit_machine_learning/neural_networks/sampler_qnn.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from .neural_network import NeuralNetwork
3939

40+
4041
if _optionals.HAS_SPARSE:
4142
# pylint: disable=import-error
4243
from sparse import SparseArray
@@ -349,7 +350,6 @@ def _postprocess_gradient(
349350
)
350351
weights_grad = DOK((num_samples, *self._output_shape, self._num_weights))
351352
else:
352-
353353
input_grad = (
354354
np.zeros((num_samples, *self._output_shape, self._num_inputs))
355355
if self._input_gradients
@@ -441,10 +441,12 @@ def _backward(
441441
circuits = [self._circuit] * num_samples
442442
job = None
443443
if self._input_gradients:
444-
job = self.gradient.run(circuits, parameter_values)
444+
job = self.gradient.run(circuits, parameter_values) # type: ignore[arg-type]
445445
elif len(parameter_values[0]) > self._num_inputs:
446446
params = [self._circuit.parameters[self._num_inputs :]] * num_samples
447-
job = self.gradient.run(circuits, parameter_values, parameters=params)
447+
job = self.gradient.run(
448+
circuits, parameter_values, parameters=params # type: ignore[arg-type]
449+
)
448450

449451
if job is not None:
450452
try:

qiskit_machine_learning/state_fidelities/compute_uncompute.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from copy import copy
1919

2020
from qiskit import QuantumCircuit
21-
2221
from qiskit.primitives import BaseSampler, BaseSamplerV1, SamplerResult, StatevectorSampler
2322
from qiskit.primitives.base import BaseSamplerV2
2423

@@ -29,6 +28,7 @@
2928
from qiskit.providers import Options
3029

3130
from ..exceptions import AlgorithmError, QiskitMachineLearningError
31+
3232
from .base_state_fidelity import BaseStateFidelity
3333
from .state_fidelity_result import StateFidelityResult
3434
from ..algorithm_job import AlgorithmJob
@@ -180,6 +180,7 @@ def _run(
180180
# primitive's default options.
181181
opts = copy(self._default_options)
182182
opts.update_options(**options)
183+
183184
if isinstance(self._sampler, BaseSamplerV1):
184185
sampler_job = self._sampler.run(
185186
circuits=circuits, parameter_values=values, **opts.__dict__

0 commit comments

Comments
 (0)