From fcf25acbfcc828a74c3f6e4be80190a2423fa6ab Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Mon, 5 Aug 2024 20:10:29 +0100 Subject: [PATCH 1/9] Restructure README.md --- README.md | 104 +++++++++++++++++++++++------------------------------- 1 file changed, 45 insertions(+), 59 deletions(-) diff --git a/README.md b/README.md index e8d773477..8a54712e8 100644 --- a/README.md +++ b/README.md @@ -12,75 +12,60 @@ ## What is Qiskit Machine Learning? -Qiskit Machine Learning introduces fundamental computational building blocks, such as Quantum Kernels -and Quantum Neural Networks, used in different applications, including classification and regression. -On the one hand, this design is very easy to use and allows users to rapidly prototype a first model -without deep quantum computing knowledge. On the other hand, Qiskit Machine Learning is very flexible, -and users can easily extend it to support cutting-edge quantum machine learning research. +Qiskit Machine Learning introduces fundamental computational building blocks, such as Quantum +Kernels and Quantum Neural Networks, used in various applications including classification +and regression. + +This library is part of the Qiskit Community ecosystem, a collection of high-level codes that are based +on the Qiskit software development kit. As of version `0.7.0`, Qiskit Machine Learning is co-maintained +by IBM and the Hartree Centre, part of the UK Science and Technologies Facilities Council (STFC). + +The Qiskit Machine Learning framework aims to be: + +* **User-friendly**, allowing users to quickly and easily prototype quantum machine learning models without + the need of extensive quantum computing knowledge. +* **Flexiblile**, providing tools and functionalities to conduct proof-of-concepts and innovative research + in quantum machine learning for both beginners and experts. +* **Extensible**, facilitating the integration of new cutting-edge features leveraging Qiskit's + architectures, patterns and related services. + ## What are the main features of Qiskit Machine Learning? -Qiskit Machine Learning provides the -[FidelityQuantumKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.QuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel) -class that makes use of the [Fidelity](https://qiskit-community.github.io/qiskit-algorithms/stubs/qiskit_algorithms.state_fidelities.BaseStateFidelity.html) algorithm introduced in Qiskit Algorithms and can be easily used -to directly compute kernel matrices for given datasets or can be passed to a Quantum Support Vector Classifier -[QSVC](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html#qiskit_machine_learning.algorithms.QSVC) or -Quantum Support Vector Regressor -[QSVR](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html#qiskit_machine_learning.algorithms.QSVR) -to quickly start solving classification or regression problems. -It also can be used with many other existing kernel-based machine learning algorithms from established -classical frameworks. - -Qiskit Machine Learning defines a generic interface for neural networks that is implemented by different -quantum neural networks. Two core implementations are readily provided, such as the -[EstimatorQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html), -and the [SamplerQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html). -The [EstimatorQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html) -leverages the [Estimator](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseEstimator) primitive from Qiskit and -allows users to combine parametrized quantum circuits with quantum mechanical observables. The circuits can be constructed using, for example, building blocks -from Qiskit’s circuit library, and the QNN’s output is given by the expected value of the observable. -The [SamplerQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html) -leverages another primitive introduced in Qiskit, the [Sampler](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseSampler) primitive. -This neural network translates quasi-probabilities of bitstrings estimated by the primitive into a desired output. This -translation step can be used to interpret a given bitstring in a particular context, e.g. translating it into a set of classes. - -The neural networks include the functionality to evaluate them for a given input as well as to compute the -corresponding gradients, which is important for efficient training. To train and use neural networks, -Qiskit Machine Learning provides a variety of learning algorithms such as the -[NeuralNetworkClassifier](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkClassifier.html#qiskit_machine_learning.algorithms.NeuralNetworkClassifier) -and -[NeuralNetworkRegressor](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkRegressor.html#qiskit_machine_learning.algorithms.NeuralNetworkRegressor). -Both take a QNN as input and then use it in a classification or regression context. -To allow an easy start, two convenience implementations are provided - the Variational Quantum Classifier -[VQC](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html#qiskit_machine_learning.algorithms.VQC) -as well as the Variational Quantum Regressor -[VQR](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQR.html#qiskit_machine_learning.algorithms.VQR). -Both take just a feature map and an ansatz and construct the underlying QNN automatically. - -In addition to the models provided directly in Qiskit Machine Learning, it has the -[TorchConnector](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.connectors.TorchConnector.html#qiskit_machine_learning.connectors.TorchConnector), -which allows users to integrate all of our quantum neural networks directly into the -[PyTorch](https://pytorch.org) -open source machine learning library. Thanks to Qiskit’s gradient algorithms, this includes automatic -differentiation - the overall gradients computed by [PyTorch](https://pytorch.org) -during the backpropagation take into -account quantum neural networks, too. The flexible design also allows the building of connectors -to other packages in the future. +### Kernel-based methods + +The [FidelityQuantumKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.QuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel) class uses the [Fidelity](https://qiskit-community.github.io/qiskit-algorithms/stubs/qiskit_algorithms.state_fidelities.BaseStateFidelity.html) algorithm from Qiskit Algorithms. It computes kernel matrices for datasets and can be used with a [Quantum Support Vector Classifier (QSVC)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html#qiskit_machine_learning.algorithms.QSVC) or [Quantum Support Vector Regressor (QSVR)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html#qiskit_machine_learning.algorithms.QSVR) to solve classification or regression problems. It is also compatible with classical kernel-based machine learning algorithms. + + +### Quantum Neural Networks (QNNs) + +Qiskit Machine Learning defines a generic interface for neural networks, implemented by two core (derived) primitives: + +- **[EstimatorQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html):** Leverages the [Estimator](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseEstimator) primitive, combining parametrized quantum circuits with quantum mechanical observables. The output is the expected value of the observable. + +- **[SamplerQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html):** Leverages the [Sampler](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseSampler) primitive, translating quasi-probabilities of bitstrings into desired outputs. + +To train and use neural networks, Qiskit Machine Learning provides learning algorithms such as the [NeuralNetworkClassifier](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkClassifier.html#qiskit_machine_learning.algorithms.NeuralNetworkClassifier) and [NeuralNetworkRegressor](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkRegressor.html#qiskit_machine_learning.algorithms.NeuralNetworkRegressor). Convenience implementations, the [Variational Quantum Classifier (VQC)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html#qiskit_machine_learning.algorithms.VQC) and [Variational Quantum Regressor (VQR)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQR.html#qiskit_machine_learning.algorithms.VQR), take a feature map and an ansatz to construct the underlying QNN automatically. + +### Integration with PyTorch + +The [TorchConnector](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.connectors.TorchConnector.html#qiskit_machine_learning.connectors.TorchConnector) integrates QNNs with [PyTorch](https://pytorch.org). Thanks to the gradient algorithms in Qiskit Machine Learning, this includes automatic differentiation. The overall gradients computed by PyTorch during the backpropagation take into account quantum neural networks, too. The flexible design also allows the building of connectors to other packages in the future. ## Installation -We encourage installing Qiskit Machine Learning via the pip tool (a python package manager). +We encourage installing Qiskit Machine Learning via the `pip` tool, a `Python` package manager. ```bash pip install qiskit-machine-learning ``` -**pip** will handle all dependencies automatically and you will always install the latest -(and well-tested) version. +`pip` will install all dependencies automatically, so that you will always have the most recent +stable version. -If you want to work on the very latest work-in-progress versions, either to try features ahead of -their official release or if you want to contribute to Machine Learning, then you can install from source. -To do this follow the instructions in the +If you want to work instead on the very latest _work-in-progress_ versions of Qiskit Machine Learning, +either to try features ahead of +their official release or if you want to contribute to the library, then you can install from source. +For more details on how to do so, follow the instructions in the [documentation](https://qiskit-community.github.io/qiskit-machine-learning/getting_started.html#installation). ### Optional Installs @@ -94,12 +79,13 @@ To do this follow the instructions in the ## Migration to Qiskit 1.x > [!NOTE] -> Qiskit Machine Learning learning depends on Qiskit, which will be automatically installed as a +> Qiskit Machine Learning depends on Qiskit, which will be automatically installed as a > dependency when you install Qiskit Machine Learning. If you have a pre-`1.0` version of Qiskit > installed in your environment (however it was installed), and wish to upgrade to `1.0`, you > should take note of the > official [Qiskit 1.0 Migration Guide](https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0) -> for detailed instructions and examples on how to upgrade. +> for detailed instructions and examples on how to upgrade. From version `0.8.0`, Qiskit 1.0 or above +> will be required. ---------------------------------------------------------------------------------------------------- From 94ad555dc192e2d964f035a752a69c72819e03b9 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Mon, 5 Aug 2024 20:43:25 +0100 Subject: [PATCH 2/9] Restructure README.md --- README.md | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8a54712e8..b56eb5111 100644 --- a/README.md +++ b/README.md @@ -34,24 +34,36 @@ The Qiskit Machine Learning framework aims to be: ### Kernel-based methods -The [FidelityQuantumKernel](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.QuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel) class uses the [Fidelity](https://qiskit-community.github.io/qiskit-algorithms/stubs/qiskit_algorithms.state_fidelities.BaseStateFidelity.html) algorithm from Qiskit Algorithms. It computes kernel matrices for datasets and can be used with a [Quantum Support Vector Classifier (QSVC)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html#qiskit_machine_learning.algorithms.QSVC) or [Quantum Support Vector Regressor (QSVR)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html#qiskit_machine_learning.algorithms.QSVR) to solve classification or regression problems. It is also compatible with classical kernel-based machine learning algorithms. +The [`FidelityQuantumKernel`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.QuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel) +class uses the [`Fidelity`](https://qiskit-community.github.io/qiskit-algorithms/stubs/qiskit_algorithms.state_fidelities.BaseStateFidelity.html) +algorithm. It computes kernel matrices for datasets and can be combined with a Quantum Support Vector Classifier ([`QSVC`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html#qiskit_machine_learning.algorithms.QSVC)) +or a Quantum Support Vector Regressor ([`QSVR`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html#qiskit_machine_learning.algorithms.QSVR)) +to solve classification or regression problems respectively. It is also compatible with classical kernel-based machine learning algorithms. ### Quantum Neural Networks (QNNs) Qiskit Machine Learning defines a generic interface for neural networks, implemented by two core (derived) primitives: -- **[EstimatorQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html):** Leverages the [Estimator](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseEstimator) primitive, combining parametrized quantum circuits with quantum mechanical observables. The output is the expected value of the observable. +- **[`EstimatorQNN`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.EstimatorQNN.html):** Leverages the [`Estimator`](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseEstimator) primitive, combining parametrized quantum circuits with quantum mechanical observables. The output is the expected value of the observable. -- **[SamplerQNN](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html):** Leverages the [Sampler](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseSampler) primitive, translating quasi-probabilities of bitstrings into desired outputs. +- **[`SamplerQNN`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.neural_networks.SamplerQNN.html):** Leverages the [`Sampler`](https://docs.quantum.ibm.com/api/qiskit/qiskit.primitives.BaseSampler) primitive, translating bit-string counts into the desired outputs. -To train and use neural networks, Qiskit Machine Learning provides learning algorithms such as the [NeuralNetworkClassifier](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkClassifier.html#qiskit_machine_learning.algorithms.NeuralNetworkClassifier) and [NeuralNetworkRegressor](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkRegressor.html#qiskit_machine_learning.algorithms.NeuralNetworkRegressor). Convenience implementations, the [Variational Quantum Classifier (VQC)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html#qiskit_machine_learning.algorithms.VQC) and [Variational Quantum Regressor (VQR)](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQR.html#qiskit_machine_learning.algorithms.VQR), take a feature map and an ansatz to construct the underlying QNN automatically. +To train and use neural networks, Qiskit Machine Learning provides learning algorithms such as the [`NeuralNetworkClassifier`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkClassifier.html#qiskit_machine_learning.algorithms.NeuralNetworkClassifier) +and [`NeuralNetworkRegressor`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.NeuralNetworkRegressor.html#qiskit_machine_learning.algorithms.NeuralNetworkRegressor). +Finally, built on these, the Variational Quantum Classifier ([`VQC`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQC.html#qiskit_machine_learning.algorithms.VQC)) +and the Variational Quantum Regressor ([`VQR`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.VQR.html#qiskit_machine_learning.algorithms.VQR)) +take a _feature map_ and an _ansatz_ to construct the underlying QNN automatically using high-level syntax. ### Integration with PyTorch -The [TorchConnector](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.connectors.TorchConnector.html#qiskit_machine_learning.connectors.TorchConnector) integrates QNNs with [PyTorch](https://pytorch.org). Thanks to the gradient algorithms in Qiskit Machine Learning, this includes automatic differentiation. The overall gradients computed by PyTorch during the backpropagation take into account quantum neural networks, too. The flexible design also allows the building of connectors to other packages in the future. +The [`TorchConnector`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.connectors.TorchConnector.html#qiskit_machine_learning.connectors.TorchConnector) +integrates QNNs with [PyTorch](https://pytorch.org). +Thanks to the gradient algorithms in Qiskit Machine Learning, this includes automatic differentiation. +The overall gradients computed by PyTorch during the backpropagation take into account quantum neural +networks, too. The flexible design also allows the building of connectors to other packages in the future. -## Installation +## Installation and documentation We encourage installing Qiskit Machine Learning via the `pip` tool, a `Python` package manager. @@ -65,17 +77,20 @@ stable version. If you want to work instead on the very latest _work-in-progress_ versions of Qiskit Machine Learning, either to try features ahead of their official release or if you want to contribute to the library, then you can install from source. -For more details on how to do so, follow the instructions in the +For more details on how to do so and much more, follow the instructions in the [documentation](https://qiskit-community.github.io/qiskit-machine-learning/getting_started.html#installation). ### Optional Installs -* **PyTorch**, may be installed either using command `pip install 'qiskit-machine-learning[torch]'` to install the +* **PyTorch** may be installed either using command `pip install 'qiskit-machine-learning[torch]'` to install the package or refer to PyTorch [getting started](https://pytorch.org/get-started/locally/). When PyTorch is installed, the `TorchConnector` facilitates its use of quantum computed networks. -* **Sparse**, may be installed using command `pip install 'qiskit-machine-learning[sparse]'` to install the - package. Sparse being installed will enable the usage of sparse arrays/tensors. +* **Sparse** may be installed using command `pip install 'qiskit-machine-learning[sparse]'` to install the + package. Sparse being installed will enable the usage of sparse arrays and tensors. + +* **NLOpt** is required by the global optimizers. [`NLOpt`](https://nlopt.readthedocs.io/en/latest/) + can be installed with `pip install 'qiskit-machine-learning[nlopt]'`. ## Migration to Qiskit 1.x > [!NOTE] @@ -84,7 +99,7 @@ For more details on how to do so, follow the instructions in the > installed in your environment (however it was installed), and wish to upgrade to `1.0`, you > should take note of the > official [Qiskit 1.0 Migration Guide](https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0) -> for detailed instructions and examples on how to upgrade. From version `0.8.0`, Qiskit 1.0 or above +> for detailed instructions and examples on how to upgrade. From version `0.8.0`, Qiskit `1.0` or above > will be required. ---------------------------------------------------------------------------------------------------- From 5f2f0297becdc14029dc4a5ef65aee2dcdff8807 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Tue, 6 Aug 2024 21:58:54 +0100 Subject: [PATCH 3/9] Update README.md Co-authored-by: Steve Wood <40241007+woodsp-ibm@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b56eb5111..f123f0fb2 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ The Qiskit Machine Learning framework aims to be: * **User-friendly**, allowing users to quickly and easily prototype quantum machine learning models without the need of extensive quantum computing knowledge. -* **Flexiblile**, providing tools and functionalities to conduct proof-of-concepts and innovative research +* **Flexible**, providing tools and functionalities to conduct proof-of-concepts and innovative research in quantum machine learning for both beginners and experts. * **Extensible**, facilitating the integration of new cutting-edge features leveraging Qiskit's architectures, patterns and related services. From 30e8a29924f4d6be2a12ce54b9a3848c843e0814 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Wed, 7 Aug 2024 19:27:20 +0200 Subject: [PATCH 4/9] Rephrase and add nlot --- .github/actions/install-machine-learning/action.yml | 2 +- README.md | 10 +++++----- setup.py | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/actions/install-machine-learning/action.yml b/.github/actions/install-machine-learning/action.yml index 51f37f443..c8fc901b0 100644 --- a/.github/actions/install-machine-learning/action.yml +++ b/.github/actions/install-machine-learning/action.yml @@ -17,6 +17,6 @@ runs: using: "composite" steps: - run : | - pip install -e .[torch,sparse] + pip install -e .[torch,sparse,nlopt] pip install -U -c constraints.txt -r requirements-dev.txt shell: bash diff --git a/README.md b/README.md index f123f0fb2..e22a4cb30 100644 --- a/README.md +++ b/README.md @@ -95,12 +95,12 @@ For more details on how to do so and much more, follow the instructions in the ## Migration to Qiskit 1.x > [!NOTE] > Qiskit Machine Learning depends on Qiskit, which will be automatically installed as a -> dependency when you install Qiskit Machine Learning. If you have a pre-`1.0` version of Qiskit -> installed in your environment (however it was installed), and wish to upgrade to `1.0`, you -> should take note of the +> dependency when you install Qiskit Machine Learning. From version `0.8.0` of Qiskit Machine +> Learning, Qiskit `1.0` or above will be required. If you have a pre-`1.0` version of Qiskit +> installed in your environment (however it was installed), you should upgrade to `1.x` to +> continue using the latest features. You may refer to the > official [Qiskit 1.0 Migration Guide](https://docs.quantum.ibm.com/api/migration-guides/qiskit-1.0) -> for detailed instructions and examples on how to upgrade. From version `0.8.0`, Qiskit `1.0` or above -> will be required. +> for detailed instructions and examples on how to upgrade Qiskit. ---------------------------------------------------------------------------------------------------- diff --git a/setup.py b/setup.py index 0d654e889..7d7688b9f 100644 --- a/setup.py +++ b/setup.py @@ -72,6 +72,7 @@ extras_require={ 'torch': ["torch"], 'sparse': ["sparse"], + 'nlopt': ["nlopt"] }, project_urls={ "Bug Tracker": "https://github.com/qiskit-community/qiskit-machine-learning/issues", From e25386c6e7627c2a53fb2ab0fd329505402593c2 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:51:00 +0200 Subject: [PATCH 5/9] Remove NLopt as automatic optinal install and update RST files. --- .../install-machine-learning/action.yml | 2 +- README.md | 21 ++-- docs/getting_started.rst | 23 +++- docs/index.rst | 109 +++++++++--------- setup.py | 1 - 5 files changed, 92 insertions(+), 64 deletions(-) diff --git a/.github/actions/install-machine-learning/action.yml b/.github/actions/install-machine-learning/action.yml index c8fc901b0..51f37f443 100644 --- a/.github/actions/install-machine-learning/action.yml +++ b/.github/actions/install-machine-learning/action.yml @@ -17,6 +17,6 @@ runs: using: "composite" steps: - run : | - pip install -e .[torch,sparse,nlopt] + pip install -e .[torch,sparse] pip install -U -c constraints.txt -r requirements-dev.txt shell: bash diff --git a/README.md b/README.md index e22a4cb30..e63fe9464 100644 --- a/README.md +++ b/README.md @@ -89,8 +89,10 @@ For more details on how to do so and much more, follow the instructions in the * **Sparse** may be installed using command `pip install 'qiskit-machine-learning[sparse]'` to install the package. Sparse being installed will enable the usage of sparse arrays and tensors. -* **NLOpt** is required by the global optimizers. [`NLOpt`](https://nlopt.readthedocs.io/en/latest/) - can be installed with `pip install 'qiskit-machine-learning[nlopt]'`. +* **NLopt** is required for the global optimizers. [`NLopt`](https://nlopt.readthedocs.io/en/latest/) + can be installed manually with `pip install nlopt` on Windows and Linux platforms, or with `brew + install nlopt` on MacOS using the Homebrew package manager. For more information, + refer to the [installation guide](https://nlopt.readthedocs.io/en/latest/NLopt_Installation/). ## Migration to Qiskit 1.x > [!NOTE] @@ -106,10 +108,9 @@ For more details on how to do so and much more, follow the instructions in the ### Creating Your First Machine Learning Programming Experiment in Qiskit -Now that Qiskit Machine Learning is installed, it's time to begin working with the Machine Learning module. -Let's try an experiment using VQC (Variational Quantum Classifier) algorithm to -train and test samples from a data set to see how accurately the test set can -be classified. +Now that Qiskit Machine Learning is installed, it's time to begin working with the Machine +Learning module. Let's try an experiment using VQC (Variational Quantum Classifier) algorithm to +train and test samples from a data set to see how accurately the test set can be classified. ```python from qiskit.circuit.library import TwoLocal, ZZFeatureMap @@ -178,9 +179,11 @@ For questions that are more suited for a forum, we use the **Qiskit** tag in [St ## Humans behind Qiskit Machine Learning -Qiskit Machine Learning was inspired, authored and brought about by the collective work of a team of researchers -and software engineers. This library continues to grow with the help and work of -[many people](https://github.com/qiskit-community/qiskit-machine-learning/graphs/contributors), who contribute to the project at different levels. +Qiskit Machine Learning was inspired, authored and brought about by the collective work of a +team of researchers and software engineers. This library continues to grow with the help and +work of +[many people](https://github.com/qiskit-community/qiskit-machine-learning/graphs/contributors), +who contribute to the project at different levels. ## How can I cite Qiskit Machine Learning? If you use Qiskit, please cite as per the provided diff --git a/docs/getting_started.rst b/docs/getting_started.rst index b64772460..5ef8a3c99 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -14,7 +14,7 @@ that first. Then the information here can be followed which focuses on the addit specific to Qiskit Machine Learning. Qiskit Machine Learning has some functions that have been made optional where the dependent code and/or -support program(s) are not (or cannot be) installed by default. Those are PyTorch and Sparse. +support program(s) are not (or cannot be) installed by default. Those are PyTorch, Sparse and NLopt. See :ref:`optional_installs` for more information. .. tab-set:: @@ -97,6 +97,27 @@ Optional installs * **Sparse**, may be installed using command ``pip install 'qiskit-machine-learning[sparse]'`` to install the package. Sparse being installed will enable the usage of sparse arrays/tensors. +* **NLopt** is required for the global optimizers. `NLOpt `__ + can be installed manually with ``pip install nlopt`` on Windows and Linux platforms, or with + ``brew install nlopt`` on MacOS using the Homebrew package manager. For more information, refer + to the `installation guide `__. + +.. _migration-to-qiskit-1x: + +Migration to Qiskit 1.x +======================== + +.. note:: + + Qiskit Machine Learning depends on Qiskit, which will be automatically installed as a + dependency when you install Qiskit Machine Learning. From version ``0.8.0`` of Qiskit Machine + Learning, Qiskit ``1.0`` or above will be required. If you have a pre-``1.0`` version of Qiskit + installed in your environment (however it was installed), you should upgrade to ``1.x`` to + continue using the latest features. You may refer to the + official `Qiskit 1.0 Migration Guide `_ + for detailed instructions and examples on how to upgrade Qiskit. + + ---- Ready to get going?... diff --git a/docs/index.rst b/docs/index.rst index ee045ff58..1ef849bda 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -5,58 +5,63 @@ Qiskit Machine Learning overview Overview ============== -Qiskit Machine Learning introduces fundamental computational building blocks - such as Quantum Kernels -and Quantum Neural Networks - used in different applications, including classification and regression. -On the one hand, this design is very easy to use and allows users to rapidly prototype a first model -without deep quantum computing knowledge. On the other hand, Qiskit Machine Learning is very flexible, -and users can easily extend it to support cutting-edge quantum machine learning research. - -Qiskit Machine Learning provides the :class:`~qiskit_machine_learning.kernels.FidelityQuantumKernel` -class class that makes use of the :class:`~qiskit_algorithms.state_fidelities.BaseStateFidelity` algorithm -introduced in Qiskit and can be easily used to directly compute kernel matrices for given datasets -or can be passed to a Quantum Support Vector Classifier -(:class:`~qiskit_machine_learning.algorithms.QSVC`) or -Quantum Support Vector Regressor (:class:`~qiskit_machine_learning.algorithms.QSVR`) -to quickly start solving classification or regression problems. -It also can be used with many other existing kernel-based machine learning algorithms from established -classical frameworks. - -Qiskit Machine Learning defines a generic interface for neural networks that is implemented by different -quantum neural networks. Two core implementations are readily provided, such as the -:class:`~qiskit_machine_learning.neural_networks.EstimatorQNN` -and the :class:`~qiskit_machine_learning.neural_networks.SamplerQNN`. -The :class:`~qiskit_machine_learning.neural_networks.EstimatorQNN` leverages -the :class:`~qiskit.primitives.BaseEstimator` primitive from Qiskit and allows users to combine -parametrized quantum circuits with quantum mechanical observables. The circuits can be constructed -using, for example, building blocks from Qiskit's circuit library, and the QNN's output is given -by the expected value of the observable. -The :class:`~qiskit_machine_learning.neural_networks.SamplerQNN` leverages another primitive -introduced in Qiskit, the :class:`~qiskit.primitives.BaseSampler` primitive. This neural network -translates quasi-probabilities of bitstrings estimated by the primitive into a desired output. This -translation step can be used to interpret a given bitstring in a particular context, e.g. -translating it into a set of classes. - -The neural networks include the functionality to evaluate them for a given input as well as to compute the -corresponding gradients, which is important for efficient training. To train and use neural networks, -Qiskit Machine Learning provides a variety of learning algorithms such as the -:class:`~qiskit_machine_learning.algorithms.NeuralNetworkClassifier` and -:class:`~qiskit_machine_learning.algorithms.NeuralNetworkRegressor`. -Both take a QNN as input and then use it in a classification or regression context. -To allow an easy start, two convenience implementations are provided - the Variational Quantum Classifier -(:class:`~qiskit_machine_learning.algorithms.VQC`) -as well as the Variational Quantum Regressor (:class:`~qiskit_machine_learning.algorithms.VQR`). -Both take just a feature map and an ansatz and construct the underlying QNN automatically. - -In addition to the models provided directly in Qiskit Machine Learning, it has the -:class:`~qiskit_machine_learning.connectors.TorchConnector`, -which allows users to integrate all of our quantum neural networks directly into the -`PyTorch `__ -open source machine learning library. Thanks to Qiskit Algorithm's gradient algorithms, -this includes automatic -differentiation - the overall gradients computed by `PyTorch `__ -during the backpropagation take into -account quantum neural networks, too. The flexible design also allows the building of connectors -to other packages in the future. +Qiskit Machine Learning introduces fundamental computational building blocks, such as Quantum +Kernels and Quantum Neural Networks, used in various applications including classification +and regression. + +This library is part of the Qiskit Community ecosystem, a collection of high-level codes that are based +on the Qiskit software development kit. As of version ``0.7.0``, Qiskit Machine Learning is co-maintained +by IBM and the Hartree Centre, part of the UK Science and Technologies Facilities Council (STFC). + +The Qiskit Machine Learning framework aims to be: + +* **User-friendly**, allowing users to quickly and easily prototype quantum machine learning models without + the need of extensive quantum computing knowledge. +* **Flexible**, providing tools and functionalities to conduct proof-of-concepts and innovative research + in quantum machine learning for both beginners and experts. +* **Extensible**, facilitating the integration of new cutting-edge features leveraging Qiskit's + architectures, patterns and related services. + +What are the main features of Qiskit Machine Learning? +====================================================== + +Kernel-based methods +--------------------- + +The :class:`~qiskit_machine_learning.kernels.FidelityQuantumKernel` +class uses the :class:`~qiskit_algorithms.state_fidelities.BaseStateFidelity` +algorithm. It computes kernel matrices for datasets and can be combined with a Quantum Support Vector Classifier (:class:`~qiskit_machine_learning.algorithms.QSVC`) +or a Quantum Support Vector Regressor (:class:`~qiskit_machine_learning.algorithms.QSVR`) +to solve classification or regression problems respectively. It is also compatible with classical kernel-based machine learning algorithms. + +Quantum Neural Networks (QNNs) +------------------------------ + +Qiskit Machine Learning defines a generic interface for neural networks, implemented by two core (derived) primitives: + +- :class:`~qiskit_machine_learning.neural_networks.EstimatorQNN` leverages the Qiskit + `Estimator `__ primitive, combining parametrized quantum circuits + with quantum mechanical observables. The output is the expected value of the observable. + +- :class:`~qiskit_machine_learning.neural_networks.SamplerQNN` leverages the Qiskit + `Sampler `__ primitive, + translating bit-string counts into the desired outputs. + +To train and use neural networks, Qiskit Machine Learning provides learning algorithms such as the :class:`~qiskit_machine_learning.algorithms.NeuralNetworkClassifier` +and :class:`~qiskit_machine_learning.algorithms.NeuralNetworkRegressor`. +Finally, built on these, the Variational Quantum Classifier (:class:`~qiskit_machine_learning.algorithms.VQC`) +and the Variational Quantum Regressor (:class:`~qiskit_machine_learning.algorithms.VQR`) +take a *feature map* and an *ansatz* to construct the underlying QNN automatically using high-level syntax. + +Integration with PyTorch +------------------------ + +The :class:`~qiskit_machine_learning.connectors.TorchConnector` +integrates QNNs with `PyTorch `_. +Thanks to the gradient algorithms in Qiskit Machine Learning, this includes automatic differentiation. +The overall gradients computed by PyTorch during the backpropagation take into account quantum neural +networks, too. The flexible design also allows the building of connectors to other packages in the future. + diff --git a/setup.py b/setup.py index 7d7688b9f..0d654e889 100644 --- a/setup.py +++ b/setup.py @@ -72,7 +72,6 @@ extras_require={ 'torch': ["torch"], 'sparse': ["sparse"], - 'nlopt': ["nlopt"] }, project_urls={ "Bug Tracker": "https://github.com/qiskit-community/qiskit-machine-learning/issues", From 2e5d5e3ae3d10fe70523bb8a1cf548b69af4479a Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:58:26 +0200 Subject: [PATCH 6/9] Add words to dictionary --- .pylintdict | 5 +++++ README.md | 2 +- docs/index.rst | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.pylintdict b/.pylintdict index 51c6a9431..724d5bba3 100644 --- a/.pylintdict +++ b/.pylintdict @@ -304,3 +304,8 @@ yoder zoufal zsh θ +nlopt +linux +homebrew +hartree +stfc diff --git a/README.md b/README.md index e63fe9464..bdd2cf926 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ and regression. This library is part of the Qiskit Community ecosystem, a collection of high-level codes that are based on the Qiskit software development kit. As of version `0.7.0`, Qiskit Machine Learning is co-maintained -by IBM and the Hartree Centre, part of the UK Science and Technologies Facilities Council (STFC). +by IBM and the Hartree Center, part of the UK Science and Technologies Facilities Council (STFC). The Qiskit Machine Learning framework aims to be: diff --git a/docs/index.rst b/docs/index.rst index 1ef849bda..767c75bce 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -11,7 +11,7 @@ and regression. This library is part of the Qiskit Community ecosystem, a collection of high-level codes that are based on the Qiskit software development kit. As of version ``0.7.0``, Qiskit Machine Learning is co-maintained -by IBM and the Hartree Centre, part of the UK Science and Technologies Facilities Council (STFC). +by IBM and the Hartree Center, part of the UK Science and Technologies Facilities Council (STFC). The Qiskit Machine Learning framework aims to be: From b0f016644c557efa43aba8c081d7077d78845f80 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Mon, 12 Aug 2024 12:23:35 +0200 Subject: [PATCH 7/9] Reorder dictionary --- .pylintdict | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.pylintdict b/.pylintdict index 724d5bba3..6cf41bd9a 100644 --- a/.pylintdict +++ b/.pylintdict @@ -101,10 +101,12 @@ guang guzik hamiltonian hao +hartree hashable havlíček hilbert hoc +homebrew html hubbard hyperparameter @@ -132,6 +134,7 @@ kwargs labelled lagrange langle +linux lukin macos makefile @@ -156,6 +159,7 @@ nat nbsphinx ndarray nielsen +nlopt nn noancilla nonlocal @@ -250,8 +254,8 @@ sparsearray statevector statevectors stdlib -stdlib stdout +stfc str subclasses subcircuits @@ -304,8 +308,3 @@ yoder zoufal zsh θ -nlopt -linux -homebrew -hartree -stfc From aca85b2bf8e08c74201f16c71ebaec8872b7ca07 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Tue, 13 Aug 2024 13:03:52 +0200 Subject: [PATCH 8/9] Update dictionary --- .pylintdict | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.pylintdict b/.pylintdict index 6cf41bd9a..294ba83ea 100644 --- a/.pylintdict +++ b/.pylintdict @@ -11,6 +11,7 @@ ansatzes args asmatrix aspuru +assertRaises async autoencoder autoencoders @@ -86,6 +87,7 @@ eval expressibility farrokh fidelities +fidelity fidelityquantumkernel formatter frac @@ -233,8 +235,10 @@ reproducibility rescale rhs romero +Rosenbrock runtime runtimes +RuntimeError rx ry rz From e439579d33ab6bfdcf216836e5b0dce4246f6950 Mon Sep 17 00:00:00 2001 From: Edoardo Altamura <38359901+edoaltamura@users.noreply.github.com> Date: Mon, 19 Aug 2024 14:46:51 +0200 Subject: [PATCH 9/9] Fix base state fidelity #823 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6bf7a66b..35f3b6260 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ The Qiskit Machine Learning framework aims to be: ### Kernel-based methods The [`FidelityQuantumKernel`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.kernels.QuantumKernel.html#qiskit_machine_learning.kernels.FidelityQuantumKernel) -class uses the [`Fidelity`](https://qiskit-community.github.io/qiskit-algorithms/stubs/qiskit_algorithms.state_fidelities.BaseStateFidelity.html) +class uses the [`Fidelity`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.state_fidelities.BaseStateFidelity.html)) algorithm. It computes kernel matrices for datasets and can be combined with a Quantum Support Vector Classifier ([`QSVC`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVC.html#qiskit_machine_learning.algorithms.QSVC)) or a Quantum Support Vector Regressor ([`QSVR`](https://qiskit-community.github.io/qiskit-machine-learning/stubs/qiskit_machine_learning.algorithms.QSVR.html#qiskit_machine_learning.algorithms.QSVR)) to solve classification or regression problems respectively. It is also compatible with classical kernel-based machine learning algorithms.