Qiskit-machine-learning

Latest version: v0.8.0

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

Scan your dependencies

Page 1 of 3

0.8.0

What's Changed
* Pin mypy to fix CI by ElePT in https://github.com/qiskit-community/qiskit-machine-learning/pull/711
* Post release 0.7.0 by ElePT in https://github.com/qiskit-community/qiskit-machine-learning/pull/710
* Unpin mypy by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/713
* Fix blog post link by ElePT in https://github.com/qiskit-community/qiskit-machine-learning/pull/720
* optimize `FidelityQuantumKernel` parameterization by MoritzWillmann in https://github.com/qiskit-community/qiskit-machine-learning/pull/719
* Add new code owners by adekusar-drl in https://github.com/qiskit-community/qiskit-machine-learning/pull/722
* Workaround CI failure with nbconvert version pin by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/733
* Fix QNN for input and weights ordering by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/728
* Fix copyright dates from PR 728 for 2024 by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/737
* Deploy docs to GitHub Pages by arnaucasau in https://github.com/qiskit-community/qiskit-machine-learning/pull/739
* The deprecated calling sytle of circut draw function has been updated in tutorials. by espREssOOOHHH in https://github.com/qiskit-community/qiskit-machine-learning/pull/743
* Update intersphinx links and others by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/747
* Add dependabot to manage Github Actions update by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/748
* Update upload/download-artifact actions versions by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/755
* Bump actions/setup-python from 4 to 5 by dependabot in https://github.com/qiskit-community/qiskit-machine-learning/pull/751
* Bump actions/checkout from 3 to 4 by dependabot in https://github.com/qiskit-community/qiskit-machine-learning/pull/753
* Make MockFidelity also compatible with Qiskit Algorithms >= 0.3.0 by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/761
* Remove most qiskit.org links by Eric-Arellano in https://github.com/qiskit-community/qiskit-machine-learning/pull/763
* Remove qiskit.org links from release notes by Eric-Arellano in https://github.com/qiskit-community/qiskit-machine-learning/pull/764
* Remove all other languages other than Spanish and Japanese by SooluThomas in https://github.com/qiskit-community/qiskit-machine-learning/pull/766
* Fix tutorials to work with Qiskit 1.0 by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/769
* Add Python 3.12 support by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/774
* Added max_circuits_per_job and removed deepcopy dependency of the quantum kernel trainer fixing 701 and 600 by OkuyanBoga in https://github.com/qiskit-community/qiskit-machine-learning/pull/772
* Bug/607 fidelity statevector kernel cannot be pickled by oscar-wallis in https://github.com/qiskit-community/qiskit-machine-learning/pull/778
* Update README.md for failing unit test badge by FrancescaSchiav in https://github.com/qiskit-community/qiskit-machine-learning/pull/784
* Add M1 image for MacOS for tests by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/779
* Pin torch==2.2.2 in CI to avoid a UTF-8 error in Windows (temporary bug in Torch) by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/796
* Patches einsum dimensionality in `torch_connector` - 716 by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/793
* Update black by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/799
* Fix lint by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/804
* Integrated quantum bayesian inference by proeseler in https://github.com/qiskit-community/qiskit-machine-learning/pull/717
* Include GitHub security policy by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/806
* Add Qiskit `1.0` migration instructions and light modifications by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/808
* Restore latest dependencies in CI environment by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/816
* PyTorch connector refractoring by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/809
* Migrating `qiskit_algorithms` by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/817
* Revamp readme pt2 by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/822
* Fix lint errors due to Pylint 3.3.0 update in CI by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/833
* Remove Python 3.8 from CI (824) by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/826
* Reestablish latest Pytorch and Numpy (818) by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/827
* Fix RawFeatureVector for failing test case by woodsp-ibm in https://github.com/qiskit-community/qiskit-machine-learning/pull/838
* Release `nbconvert` constraint by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/842
* Remove redundant MacOS 14 image in CI by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/841
* Support for V2 primitives by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/843
* Prepare for 0.8 release by edoaltamura in https://github.com/qiskit-community/qiskit-machine-learning/pull/828

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.

0.6.1

Changelog

Bug Fixes

- Compatibility fix to support Python 3.11.

- The function `qiskit_machine_learning.datasets.discretize_and_truncate()` is fixed on numpy version 1.24. This function is used by the QGAN implementation.

0.6.0

Changelog

New Features

