Giter Site home page Giter Site logo

microsoft / mlads2018-quantumml Goto Github PK

View Code? Open in Web Editor NEW
48.0 25.0 27.0 3.08 MB

Introduction to Quantum Machine Learning tutorial: Building a quantum perceptron using Microsoft Quantum Development Kit

License: MIT License

C# 32.98% Q# 67.02%

mlads2018-quantumml's Introduction

This repository has been archived. Please refer to the tutorial on quantum classification with Q# for the latest version of the tutorial.

Welcome!

This repository contains the materials for the "Introduction to Quantum Machine Learning" workshop.

In this workshop the participants will get hands-on experience implementing the simplest quantum machine learning algorithm - a quantum perceptron.

Installing and Getting Started

To work on this tutorial, you'll need to install the Quantum Development Kit, available for Windows 10, macOS, and for Linux. Please see the install guide for the Quantum Development Kit for the detailed instructions. We recommend that you use Visual Studio 2017 or Visual Studio Code.

If you have Git installed, go on and clone the Microsoft/MLADS2018-QuantumML repository. From your favorite command line:

git clone https://github.com/Microsoft/MLADS2018-QuantumML.git

TIP: Both Visual Studio 2017 and Visual Studio Code make it easy to clone repositories from within your development environment. See the Visual Studio 2017 and Visual Studio Code documentation for details.

If you don't have Git installed, you can manually download a standalone copy of the tutorials.

Tutorial Structure

The tutorial contains the template of the algorithm which you will work on and the classical harness used for running your code. The project is laid out as below.

README.md                           # Tutorial instructions
QuantumPerceptron/
  QuantumPerceptron.sln             # Visual Studio 2017 solution file.
  QuantumPerceptron.csproj          # Project file used to build both classical and quantum code.

  QuantumClassifier.qs              # Q# source code containing the template of the quantum perceptron.
  QuantumClassifier_Easy.qs         # Q# source code containing the implementations of the quantum perceptron.
  ClassicalDriver.cs                # C# source code used to load the data, invoke the Q# code and do classical processing.

To open the tutorial in Visual Studio 2017, open the QuantumPerceptron.sln solution file.

To open the tutorial in Visual Studio Code, open the QuantumPerceptron/ folder. Press Ctrl + Shift + P / โŒ˜ + Shift + P to open the Command Palette and type "Open Folder" on Windows 10 or Linux or "Open" on macOS.

TIP: Almost all commands available in Visual Studio Code can be found in the Command Palette. If you ever get stuck, press Ctrl + Shfit + P / โŒ˜ + Shift + P and type some letters to search through all available commands.

TIP: You can also launch Visual Studio Code from the command line if you prefer:

code QuantumPerceptron/

Working on the Tutorial

Once you have the project open, you can build it and run it (F5 in Visual Studio, dotnet run in Visual Studio Code terminal or command line).

Initially the quantum code does nothing and always reports classification success rate of -1. Once you fill in the correct code in QuantumClassifier.qs file, the code will learn the model parameter which provides the best separation of the given classes. If you get stuck or run out of time and just want to see the model train, QuantumClassifier_Easy.qs file contains the full code for model training. You can look up the place in which you got stuck or switch to running the code in that file.

As a stretch goal, try to implement the classical harness and the quantum classification circuit to generate new data and classify it using your trained model.

Useful Links

  • You can find Q# language quick reference here.

  • To improve your experience in the workshop, we suggest you to go through the BasicGates kata from the Quantum Katas project. It teaches you the basic gates used in quantum computing and helps you get more comfortable with Q#. Superposition and Measurement katas are the next best follow-up topics.

  • You can find the slides used in the introductory part of the workshop here.


Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

mlads2018-quantumml's People

Contributors

lokijota avatar microsoftopensource avatar msftgits avatar tcnickolas 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

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

mlads2018-quantumml's Issues

Inconsistency between documentation and code

The version of ClassicalDriver.cs in the repo refers incorrectly to the already implemented QuantumClassifier_SuccessRate_Easy and not to QuantumClassifier_SuccessRate, so when you run the code for the first time it already works, contradicting the readme notes.

Wrong definition of SaveAsCsv

It is:

static void SaveAsCsv(double[] data, int[] labels)

should be:

static void SaveAsCsv(double[] data, long[] labels)

Generates a compilation error when uncommenting the SaveAsCsv call.

Error generating data angles

The version of the code as-is always generates values (considering that the seed of the random generator is fixed at 123) between Min -0.978941001912466 and Max 4.94084872741803.

However the code of the driver states:

// Do a ternary search on the classification angle (we know that the angle is between 0 and 2*PI).

and then the boundaries are set at:

double l = 0.0, r = 2 * Math.PI;

I'd either fix the code to generate values in the correct range, or fix the comment and ranges.

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.