Skip to main content

High level Python interface to abzu qlattice

Project description

Feyn: AI by Abzu

Feyn is a Python library that pushes machine learning to a new level by taking strong inspiration from quantum physics. A Feyn-model is based on the path integral formulation of quantum physics originally proposed by the American physicist Richard P. Feynman.

Feyn-model is in many ways similar to Neural Network (or Deep Learning) models, so some of the concepts may be familiar to you already. But at it's core, the Feyn-model introduces a new way to work with your data together with a revolutionary way to accumulate and transfer learnings.

But let's start with the basics.

To generate a Feyn-model you need access to a Qlattice, short for Quantum Lattice. A QLattice is a high-performance quantum simulator that runs on dedicated hardware. To learn more about getting access to a QLattice, visit www.abzu.ai

The other needed component is this Python package (feyn) that runs on your computer and accumulate learnings from your data. These learnings are communicated to your QLattice over the network.

A QLattice is the heart of a Feyn-model. The QLattice is divided into 2 different parts: the registers and the interactions.

The registers are what we use to interact with the QLattice. They are the input and output interface of a Feyn-model. There are different register types, but the basics are continuous and categorical. The output register is always continuous. More on this later.

The interactions layer is where the learnings are stored and is what we use to extract the QGraphs.

The QGraph represents all possible graphs, from the input registers to the output register. In human words that means all possible explanations for the given output with the given inputs, suggested by the qlattice.

Getting started: Feyn in 1 min

Ok, all this sounds good! But in practice how does this work?

Let us walk through a simple classification problem, step by step.

Create a blank QLattice.

from feyn import QLattice
ql = QLattice()
ql

Read the example dataset and add a register for each column in the dataset.

import sklearn.datasets
import pandas as pd

X, y = sklearn.datasets.load_breast_cancer(return_X_y=True)

in_registers = []
_data = {}

for i in range(X.shape[1]):
    label = 'inp_%i' % i
    _data[label] = X[:, i]
    in_registers.append(ql.add_register(label=label, register_type="cont"))

X = pd.DataFrame(_data)
out_reg = ql.add_register(label='out')

Now the QLattice is prepared for your problem.

Next, run for some epochs, where you retrieve a new QGraph, tune it, and update the QLattice with the learnings from the best graph.

The update calls will bias the QLattice from your learnings. Meaning that next time you call QLattice.get_qgraph, the QGraph will fit your problem better.

from sklearn.model_selection import train_test_split

X_test, X_train, y_test, y_train = train_test_split(X, y, test_size=0.33)

for _ in range(10):
    qgraph = ql.get_qgraph(in_registers, out_reg)
    qgraph.tune(X_train, y_train, epochs=10)
    best_graph = qgraph.graphs[0]
    ql.update(best_graph)

Finally, evaluate the results in the test dataset.

from feyn import tools

prediction = best_graph.predict(X_test)
tools.plot_confusion_matrix(y_true=y_test,
                                y_pred=prediction.round(),
                                title="Evaluation Results")

For a detailed tutorial about Feyn continue with:

  • Getting Started with Feyn
  • Building complex trainers

Installation

Feyn is available as python package distributed from PyPi server.

Requirements:

  • OS: Linux
  • Python 3.6, 3.7 or 3.8
  • Graphviz is used to draw charts (optional):
foo@bar:~$ sudo apt install graphviz

You can install it with the following command

foo@bar:~$ pip3 install feyn

Alternatively or if you don't have Linux OS you can use the jupyterlab Docker image.

foo@bar:~$ docker run -it --net=host abzu/jupyterlab:latest

adding the current folder as /data to the working directory.

foo@bar:~$ docker run -it --net=host -v $(pwd):/data abzu/jupyterlab:latest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for feyn, version 1.0.3
Filename, size File type Python version Upload date Hashes
Filename, size feyn-1.0.3-cp36-cp36m-macosx_10_14_x86_64.whl (41.8 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.0.3-cp36-cp36m-macosx_10_15_x86_64.whl (41.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.0.3-cp36-cp36m-manylinux1_x86_64.whl (109.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.0.3-cp36-cp36m-manylinux2014_x86_64.whl (109.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.0.3-cp37-cp37m-macosx_10_14_x86_64.whl (41.8 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.0.3-cp37-cp37m-macosx_10_15_x86_64.whl (41.9 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.0.3-cp37-cp37m-manylinux1_x86_64.whl (114.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.0.3-cp37-cp37m-manylinux2014_x86_64.whl (114.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.0.3-cp38-cp38-macosx_10_14_x86_64.whl (41.9 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.0.3-cp38-cp38-macosx_10_15_x86_64.whl (42.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.0.3-cp38-cp38-manylinux1_x86_64.whl (113.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.0.3-cp38-cp38-manylinux2014_x86_64.whl (113.1 kB) File type Wheel Python version cp38 Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page