- Allow callable as an optimizer in NeuralNetworkClassifier, VQC, NeuralNetworkRegressor, VQR, as well as in [QuantumKernelTrainer](https://qiskit.org/documentation/machine-learning/stubs/qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer.html#qiskit_machine_learning.kernels.algorithms.QuantumKernelTrainer).

Now, the optimizer can either be one of Qiskit’s optimizers, such as [SPSA](https://qiskit.org/documentation/stubs/qiskit.algorithms.optimizers.SPSA.html#qiskit.algorithms.optimizers.SPSA) or a callable with the following signature:

python
from qiskit.algorithms.optimizers import OptimizerResult

def my_optimizer(fun, x0, jac=None, bounds=None) -> OptimizerResult:
Args:
fun (callable): the function to minimize
x0 (np.ndarray): the initial point for the optimization
jac (callable, optional): the gradient of the objective function
bounds (list, optional): a list of tuples specifying the parameter bounds
result = OptimizerResult()
result.x = optimal parameters
result.fun = optimal function value
return result

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The above signature also allows to directly pass any SciPy minimizer, for instance as

python
from functools import partial
from scipy.optimize import minimize
optimizer = partial(minimize, method="L-BFGS-B")


- Added a new `FidelityStatevectorKernel` class that is optimized to use only statevector-implemented feature maps. Therefore, computational complexity is reduced from $O(N^2)$ to $O(N)$.

Computed statevector arrays are also cached to further increase efficiency. This cache is cleared when the `evaluate` method is called, unless `auto_clear_cache` is `False`. The cache is unbounded by default, but its size can be set by the user, i.e., limited to the number of samples in the worst case.

By default the Terra reference `Statevector` is used, however, the type can be specified via the `statevector_type` argument.

Shot noise emulation can also be added. If `shots` is `None`, the exact fidelity is used. Otherwise, the mean is taken of samples drawn from a binomial distribution with probability equal to the exact fidelity.

With the addition of shot noise, the kernel matrix may no longer be positive semi-definite (PSD). With `enforce_psd` set to `True` this condition is enforced.

An example of using this class is as follows:

python
from sklearn.datasets import make_blobs
from sklearn.svm import SVC

from qiskit.circuit.library import ZZFeatureMap
from qiskit.quantum_info import Statevector

from qiskit_machine_learning.kernels import FidelityStatevectorKernel

generate a simple dataset
features, labels = make_blobs(
n_samples=20, centers=2, center_box=(-1, 1), cluster_std=0.1
)

feature_map = ZZFeatureMap(feature_dimension=2, reps=2)
statevector_type = Statevector

kernel = FidelityStatevectorKernel(
feature_map=feature_map,
statevector_type=Statevector,
cache_size=len(labels),
auto_clear_cache=True,
shots=1000,
enforce_psd=True,
)
svc = SVC(kernel=kernel.evaluate)
svc.fit(features, labels)


- The PyTorch connector `TorchConnector` now fully supports sparse output in both forward and backward passes. To enable sparse support, first of all, the underlying quantum neural network must be sparse. In this case, if the sparse property of the connector itself is not set, then the connector inherits sparsity from the networks. If the connector is set to be sparse, but the network is not, an exception will be raised. Also you may set the connector to be dense if the network is sparse.

This snippet illustrates how to create a sparse instance of the connector.

python
import torch
from qiskit import QuantumCircuit
from qiskit.circuit.library import ZFeatureMap, RealAmplitudes

from qiskit_machine_learning.connectors import TorchConnector
from qiskit_machine_learning.neural_networks import SamplerQNN

num_qubits = 2
fmap = ZFeatureMap(num_qubits, reps=1)
ansatz = RealAmplitudes(num_qubits, reps=1)
qc = QuantumCircuit(num_qubits)
qc.compose(fmap, inplace=True)
qc.compose(ansatz, inplace=True)

qnn = SamplerQNN(
circuit=qc,
input_params=fmap.parameters,
weight_params=ansatz.parameters,
sparse=True,
)

connector = TorchConnector(qnn)

output = connector(torch.tensor([[1., 2.]]))
print(output)

loss = torch.sparse.sum(output)
loss.backward()

grad = connector.weight.grad
print(grad)


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;In hybrid setup, where a PyTorch-based neural network has classical and quantum layers, sparse operations should not be mixed with dense ones, otherwise exceptions may be thrown by PyTorch.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sparse support works on python 3.8+.

Upgrade Notes

- The previously deprecated `CrossEntropySigmoidLoss` loss function has been removed.
- The previously deprecated datasets have been removed: `breast_cancer`, `digits`, `gaussian`, `iris`, `wine`.
- Positional arguments in [`QSVC`](https://qiskit.org/documentation/machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html#qiskit_machine_learning.algorithms.QSVC) and [`QSVR`](https://qiskit.org/documentation/machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html#qiskit_machine_learning.algorithms.QSVR) were deprecated as of version 0.3. Support of the positional arguments was completely removed in this version, please replace them with corresponding keyword arguments.

Bug Fixes
- [`SamplerQNN`](https://qiskit.org/documentation/machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html#qiskit_machine_learning.neural_networks.SamplerQNN) can now correctly handle quantum circuits without both input parameters and weights. If such a circuit is passed to the QNN then this circuit executed once in the forward pass and backward returns `None` for both gradients.

Page 1 of 3

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.