Giter VIP home page Giter VIP logo

arfmatos / quantum-single-layer-perceptron Goto Github PK

View Code? Open in Web Editor NEW

This project forked from amacaluso/quantum-single-layer-perceptron

1.0 0.0 0.0 8.45 MB

This repository contains the code to reproduce the results in the paper A Variational algorithm for Quantum Neural Networks, accepted in the International Conference on Computational Science 2020, Quantum Computing track.

License: Apache License 2.0

Python 100.00%

quantum-single-layer-perceptron's Introduction

qSLP: A Variational Algorithm for Quantum Neural Networks

This repository contains the code to reproduce the results in the paper A Variational algorithm for Quantum Neural Networks, published in the International Conference on Computational Science 2020, Quantum Computing track.

Description

We introduce a novel variational algorithm for quantum Single Layer Perceptron. In particular, we design a quantum circuit to perform linear combinations in superposition and discuss adaptations to classification tasks. After this theoretical investigation, we also provide practical implementations using various simulation environments. Finally, we test the proposed algorithm on synthetic data exploiting both simulators and real quantum devices.

Quantum Circuit

Intuitively, a qSLP can be implemented into a quantum computer in two steps. Firstly, we generate different linear operations in superposition, each one having different parameters , entangled with a control register. Secondly, we propagate the activation function to all the linear combinations in superposition. To this end, three quantum registers are necessary: control, data and temp. The latter is responsible for generating the linear combinations of the input data in superposition.

The circuit above leads to the following quantum state:

where the two linear operations, , are put through the same activation function, , represented by the gate . Each output is weighed by the parameters of the control qubit , i.e. the coefficients attached to the hidden neurons in the linear combination that produces the output of the NN. This is exactly the quantum version of the two-neurons classical SLP.

Thus, the quantum circuit described above allows reproducing a classical Neural Network with one hidden layer on a quantum computer.

Usage

The code implements all the experiments regarding the implementation of the quantum Single Layer Perceptron using two frameworks for quantum computation: the qml_ scripts use pennylane and reproduce the experiments reported in the paper. The qiskit_ scripts use Qiskit and allow to visualize easily the quantum circuit. The qSLP works well in both cases, this strengthens the validity of the model which is independent from the implementation.

Pennylane implementation:

  • The script qml_qSLP.py contains the code for generating data and training a single classifier.

  • The script qml_multiple_runs.py generates many dataset from two bivariate gaussian distributions with different standard deviations and trains the classifier for each of them.

  • The script qml-qiskit_real_device.py executes the trained algorithm on real device, using a specific plug-in that allows to run the circuit using qiskit environment.

  • The script qml_Utils.py contains the import of the needed packages and all the custom routines for evaluation.

  • The script qml_visualization.py plots the data and the performances of the classifier.

  • The script qml_collect_results_rl.py collects the results generated by running the quantum algorithm in a real device.

Some of the functions for optimisation are taken from https://pennylane.ai/qml/demos/tutorial_variational_classifier.html

Qiskit implementation:

  • The script qiskit_qSLP.py contains the code for generating data and training a single classifier. Also it allows to visualise the two-layer qSLP.

  • The script qiskit_Utils.py contains the import of the needed packages and all the custom routines for evaluation.

Issues

For any issues or questions related to the code, open a new git issue or send a mail to [email protected]

quantum-single-layer-perceptron's People

Contributors

amacaluso avatar

Stargazers

Ângelo Matos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.