qdevpsi3 / qml-qcnn

Python implementation of Quantum Algorithms for Deep Convolutional Neural Networks (Kerenidis, Landman and Prakash, 2019)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Quantum Algorithms for Deep Convolutional Neural Networks

paper framework packages license exp

Description

This repository contains an implementation of the quantum convolutional layer and its application to the MNIST classification task in :

  • Paper : Quantum Algorithms for Deep Convolutional Neural Networks
  • Authors : Kerenidis, Landman and Prakash
  • Date : 2019

Setup

To install the quantum convolutional layer, clone this repository and execute the following commands :

$ cd qml-qcnn
$ pip install -e .

Details

The quantum convolutional layer is a PyTorch module with the following parameters :

  • in_channels (int): number of input channels.
  • out_channels (int): number of output channels.
  • kernel_size (int): size of the convolution kernel.
  • eps (float): precision of quantum multiplication.
  • cap (float): value for cap 'relu' activation function.
  • ratio (float): precision of quantum tomography.
  • delta (float): precision of quantum gradient estimation.
  • stride (int, optional): convolution stride. Defaults to 1.
  • padding (int, optional): convolution padding. Defaults to 0.
  • dilation (int, optional): convolution dilation. Defaults to 1.

The bias is unsupported for now.

Example

In Pytorch, you can use the 2D convolution module as follows :

from torch import nn

torch_conv2d = nn.Conv2d(16, 32, 3, stride=1)

Similarly, you can use the 2D quantum convolution module as follows :

import qcnn

eps = 0.01
cap = 10.
ratio = 0.5
delta = 0.01

quantum_conv2d = qcnn.QuantumConv2d(16, 32, 3, eps, cap, ratio, delta, stride=1)

Experiments

The experiments in the paper are reproduced for MNIST classification task using PyTorch Lightning.

  • Option 1 : Open in Colab. You can activate the GPU in Notebook Settings.
  • Option 2 : Run on local machine. First, you need to install PyTorch Lightning :
$ pip install pytorch_lightning

You can run an experiment using the following command :

$ cd qml-qcnn/scripts/
$ python mnist_classification --eps=0.01 --cap=10 --ratio=0.5 --delta=0.01

Acknowledgements

About

Python implementation of Quantum Algorithms for Deep Convolutional Neural Networks (Kerenidis, Landman and Prakash, 2019)

License:GNU General Public License v3.0


Languages

Language:Python 100.0%