Training sequential models with Q#, using data loaded from JSON

This sample uses Q# and the Microsoft.Quantum.MachineLearning library to train a simple sequential model. The model is trained on a half-moons dataset, loaded in C# using the System.Text.Json package or in Python using the json module, then preprocessed using Q#.

Prerequisites

Running the Sample

This sample can be run in a number of different ways, depending on your preferred environment.

Python in Visual Studio Code or the Command Line

This sample also uses a couple extra Python packages to help out, so you'll need to have those ready as well. If you are using the Anaconda distribution of Python, this can be done automatically by using the environment.yml file provided with this sample:

cd samples/machine-learning/half-moons
conda env create -f environment.yml
conda activate qsharp-sample-classifier

At a terminal, run the following command:

python host.py

C# in Visual Studio Code or the Command Line

At a terminal, run the following command:

dotnet run

C# in Visual Studio 2019

Open the folder containing this sample in Visual Studio ("Open a local folder" from the Getting Started screen or "File → Open → Folder..." from the menu bar) and set HalfMoons.csproj as the startup project. Press Start in Visual Studio to run the sample.

Manifest

  • Training.qs: Q# code implementing quantum operations for this sample.
  • Host.py: Python code to load data, and to interact with and print out results of the Q# operations for this sample.
  • Host.cs: C# code to load data, and to interact with and print out results of the Q# operations for this sample.
  • HalfMoons.csproj: Main C# project for the sample.
  • data.json: JSON-serialized training and validation data used by this sample.