Skip to main content

A quantum convolutional neural network library.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hqccnn-0.1.1.tar.gz (31.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hqccnn-0.1.1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file hqccnn-0.1.1.tar.gz.

File metadata

  • Download URL: hqccnn-0.1.1.tar.gz
  • Upload date:
  • Size: 31.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for hqccnn-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c219e49b444b1aa1f42ae362b3ff54a22ad26b5a34fcf996fc57050fd0a047a1
MD5 36c3e270d524612d7a4fd13a44265605
BLAKE2b-256 0a9429e09ddd75f4fa9da55c20051865b7a194596e14b3577770eb4099bdb955

See more details on using hashes here.

File details

Details for the file hqccnn-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: hqccnn-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for hqccnn-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 593b9d8e51f6fe1f796ba8226ea5c93e7a57a0b55cb65facf1d2ac41a23d2fcc
MD5 452e962a68adf98ed197760ab0d10273
BLAKE2b-256 37fa9102bd96eb878944c8fe71621b95ceb6db5af851a7693e5dea48ab30ead0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page