Coder Social home page Coder Social logo

xanaduai / quantum-neural-networks Goto Github PK

View Code? Open in Web Editor NEW
295.0 25.0 86.0 1.03 MB

This repository contains the source code used to produce the results presented in the paper "Continuous-variable quantum neural networks". Due to subsequent interface upgrades, these scripts will work only with Strawberry Fields version <= 0.10.0.

Home Page: https://arxiv.org/abs/1806.06871

License: Apache License 2.0

Python 100.00%
quantum quantum-computing photonics machine-learning optimization tensorflow quantum-machine-learning deep-learning

quantum-neural-networks's Introduction

Continuous-variable quantum neural networks

This repository contains the source code used to produce the results presented in "Continuous-variable quantum neural networks".


Requirements

To construct and optimize the variational quantum circuits, these scripts and notebooks use the TensorFlow backend of Strawberry Fields. In addition, matplotlib is required for generating output plots.

Due to subsequent interface upgrades, these scripts will work only with the following configuration

  • Strawberry Fields version 0.10.0
  • TensorFlow version 1.3
  • Python version 3.5 or 3.6

Your version of Python can be checked by running python --version. The correct versions of StrawberryFields and TensorFlow can be installed by running pip install -r requirements.txt from the main directory of this repository.

Contents

  • Function fitting: The folder function_fitting contains the Python script function_fitting.py, which automates the process of fitting classical functions using continuous-variable (CV) variational quantum circuits. Simply specify the function you would like to fit, along with other hyperparameters, and this script automatically constructs and optimizes the CV quantum neural network. In addition, training data is also provided.

  • Quantum autoencoder: coming soon.

  • Quantum fraud detection: The folder fraud_detection contains the Python script fraud_detection.py, which builds and trains a hybrid classical/quantum model for fraud detection. Additional scripts are provided for visualizing the results.

  • Tetrominos learning: The folder tetrominos_learning contains the Python script tetrominos_learning.py, which trains a continuous-variable (CV) quantum neural network. The task of the network is to encode 7 different 4X4 images, representing the (L,O,T,I,S,J,Z) tetrominos, in the photon number distribution of two light modes. Once the training phase is completed, the script plot_images.py can be executed in order to generate a .png figure representing the final results.

Using the scripts

To use the scripts, simply set the input data, output data, and hyperparametersby modifying the scripts directly - and then enter the subdirectory and run the script using Python 3:

python3 script_name.py

The outputs of the simulations will be saved in the subdirectory.

To access any saved data, the file can be loaded using NumPy:

results = np.load('simulation_results.npz')

Authors

Nathan Killoran, Thomas R. Bromley, Juan Miguel Arrazola, Maria Schuld, Nicolás Quesada, and Seth Lloyd.

If you are doing any research using this source code and Strawberry Fields, please cite the following two papers:

Nathan Killoran, Thomas R. Bromley, Juan Miguel Arrazola, Maria Schuld, Nicolás Quesada, and Seth Lloyd. Continuous-variable quantum neural networks. Physical Review Research, 1(3), 033063 (2019).

Nathan Killoran, Josh Izaac, Nicolás Quesada, Ville Bergholm, Matthew Amy, and Christian Weedbrook. Strawberry Fields: A Software Platform for Photonic Quantum Computing. arXiv, 2018. Quantum, 3, 129 (2019).

License

This source code is free and open source, released under the Apache License, Version 2.0.

quantum-neural-networks's People

Contributors

andreamari avatar co9olguy avatar josh146 avatar trbromley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

quantum-neural-networks's Issues

Error running the roc.py file

I'm getting a latex error when attempting to run the roc.py code. I installed latex, but the problem is still persisting. Any help would be appreciated. Thanks.

ENV:**
Colab
!pip install strawberryfields==0.11.0 tensorflow==1.3.0
set to GPU

COMMAND RAN
!python roc.py

ERROR MESSAGE:*************************
Area under ROC curve: 0.5882831367606355
Closest threshold to optimal ROC: 0.46
Traceback (most recent call last):
File "roc.py", line 76, in
plt.savefig('./roc.pdf')
File "/usr/local/lib/python3.6/dist-packages/matplotlib/pyplot.py", line 689, in savefig
res = fig.savefig(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py", line 2094, in savefig
self.canvas.print_figure(fname, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/backend_bases.py", line 2075, in print_figure
**kwargs)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_pdf.py", line 2565, in print_pdf
self.figure.draw(renderer)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/figure.py", line 1649, in draw
renderer, self, artists, self.suppressComposite)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/axes/_base.py", line 2628, in draw
mimage._draw_list_compositing_images(renderer, self, artists)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/image.py", line 138, in _draw_list_compositing_images
a.draw(renderer)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/artist.py", line 50, in draw_wrapper
return draw(artist, renderer, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/axis.py", line 1187, in draw
renderer)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/axis.py", line 1125, in _get_tick_bboxes
extent = tick.label1.get_window_extent(renderer)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/text.py", line 930, in get_window_extent
bbox, info, descent = self._get_layout(self._renderer)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/text.py", line 304, in _get_layout
ismath=False)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/backends/backend_pdf.py", line 2126, in get_text_width_height_descent
renderer=self)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/texmanager.py", line 464, in get_text_width_height_descent
dvifile = self.make_dvi(tex, fontsize)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/texmanager.py", line 328, in make_dvi
texfile], tex)
File "/usr/local/lib/python3.6/dist-packages/matplotlib/texmanager.py", line 298, in _run_checked_subprocess
stderr=subprocess.STDOUT)
File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
**kwargs).stdout
File "/usr/lib/python3.6/subprocess.py", line 423, in run
with Popen(*popenargs, **kwargs) as process:
File "/usr/lib/python3.6/subprocess.py", line 729, in init
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'latex': 'latex'

Files not found error

Thanks for such a fabulous working. I want to run the script but facing error messages. When I try to run data_processor.py file it gives an error message of file not found. creditcard.csv
When I try to run fraud_detection.py file it also gives an error message of file not found. creditcard_genuine_1.csv
Do we have to create these files at our own or these are found at some other place.

Number of hidden and output neurons for different dataset

I have got a dataset of shape (2820520, 15), which has 14 independent features and 1 binary target feature. I'm performing SMOTE instead of undersampling on this QNN model using that particular dataset. What should be the number of neurons in this case? Is there anything that I need to modify for that particular dataset?

[Note: The features are not PCAs like credit card data]

TypeError: backend must be a string or a BaseBackend instance.

When I run the function_fitting.py & fraud_detection.py, there was a same error
TypeError: backend must be a string or a BaseBackend instance.
When the code runs to this line
eng, q = sf.Engine(1)

btw, the version of tensorflow and strawberryfields in my environment are 1.3.0 and 0.13.0

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.