Qiskit-machine-learning

Latest version: v0.8.2

Safety actively analyzes 706259 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 3

0.8.2

What's Changed
* Fixed a compatibility issue for different `callback` functions when they are used in `qiskit_machine_learning.algorithms.trainable_model` based algorithms.
* Updated documentation for `SamplerQNN`, improving the description on using interpret functions and output shapes.
* Extended support for different V2 transpilers from different backends.
* Extended support with Qiskit 1.3.x (latest at the time of release).

> [!NOTE]
> We continue to support the `BlueprintCircuit` implementation of derived circuit classes until the next major release of Qiskit Machine Learning.

0.8.1

New Features

- Enhanced Tutorials and Documentation for V2 Primitives, including a [migration guide for V2 primitives](https://qiskit-community.github.io/qiskit-machine-learning/migration/02_migration_guide_0.8.html).

- Extended support for V2 primitives across various quantum machine learning algorithms including [VQC](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html), [VQR](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQR.html), [QSVC](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html), [QSVR](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html), and [QBayesian](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QBayesian.html). If no primitive is provided, these algorithms will default to using V1 primitives as a fallback for this release. A warning is now issued to inform users of this default behavior.

- Added partial multi-class support for [VQC](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html). This feature is now enabled when the output_shape parameter is set to num_classes and an interpret function is defined, allowing for multi-label classification tasks.

- The [PegasosQSVC](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.PegasosQSVC.html) and algorithms derived from [NeuralNetworkClassifier](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkClassifier.html) module now support predict_proba function. This method can be utilized similarly to other scikit-learn-based algorithms.


- The [ADAM](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.optimizers.ADAM.html#qiskit_machine_learning.optimizers.ADAM) class now supports a callback function. This feature allows users to pass a custom callback function that will be called with information at each iteration step during the optimization process. The information passed to the callback includes the current time step, the parameters, and the function value. The callback function should be of the type `Callable[[int, Union[float, np.ndarray], float], None]`. Example of a callback function:

python
def callback(iteration:int, weights:np.ndarray, loss:float):
...
acc = calculate_accuracy(weights)
print(acc)
print(loss)
...

0.8.0

Prelude to the changelog

From this release, Qiskit Machine Learning requires Qiskit `1.0` or above, with important changes and upgrades, such as introducing Quantum Bayesian inference and migrating a subset of Qiskit Algorithms features to Qiskit Machine Learning. These changes are part of building full compatibility with the version-2 (V2) Qiskit primitives available from version `0.8` of Qiskit Machine Learning. V1 primitives are deprecated and will be removed from version `0.9` (please find more information below).


New Features

1. Quantum Bayesian inference
We introduced a new class `qiskit_machine_learning.algorithms.QBayesian` which implements quantum Bayesian inference on a quantum circuit representing a Bayesian network with binary random variables.

The computational complexity is reduced from $\mathcal{O}(nmP(e)^{-1})$ to $\mathcal{O}(n\ 2^{m}P(e)^{-\frac{1}{2}})$ per sample, where $n$ is the number of nodes in the Bayesian network with at most $m$ parents per node and $e$ is the evidence. At least a quantum circuit that represents the Bayesian network has to be provided. A quantum circuit can be passed in various forms as long as it represents the joint probability distribution of the Bayesian network. Note that `QBayesian` defines an order for the qubits in the circuit. The last qubit in the circuit will correspond to the most significant bit in the joint probability distribution. For example, if the random variables A, B, and C are entered into the circuit in this order with ($A=1, B=0 and C=0$), the probability is represented by the probability amplitude of quantum state $001$.

An example of using this class is as follows:
python
from qiskit import QuantumCircuit
from qiskit_machine_learning.algorithms import QBayesian

Define a quantum circuit
qc = QuantumCircuit(...)

Initialize the framework
qb = QBayesian(qc)

Perform inference
result = qb.inference(query={...}, evidence={...})

print("Probability of query given evidence:", result)

You may refer to the [QBI tutorial](https://github.com/qiskit-community/qiskit-machine-learning/blob/stable/0.8/docs/tutorials/13_quantum_bayesian_inference.ipynb) which describes a step-by-step approach to quantum Bayesian inference on a Bayesian network.

2. Support for Python `3.12`

Added support for using Qiskit Machine Learning with Python `3.12`.

3. Incorporation of Qiskit Algorithms

Migrated essential Qiskit Algorithms features to Qiskit Machine Learning. Also, Qiskit Machine Learning now requires Qiskit 1.0 or higher. You may be required to upgrade Qiskit Aer accordingly, depending on your setup. The merge of some of the features of Qiskit Algorithms into Qiskit Machine Learning might lead to breaking changes. For this reason, caution is advised when updating to version `0.8` during critical production stages in a project. This change ensures continued enhancement and maintenance of essential features for Qiskit Machine Learning following the end of official support for Qiskit Algorithms. Therefore, Qiskit Machine Learning will no longer depend on Qiskit Algorithms.

Users must update their imports and code references in code that uses Qiskit Machine Leaning and Algorithms:

- Change `qiskit_algorithms.gradients` to `qiskit_machine_learning.gradients`
- Change `qiskit_algorithms.optimizers` to `qiskit_machine_learning.optimizers`
- Change `qiskit_algorithms.state_fidelities` to `qiskit_machine_learning.state_fidelities`
- Update utilities as needed due to partial merge.

To continue using sub-modules and functionalities of Qiskit Algorithms that **have not been transferred**, you may continue using them as before by importing from Qiskit Algorithms. However, be aware that Qiskit Algorithms is no longer officially supported and some of its functionalities may not work in your use case. For any problems directly related to Qiskit Algorithms, please open a GitHub issue at [https://github.com/qiskit-community/qiskit-algorithms](https://github.com/qiskit-community/qiskit-algorithms). Should you want to include a Qiskit Algorithms functionality that has not been incorporated in Qiskit Machine Learning, please open a feature-request issue at [https://github.com/qiskit-community/qiskit-machine-learning](https://github.com/qiskit-community/qiskit-machine-learning), explaining why this change would be useful for you and other users.

Four examples of upgrading the code can be found below.

Gradients:
python
Before:
from qiskit_algorithms.gradients import SPSA, ParameterShift
After:
from qiskit_machine_learning.gradients import SPSA, ParameterShift
Usage
spsa = SPSA()
param_shift = ParameterShift()

Optimizers:
python
Before:
from qiskit_algorithms.optimizers import COBYLA, ADAM
After:
from qiskit_machine_learning.optimizers import COBYLA, ADAM
Usage
cobyla = COBYLA()
adam = ADAM()

Quantum state fidelities:
python
Before:
from qiskit_algorithms.state_fidelities import ComputeFidelity
After:
from qiskit_machine_learning.state_fidelities import ComputeFidelity
Usage
fidelity = ComputeFidelity()

Algorithm globals (used to fix the random seed):
python
Before:
from qiskit_algorithms.utils import algorithm_globals
After:
from qiskit_machine_learning.utils import algorithm_globals
algorithm_globals.random_seed = 1234


4. Support for V2 Primitives

The `EstimatorQNN` and `SamplerQNN` classes now support `V2` primitives (`EstimatorV2` and `SamplerV2`), allowing direct execution on IBM Quantum backends. This enhancement ensures compatibility with Qiskit IBM Runtime’s Primitive Unified Block (PUB) requirements and instruction set architecture (ISA) constraints for circuits and observables. Users can switch between `V1` primitives and `V2` primitives from version `0.8`. From version `0.9`, V1 primitives will be removed.

Upgrade notes

- Removed support for using Qiskit Machine Learning with Python `3.8` to reflect the EOL of Python `3.8` in October 2024 (PEP 569). To continue using Qiskit Machine Learning, you must upgrade to Python `3.9` or above if you are using older versions of Python.

- From version `0.8`, Qiskit Machine Learning requires Qiskit `1.0` or higher.

- Users working with real backends are advised to migrate to `V2` primitives (`EstimatorV2` and `SamplerV2`) to ensure compatibility with Qiskit IBM Runtime hardware requirements. These `V2` primitives will become the standard in the `0.8` release going forward, while `V1` primitives are deprecated.

Deprecation Notes

- The `V1` primitives (e.g., `EstimatorV1` and `SamplerV1`) are no longer compatible with real quantum backends via Qiskit IBM Runtime. This update provides initial transitional support, but `V1` primitives may be fully deprecated and removed in version `0.9`. Users should adopt `V2` primitives for both local and hardware executions to ensure long-term compatibility.

Bug Fixes

- Added a `max_circuits_per_job` parameter to the `FidelityQuantumKernel` used in the case that more circuits are submitted than the job limit for the backend, the circuits are split up and run through separate jobs.

- Removed `QuantumKernelTrainer` dependency on `copy.deepcopy` that was throwing an error with real backends. Now, it modifies the `TrainableKernel` in place. If you would like to use the initial kernel, please call `TrainableKernel.assign_training_parameters` of the `TrainableKernel` using the `QuantumKernelTrainer.initial_point` attribute of `QuantumKernelTrainer`.

- Fixes the dimension mismatch error in the `torch_connector` raised when using other-than 3D datasets. The updated implementation defines the Einstein summation signature dynamically based on the number of dimensions `ndim` of the input data (up to 26 dimensions).

- Fixed a bug where `FidelityStatevectorKernel` threw an error when pickled.

- Fixes an issue for the Quantum Neural Networks where the binding order of the inputs and weights might end up being incorrect. Though the parameters for the inputs and weights are specified to the QNN, the code previously bound the inputs and weights in the order given by the `circuit.parameters`. This would end up being the right order for the Qiskit circuit library feature maps and ansatzes most often used, as the default parameter names led to the order being as expected. However, for custom names and so on, this was not always the case and then led to unexpected behaviour. The sequences for the input and weights parameters, as supplied, are now always used as the binding order, for the inputs and weights respectively, such that the order of the parameters in the overall circuit no longer matters.

New Contributors

* MoritzWillmann made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/719
* espREssOOOHHH made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/743
* dependabot made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/751
* OkuyanBoga made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/772
* oscar-wallis made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/778
* FrancescaSchiav made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/784
* edoaltamura made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/796
* proeseler made their first contribution in https://github.com/qiskit-community/qiskit-machine-learning/pull/717

**Full Changelog**: https://github.com/qiskit-community/qiskit-machine-learning/compare/0.7.0...0.8.0

0.7.2

Changelog
New Features
- Added support for using Qiskit Machine Learning with Python 3.12.

Bug Fixes
- Added a max_circuits_per_job parameter to the [FidelityQuantumKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.FidelityQuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel) used in the case that if more circuits are submitted than the job limit for the backend, the circuits are split up and run through separate jobs.

- Removed [QuantumKernelTrainer](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer.html#qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer) dependency on copy.deepcopy that was throwing an error with real backends. Now, it modifies the [TrainableKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.TrainableKernel.html#qiskit_machine_learning.kernels.TrainableKernel) in place. If you would like to use the initial kernel, please call [assign_training_parameters()](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.TrainableKernel.html#qiskit_machine_learning.kernels.TrainableKernel.assign_training_parameters) of the [TrainableKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.TrainableKernel.html#qiskit_machine_learning.kernels.TrainableKernel) using the [initial_point](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer.html#qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer.initial_point) attribute of [QuantumKernelTrainer](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer.html#qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer).

- Fixes an issue for the Quantum Neural Networks where the binding order of the inputs and weights might end up being incorrect. Though the params for the inputs and weights are specified to the QNN, the code previously bound the inputs and weights in the order given by the circuit.parameters. This would end up being the right order for the Qiskit circuit library feature maps and ansatzes most often used, as the default parameter names led to the order being as expected. However for custom names etc. this was not always the case and then led to unexpected behavior. The sequences for the input and weights parameters, as supplied, are now always used as the binding order, for the inputs and weights respectively, such that the order of the parameters in the overall circuit no longer matters.

- Fixed a bug where [FidelityStatevectorKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.FidelityStatevectorKernel.html#qiskit_machine_learning.kernels.FidelityStatevectorKernel) threw an error when pickled.

0.7.1

Changelog

This bug fix release fixed the link to the Qiskit medium blog post where it was announced that application modules had been moved to the qiskit-community organization.

0.7.0

Prelude

Qiskit Machine Learning has been migrated to the [qiskit-community Github organization](https://github.com/qiskit-community) to further emphasize that it is a community-driven project. To reflect this change, and because we are onboarding additional code-owners and maintainers, with this version (0.7) we have decided to remove all deprecated code, regardless of the time of its deprecation. This ensures that the new members of the development team do not have a large bulk of legacy code to maintain. This can mean one of two things for you as the end-user:

- Nothing, if you already migrated your code and no longer rely on any deprecated features.
- Otherwise, you should make sure that your workflow doesn’t rely on deprecated classes. If you cannot do that, or want to continue
using some of the features that were removed, you should pin your version of Qiskit Machine Learning to 0.6.

For more context on the changes around Qiskit Machine Learning and the other application projects as well as the Algorithms library in Qiskit, be sure to read this [blog post](https://ibm.biz/BdSyNm).

New Features

- The [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) class can be passed as circuit to the [SamplerQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html#qiskit_machine_learning.neural_networks.SamplerQNN) and [EstimatorQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html#qiskit_machine_learning.neural_networks.EstimatorQNN). This simplifies the interfaces to build a [Sampler](https://qiskit.org/documentation/stubs/qiskit.primitives.Sampler.html#qiskit.primitives.Sampler) or [Estimator](https://qiskit.org/documentation/stubs/qiskit.primitives.Estimator.html#qiskit.primitives.Estimator) based neural network implementation from a feature map and an ansatz circuit.
Using the [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) comes with the benefit that the feature map and ansatz do not have to be composed explicitly. If a [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) is passed to the [SamplerQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html#qiskit_machine_learning.neural_networks.SamplerQNN) or [EstimatorQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html#qiskit_machine_learning.neural_networks.EstimatorQNN) the input and weight parameters do not have to be provided, because these two properties are taken from the [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit).
An example of using [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) with the [SamplerQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html#qiskit_machine_learning.neural_networks.SamplerQNN) class is as follows:

python
from qiskit_machine_learning.circuit.library import QNNCircuit
from qiskit_machine_learning.neural_networks import SamplerQNN

def parity(x):
return f"{bin(x)}".count("1") % 2

Create a parameterized 2 qubit circuit composed of the default ZZFeatureMap feature map
and RealAmplitudes ansatz.
qnn_qc = QNNCircuit(num_qubits = 2)

qnn = SamplerQNN(
circuit=qnn_qc,
interpret=parity,
output_shape=2
)

qnn.forward(input_data=[1, 2], weights=[1, 2, 3, 4, 5, 6, 7, 8])


The [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) is used with the [EstimatorQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html#qiskit_machine_learning.neural_networks.EstimatorQNN) class in the same fashion:

python
from qiskit_machine_learning.circuit.library import QNNCircuit
from qiskit_machine_learning.neural_networks import EstimatorQNN

Create a parameterized 2 qubit circuit composed of the default ZZFeatureMap feature map
and RealAmplitudes ansatz.
qnn_qc = QNNCircuit(num_qubits = 2)

qnn = EstimatorQNN(
circuit=qnn_qc
)

qnn.forward(input_data=[1, 2], weights=[1, 2, 3, 4, 5, 6, 7, 8])


- Added a new [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) class that composes a Quantum Circuit from a feature map and an ansatz.
At least one parameter, i.e. number of qubits, feature map, ansatz, has to be provided.
If only the number of qubits is provided the resulting quantum circuit is a composition of the [ZZFeatureMap](https://qiskit.org/documentation/stubs/qiskit.circuit.library.ZZFeatureMap.html#qiskit.circuit.library.ZZFeatureMap) and the [RealAmplitudes](https://qiskit.org/documentation/stubs/qiskit.circuit.library.RealAmplitudes.html#qiskit.circuit.library.RealAmplitudes) ansatz. If the number of qubits is 1 the [ZFeatureMap](https://qiskit.org/documentation/stubs/qiskit.circuit.library.ZFeatureMap.html#qiskit.circuit.library.ZFeatureMap) is used per default. If only a feature map is provided, the [RealAmplitudes](https://qiskit.org/documentation/stubs/qiskit.circuit.library.RealAmplitudes.html#qiskit.circuit.library.RealAmplitudes) ansatz with the corresponding number of qubits is used. If only an ansatz is provided the [ZZFeatureMap](https://qiskit.org/documentation/stubs/qiskit.circuit.library.ZZFeatureMap.html#qiskit.circuit.library.ZZFeatureMap) with the corresponding number of qubits is used.
In case number of qubits is provided along with either a feature map, an ansatz or both, a potential mismatch between the three inputs with respect to the number of qubits is resolved by constructing the [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) with the given number of qubits. If one of the [QNNCircuit](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.QNNCircuit.html#qiskit_machine_learning.circuit.library.QNNCircuit) properties is set after the class construction, the circuit is is adjusted to incorporate the changes. This is, a new valid configuration that considers the latest property update will be derived. This ensures that the classes properties are consistent at all times.

An example of using this class is as follows:

python
from qiskit_machine_learning.circuit.library import QNNCircuit
qnn_qc = QNNCircuit(2)
print(qnn_qc)
prints:
┌──────────────────────────┐»
q_0: ┤0 ├»
│ ZZFeatureMap(x[0],x[1]) │»
q_1: ┤1 ├»
└──────────────────────────┘»
« ┌──────────────────────────────────────────────────────────┐
«q_0: ┤0 ├
« │ RealAmplitudes(θ[0],θ[1],θ[2],θ[3],θ[4],θ[5],θ[6],θ[7]) │
«q_1: ┤1 ├
« └──────────────────────────────────────────────────────────┘

print(qnn_qc.num_qubits)
prints: 2

print(qnn_qc.input_parameters)
prints: ParameterView([ParameterVectorElement(x[0]), ParameterVectorElement(x[1])])

print(qnn_qc.weight_parameters)
prints: ParameterView([ParameterVectorElement(θ[0]), ParameterVectorElement(θ[1]),
ParameterVectorElement(θ[2]), ParameterVectorElement(θ[3]),
ParameterVectorElement(θ[4]), ParameterVectorElement(θ[5]),
ParameterVectorElement(θ[6]), ParameterVectorElement(θ[7])])


- A new [TrainableFidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.TrainableFidelityStatevectorKernel.html#qiskit_machine_learning.kernels.TrainableFidelityStatevectorKernel) class has been added that provides a trainable version of [FidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.FidelityStatevectorKernel.html#qiskit_machine_learning.kernels.FidelityStatevectorKernel). This relationship mirrors that between the existing FidelityQuantumKernel. Thus, [TrainableFidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.TrainableFidelityStatevectorKernel.html#qiskit_machine_learning.kernels.TrainableFidelityStatevectorKernel) inherits from both [FidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.FidelityStatevectorKernel.html#qiskit_machine_learning.kernels.FidelityStatevectorKernel) and [TrainableKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.TrainableKernel.html#qiskit_machine_learning.kernels.TrainableKernel).
This class is used with [QuantumKernelTrainer](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer.html#qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer) in an identical way to [TrainableFidelityQuantumKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.TrainableFidelityQuantumKernel.html#qiskit_machine_learning.kernels.TrainableFidelityQuantumKernel), except for the arguments specific to [TrainableFidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.TrainableFidelityStatevectorKernel.html#qiskit_machine_learning.kernels.TrainableFidelityStatevectorKernel).

For an example, see the snippet below:

python
from qiskit.quantum_info import Statevector
from qiskit_machine_learning.kernels import TrainableFidelityStatevectorKernel
from qiskit_machine_learning.kernels.algorithms import QuantumKernelTrainer

Instantiate trainable fidelity statevector kernel.
quantum_kernel = TrainableFidelityStatevectorKernel(
feature_map=<your_feature_map>,
statevector_type=Statevector,
training_parameters=<your_training_parameters>,
cache_size=None,
auto_clear_cache=True,
shots=None,
enforce_psd=True,
)

Instantiate a quantum kernel trainer (QKT).
qkt = QuantumKernelTrainer(quantum_kernel=quantum_kernel)

Train the kernel using QKT directly.
qkt_results = qkt.fit(<your_X_train>, <your_y_train>)
optimized_kernel = qkt_results.quantum_kernel


- The module is migrated to [Qiskit Algorithms](https://qiskit.org/ecosystem/algorithms) from the qiskit.algorithms package that is deprecated now.

Upgrade Notes

- Support for running with Python 3.7 has been removed. To run Qiskit Machine Learning you need a minimum Python version of 3.8.

- Removed support of the deprecated parameter quantum_instance in the constructor of [VQC](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html#qiskit_machine_learning.algorithms.VQC) and in [VQR](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.algorithms.VQR.html#qiskit_machine_learning.algorithms.VQR). Please use sampler and estimator respectively. Refer to the [migration guide](https://qiskit.org/ecosystem/machine-learning/migration/01_migration_guide_0.5.html) for more information.

- Since [qiskit.opflow](https://qiskit.org/documentation/apidoc/opflow.html#module-qiskit.opflow) and [QuantumInstance](https://qiskit.org/documentation/stubs/qiskit.utils.QuantumInstance.html#qiskit.utils.QuantumInstance) are deprecated in Qiskit, Qiskit Machine Learning classes based on the deprecated Qiskit classes have been removed:

* Class qiskit_machine_learning.neural_networks.SamplingNeuralNetwork is removed and has no direct replacement as this is a base class.
* Class qiskit_machine_learning.neural_networks.CircuitQNN is removed and is superseded by [qiskit_machine_learning.neural_networks.SamplerQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html#qiskit_machine_learning.neural_networks.SamplerQNN).
* Class qiskit_machine_learning.neural_networks.OpflowQNN is removed and is superseded by [qiskit_machine_learning.neural_networks.EstimatorQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html#qiskit_machine_learning.neural_networks.EstimatorQNN).
* Class qiskit_machine_learning.neural_networks.TwoLayerQNN is removed and has no direct replacement. Please make use of [qiskit_machine_learning.neural_networks.EstimatorQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html#qiskit_machine_learning.neural_networks.EstimatorQNN) instead.
* Class qiskit_machine_learning.kernels.QuantumKernel is removed and is superseded by [qiskit_machine_learning.kernels.FidelityQuantumKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.FidelityQuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel), [qiskit_machine_learning.kernels.TrainableFidelityQuantumKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.TrainableFidelityQuantumKernel.html#qiskit_machine_learning.kernels.TrainableFidelityQuantumKernel), and [qiskit_machine_learning.kernels.FidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.FidelityStatevectorKernel.html#qiskit_machine_learning.kernels.FidelityStatevectorKernel).

Please refer to the [migration guide](https://qiskit.org/ecosystem/machine-learning/migration/01_migration_guide_0.5.html) on how to replace the deprecated classes with new ones.

- The previously deprecated qgan and runtime packages have been removed. Please refer to:

* New [QGAN tutorial](https://qiskit.org/documentation/machine-learning/tutorials/04_torch_qgan.html) to train a generative quantum neural network.
* New primitive based quantum neural networks [EstimatorQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html#qiskit_machine_learning.neural_networks.EstimatorQNN), [SamplerQNN](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html#qiskit_machine_learning.neural_networks.SamplerQNN), PyTorch connector [TorchConnector](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.connectors.TorchConnector.html#qiskit_machine_learning.connectors.TorchConnector), and [Qiskit Runtime Service](https://qiskit.org/documentation/partners/qiskit_ibm_runtime/apidocs/runtime_service.html) to get functionality similar to what the removed runtime package provided.

Bug Fixes

- Compatibility fix to support Python 3.11.

- Fixes a bug in [FidelityStatevectorKernel](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.kernels.FidelityStatevectorKernel.html#qiskit_machine_learning.kernels.FidelityStatevectorKernel) where kernel entries could potentially have nonzero complex components due to truncation and rounding errors when enforcing a PSD matrix.

- Updated [RawFeatureVector](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.circuit.library.RawFeatureVector.html#qiskit_machine_learning.circuit.library.RawFeatureVector) to support [changes](https://github.com/Qiskit/qiskit-terra/pull/10183) in the parameter assignment introduced in Qiskit.

- Fixed incorrect type conversions in [TorchConnector](https://qiskit.org/ecosystem/machine-learning/stubs/qiskit_machine_learning.connectors.TorchConnector.html#qiskit_machine_learning.connectors.TorchConnector). The bug was causing the connector to convert the output to the same type as the input data. As a result, when an integer tensor was passed, the output would also be converted to an integer tensor, leading to rounding errors.

Page 1 of 3

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.