Skip to main content

Feyn is the high level Python interface to interact with an 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 models have similarities with other machine learning models such as random forest models or neural networks, 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. 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.

The QLattice is a high-performance quantum simulator that runs on dedicated hardware, hosted on a cluster. It is based on the path integral formulation, which is an approach to quantum mechanics that was originally proposed by the American physicist Richard P. Feynman. For all the curious individuals, the path integral formulation, in very simple words, evaluates the relations between two points by considering and summing all the different possibilities of trajectories between those points.

The QLattice can be divided into 2 parts: Registers and Interactions.

The registers are what we use to interact with the QLattice. They are the input and output interface of a Feyn model. Often they are the features of your data set.

The interactions are the basic computation units of the QLattice. They hold their own state and transform input data into output. It is how learnings are stored and what is used to extract the QGraphs.

The QGraph, short for Quantum Graph, represents all possible combinations connecting the input registers to the output register. That means all possible explanations for the given output with the given inputs, generated by the QLattice.

If you are interested in learning more about what a QLattice is, and how it works, then you should definately take a look at the in-depth documentation here.

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.

For this quick walk-through we will pick a simple classification problem. The breast cancer dataset which is bundled with sklearn.

This will show you the core concepts in building a graph to execute predictions, that you can deploy to your application.

Connect to your QLattice

from feyn import QLattice

qlattice = QLattice(url = "<URL to your qlattice>", api_token="<Your API token>")

Read in the data

Read in an example data set (here we use the breast cancer data set which is shipped with scikit-learn)

import sklearn.datasets
import pandas as pd

breast_cancer = sklearn.datasets.load_breast_cancer()

# Convert to a pandas dataframe
df = pd.DataFrame(breast_cancer.data,columns=breast_cancer.feature_names)
df['target'] = pd.Series(breast_cancer.target)
df.head()

Train locally and update learnings remotely

Retrieve a QGraph which represents an ordered list of all possible models to solve the problem. The first parameter is a list of all the concepts or features you wanr

# Get a classifier QGraph from the remote QLattice
qgraph = qlattice.get_classifier(data.columns, target="target")

Next, run for some epochs, where you fit the QGraph to the training data, 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.fit, the new graphs found will fit your problem better.

Notice, that the QLattice lives remotely on the Abzu cluster, but it never sees your local data. The dataset stays on your premise. So, you train locally, and just transmit your learnings to the QLattice. That is the way the QLattice gets better at producing QGraphs that fits your problem.

from sklearn.model_selection import train_test_split

train, test = train_test_split(df, test_size=0.33)

for _ in range(10):
    # Fit the local QGraph with your local data
    qgraph.fit(train)

    # Pich the graph with lowest loss on the training dataset as the best solution.
    best_graph = qgraph[0]

    # Teach the QLattice about this solution, so that it gets biased towards solutions similar to this.
    qlattice.update(best_graph)

Evaluate

Finally, evaluate the results in the test dataset. This is also how you utilize the Graph for predictions in your application.

from feyn import tools

# Use the graph to produce predictions. This graph is similar your model in other framework.
# It is the thing you can save to a file, and deploy to your application or production environment.
predictions = best_graph.predict(X_test)

# This is a classification problem, but we are using a regression model to solve it.
# There are many ways to do this. In this example we will round to nearest integer (the class).
predictions = predictions.round()

tools.plot_confusion_matrix(y_true=test["target"],
                            y_pred=predictions,
                            title="Evaluation Results")

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.5.3
Filename, size File type Python version Upload date Hashes
Filename, size feyn-1.5.3-cp36-cp36m-macosx_10_14_x86_64.whl (176.0 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.5.3-cp36-cp36m-macosx_10_15_x86_64.whl (176.1 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.5.3-cp36-cp36m-manylinux1_x86_64.whl (285.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.5.3-cp36-cp36m-manylinux2014_x86_64.whl (285.4 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.5.3-cp36-cp36m-win32.whl (179.9 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.5.3-cp36-cp36m-win_amd64.whl (183.7 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size feyn-1.5.3-cp37-cp37m-macosx_10_14_x86_64.whl (176.0 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.5.3-cp37-cp37m-macosx_10_15_x86_64.whl (176.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.5.3-cp37-cp37m-manylinux1_x86_64.whl (291.9 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.5.3-cp37-cp37m-manylinux2014_x86_64.whl (291.9 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.5.3-cp37-cp37m-win32.whl (174.8 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.5.3-cp37-cp37m-win_amd64.whl (179.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size feyn-1.5.3-cp38-cp38-macosx_10_14_x86_64.whl (176.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.5.3-cp38-cp38-macosx_10_15_x86_64.whl (176.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.5.3-cp38-cp38-manylinux1_x86_64.whl (292.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.5.3-cp38-cp38-manylinux2014_x86_64.whl (292.5 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.5.3-cp38-cp38-win32.whl (175.0 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.5.3-cp38-cp38-win_amd64.whl (179.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size feyn-1.5.3-cp39-cp39-macosx_10_14_x86_64.whl (176.2 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size feyn-1.5.3-cp39-cp39-macosx_10_15_x86_64.whl (176.2 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size feyn-1.5.3-cp39-cp39-manylinux1_x86_64.whl (292.9 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size feyn-1.5.3-cp39-cp39-manylinux2014_x86_64.whl (292.9 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size feyn-1.5.3-cp39-cp39-win32.whl (175.0 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size feyn-1.5.3-cp39-cp39-win_amd64.whl (179.4 kB) File type Wheel Python version cp39 Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page