Skip to main content

Noisy hybrid quantum-classical convolutional neural networks for multi-class image classification

Key features

This library allows to investigate the performance of a noisy hybrid quantum-classical convolutional neural networks and compare it to its classical counterpart.

The library allows to create, train and validate CNNs composed of:

  • a single quantum convolutional layer;
  • a flattening operation;
  • a single fully-connected layer.

As in the classical case, the quantum convolutional layer acts on the input image by extracting sliding blocks from it and performing an operation - called filtering - on each of these blocks. However, unlike the ordinary case, the filtering operation relies upon the execution of a (variational) quantum circuit. More specifically, the $N$ pixel values of each sliding block are mapped into a $N$-qubit variational quantum circuit (VQC) by means of a particular arrangement of non-trainable parametric quantum gates, which compose the so-called "feature map". The remaining part of the VQC, usually referred to as "ansatz", features trainable parametric quantum gates. Finally, the VQC is executed a number of times and measurements in the computational basis on the output quantum state are performed, so to give an estimate for its $2^N$ probability coefficients. The obtained $2^N$ real values are fed into the $2^N$ output images, which are then created by means of a single filter. The number of trainable parameters in the ansatz can be chosen arbitrarily, so that one could in principle explore the chance to obtain better performance with fewer parameters.

The parameters update of the whole net is performed by means of the mini-batch gradient descent algorithm. In order to differentiate the quantum filter's output, the parameter-shift rule is applied.

The whole model is inspired to that proposed by Junhua Liu [1].

Users have to possibility to decide whether to execution the VQC contained within the filter with or without quantum noise. Moreover, they can choose to introduce one or more noise models.

Installation

  1. Clone the repository
  2. Create a virtual environment
  3. In the terminal, run the command "# pip install torch==2.5.1+cu121 torchvision==0.20.1+cu121 --index-url https://download.pytorch.org/whl/cu121"
  4. In the terminal, run the command "pip install -e ." to install the package and all its dependencies.

Usage

To use the library, follow the steps below.

  1. Set the quantum filter architecture (feature map, ansatz, noise etc.), the model hyperparameters (epochs, learning rate etc.), the path of the dataset (dataset_folder_path) and the path of the csv file for saving the evolution of the metrics along the training (csv_path) in the configuration file. The configuration file location is src/lutec_quantum_cnn/conf/config.yaml.
  2. Execute "qccnn" in the terminal to start training and testing. The evolution of the metrics along the training procedure are saved in results.

A default 4-class synthetic dataset of 3x3 images, called 'Tetris', is placed in the root directory of the library. This dataset is composed of 640 training images, 160 validation images and 200 test images. Each image represent a tetris brick. The grey value of the brick pixels is randomly chosen between 0.7 and 1, whereas that of the background pixels between 0 and 0.3.

Author

Giuseppe D'Ambruoso (Lutech S.p.A., University of Bari Aldo Moro).

Acknowledgements

This library was realized with the indinspensable help of dr. Dario del Sorbo (Lutech S.p.A.), dr. Claudio Basilio Caporusso (Lutech S.p.A.), dr. Ivan Palmisano (Lutech S.p.A.), dr. Giuseppe Lamanna (Lutech S.p.A.) and prof. dr. Giovanni Gramegna (University of Bari Aldo Moro). We acknowledge also the support from the whole Lutech R&D 'MILE' pole, directed by dr. Giuseppe Ieva (Lutech S.p.A.).

References

[1] Liu et al. (2021). Hybrid quantum-classical convolutional neural networks. Science China Physics, Mechanics & Astronomy. DOI: 10.1007/s11433-021-1734-3. url: http://dx.doi.org/10.1007/s11433-021-1734-3.

Metadata

Release files for hqccnn 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hqccnn 0.1.1
File Size Uploaded Provenance Actions
hqccnn-0.1.1.tar.gz 31.9 kB Without provenance Details for hqccnn-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for hqccnn 0.1.1
File Interpreter ABI Platform Actions
hqccnn-0.1.1-py3-none-any.whl Python 3 none any Details for hqccnn-0.1.1-py3-none-any.whl

Total release size: 64.0 kB

Release files / hqccnn-0.1.1.tar.gz

Download URL hqccnn-0.1.1.tar.gz
Size 31.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c219e49b444b1aa1f42ae362b3ff54a22ad26b5a34fcf996fc57050fd0a047a1
BLAKE2b-256 checksum
How to use checksums
0a9429e09ddd75f4fa9da55c20051865b7a194596e14b3577770eb4099bdb955
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / hqccnn-0.1.1-py3-none-any.whl

Download URL hqccnn-0.1.1-py3-none-any.whl
Size 32.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
593b9d8e51f6fe1f796ba8226ea5c93e7a57a0b55cb65facf1d2ac41a23d2fcc
BLAKE2b-256 checksum
How to use checksums
37fa9102bd96eb878944c8fe71621b95ceb6db5af851a7693e5dea48ab30ead0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for hqccnn 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page