Skip to content

qdev-dk/SingleShotClassifier

Repository files navigation

Single Shot Classifier

Introduction

The Readout Tool is a extension of the Qunatum Fitter package. It's pourpeses is to give the user a esay to use module to classify quantum states. This is done by using sklearn moduels for machine learning. The main focus of this package is support vector machines (SVM). The different kinds of SVM kernels are as follows:

  • linear: A linear classifier.
  • poly: A polynomial classifier.
  • rbf: A Radial Basis Function (RBF) kernel SVM.
  • sigmoid: A Hyperbolic Tangent Kernel.
  • (precomputed): Haven't looked at this yet.

The code mainly uses sklearn's SVM module, but the follwing types of classifiers can be implemented directly in the code:

Documentation

Module documentation can be found at HER.

There is a lot more information written in the documentation file. Underneath is a quick overview of the how to use the module.

How to use the package

Underneath are some of the main functionality highlighted in symbol examples.

Example One - Arrays

To begin using the module get your groundstate and excited state QI vectors and Make sure they are in the right formate ([[i,q],[i,q],...]. The formating can be done by using the rdt.reformate function.

import quantum_fitter.readout_tools as rdt
import Labber as lab
import os

# Data setup
dir = os.path.dirname(__file__)
file_path = os.path.join(dir, 'example_data/ss_q1_rabi_v_ampl_5_fine.hdf5')

file = lab.LogFile(file_path)
data = rdt.reformate(file.getData())

state_0, state_1 = data[0], data[40]
states = [state_0,state_1] # in [[i,q],[i,q],...] formate.

When you got the data in the right formate, your able to run the package like so:

# Set the instence 
rd = rdt.Readout(data=states, size=1000, verbose=1)

# Plot
rd.plot_classifier() # this plots the classifier with the data used for the fitting.

# Use
rd.predict(data[1]) # this returns a list of states for the single shot in data[1].

If a h5data file is available import this directly instead of only the QI vecrtors (see example two).

Example Two - H5data file

To begin using the module get your h5data file path run it like shown.

import quantum_fitter.readout_tools as rdt
import os

# Set up path
dir = os.path.dirname(__file__)
file_path = os.path.join(dir, 'example_data/ss_q1_rabi_v_ampl_5_fine.hdf5')

# Set the instence 
rd = rdt.Readout(file_path, size=1000, verbose=1)

# Plot
rd.plot_classifier()

This will return a plot of the classifier and training data used for determination.

Example Three - predicting

To use a classifier to predict the state of a single shot, run the following line.

rd.predict(data)

where data is the QI-array or single-shot you want the predict.

Example Four - saveing

After estimating a classifier you can save it as a pickle file, so that you keep the same classifier.

import quantum_fitter.readout_tools as rdt

# Set the instence 
rd = rdt.Readout(file_path, size=1000, verbose=1)

# Fitting the classifier
rd.do_fit()

# Exporting classifier
rd.export_classifier(filePath=somewhere/on/your/computer/)

# Importing classifier 
rdt.import_classifier(filePath=somewhere/on/your/computer/)

If successful important print state will show as "Got your pickle!"

Futher examples

There are more examples located in the example folder.

Information

This submodule has been created and are being maintained by Malthe Asmus Marciniak Nielsen

mail: [email protected], github: MaltheAN

If there any questions please feel free to contact me.

Running the tests

If you have gotten 'single_shot_classifier' from source, you may run the tests locally.

Install single_shot_classifier along with its test dependencies into your virtual environment by executing the following in the root folder

$ pip install .
$ pip install -r test_requirements.txt

Then run pytest in the tests folder.

Building the documentation

If you have gotten single_shot_classifier from source, you may build the docs locally.

Install single_shot_classifier along with its documentation dependencies into your virtual environment by executing the following in the root folder

$ pip install .
$ pip install -r docs_requirements.txt

You also need to install pandoc. If you are using conda, that can be achieved by

$ conda install pandoc

else, see here for pandoc's installation instructions.

Then run make html in the docs folder. The next time you build the documentation, remember to run make clean before you run make html.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages