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 are 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.

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>")
qlattice

Add registers

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

The registers describes your problem. Which features goes in, and which feature do you want to predict. Often the same as the columns in your dataset.

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()

in_registers = []

# Create an input register for each input feature
for feature in breast_cancer.feature_names:
    in_registers.append(qlattice.get_register(label=feature))

# Turn the target column into an output register
out_reg = qlattice.get_register(label='target')

Now the QLattice is prepared for your problem.

Train locally and update learnings remotely

Next, run for some epochs, where you retrieve a new QGraph, fit it 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.get_qgraph, the new QGraph 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):
    # Get a QGraph full of graphs between your inputs and output from the remote QLattice.
    # This QGraph will be biased towards what was learned from the previous `update` calls.
    qgraph = qlattice.get_qgraph(in_registers, out_reg)

    # Now fit the local QGraph with your local data
    qgraph.fit(train, epochs=10)

    # Select the graph with lowest loss on the training dataset as the best solution.
    # You could consider other attributes as your "best" (accuracy, complexity, etc.).
    best_graph = qgraph.select(test)[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.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

feyn-1.1.0b3-cp38-cp38-manylinux2014_x86_64.whl (138.5 kB view details)

Uploaded CPython 3.8

feyn-1.1.0b3-cp38-cp38-manylinux1_x86_64.whl (138.5 kB view details)

Uploaded CPython 3.8

feyn-1.1.0b3-cp37-cp37m-manylinux2014_x86_64.whl (140.0 kB view details)

Uploaded CPython 3.7m

feyn-1.1.0b3-cp37-cp37m-manylinux1_x86_64.whl (140.0 kB view details)

Uploaded CPython 3.7m

feyn-1.1.0b3-cp36-cp36m-manylinux2014_x86_64.whl (135.1 kB view details)

Uploaded CPython 3.6m

feyn-1.1.0b3-cp36-cp36m-manylinux1_x86_64.whl (135.1 kB view details)

Uploaded CPython 3.6m

File details

Details for the file feyn-1.1.0b3-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

  • Download URL: feyn-1.1.0b3-cp38-cp38-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 138.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for feyn-1.1.0b3-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 794c58a9a53819ac6492d678a3e66b8ec96df4749ae13a730d3f3bc262540604
MD5 a2948bcc72aadf070b44ad9ea3fbeb0e
BLAKE2b-256 3c9618f5ecbcd24589eebc94f74c3a1bdd2f41ad03fd3b143eece9892ed2868f

See more details on using hashes here.

File details

Details for the file feyn-1.1.0b3-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: feyn-1.1.0b3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 138.5 kB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for feyn-1.1.0b3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 45ac08d185969267c77b8b0619008f2f0d321d811b478b2414d4b83c20ed6fba
MD5 b253ad277e5895213ef56766c57afc07
BLAKE2b-256 e65e3df36a75bab99ce630623f4f20526c83451c2b7aa9e95f27cf53f46da9ad

See more details on using hashes here.

File details

Details for the file feyn-1.1.0b3-cp37-cp37m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: feyn-1.1.0b3-cp37-cp37m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 140.0 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for feyn-1.1.0b3-cp37-cp37m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 768167eef4f1268dc508e8ff32d9d6a94e901e1c261f414b76a0fb53ff7a8147
MD5 e5499095bc0caa2ecb6fe7624f1f7ef6
BLAKE2b-256 ba1361fa4f8f4c027233fdbc5a0ff20f14a03f47c442d65b771ec46d46a84e9d

See more details on using hashes here.

File details

Details for the file feyn-1.1.0b3-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: feyn-1.1.0b3-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 140.0 kB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for feyn-1.1.0b3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2abea699d06cb0c5da8c88095dffa2ca631305811ce67a0b440d71933eb064e0
MD5 807aa184f942c39367a29853a6db0c91
BLAKE2b-256 8f715e90dbcfc94e9303b22e6ca39f5f5eb6102f51ca55648f2e4b04470ce9ce

See more details on using hashes here.

File details

Details for the file feyn-1.1.0b3-cp36-cp36m-manylinux2014_x86_64.whl.

File metadata

  • Download URL: feyn-1.1.0b3-cp36-cp36m-manylinux2014_x86_64.whl
  • Upload date:
  • Size: 135.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for feyn-1.1.0b3-cp36-cp36m-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b89ef08a98c3776b853e90fa0a3b79c061c449a2df62928c2c6482a427ca910b
MD5 de51d0ff7a3eb54defccfae58e0474be
BLAKE2b-256 e598045b359fa32293deb4a93601b680a6ecec5a83d9101fc4c5201c011bcf38

See more details on using hashes here.

File details

Details for the file feyn-1.1.0b3-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: feyn-1.1.0b3-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 135.1 kB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for feyn-1.1.0b3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 90fce420869f94d163c1d99e26e9939387db08a7ed50b573c9f4c4cd0cbc4863
MD5 cd8fa8f66bf41a435c7f0c0fd5e5433d
BLAKE2b-256 71659cb23742e379a3380efbf0f479d64f41179fcfa5099fadf946711bd7f023

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page