Skip to content

Commit

Permalink
Fix RawFeatureVector for failing test case (#838)
Browse files Browse the repository at this point in the history
* Alter RawFeatureVector normalization

* Alter RawFeatureVector normalization
  • Loading branch information
woodsp-ibm authored Oct 9, 2024
1 parent b5e1c52 commit 2bc61a3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions qiskit_machine_learning/circuit/library/raw_feature_vector.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 @@ -176,7 +176,8 @@ def _define(self):
raise QiskitError("Cannot define a ParameterizedInitialize with unbound parameters")

# normalize
normalized = np.array(cleaned_params) / np.linalg.norm(cleaned_params)
norm = np.linalg.norm(cleaned_params)
normalized = cleaned_params if np.isclose(norm, 1) else cleaned_params / norm

circuit = QuantumCircuit(self.num_qubits)
circuit.initialize(normalized, range(self.num_qubits))
Expand Down

0 comments on commit 2bc61a3

Please sign in to comment.