Skip to main content

A framework for quantum neural networks.

Project description

QNN-Gen: A Framework for Quantum Neural Networks

Beta Release

Install

Requirements:

  • qiskit
  • numpy

Install from PyPI with pip:

pip install QNN-Gen

Install an editable version with github (good if you want to change the source code):

git clone https://github.com/Farquhar13/QNN-Gen.git
cd QNN-Gen
pip install -e . 

Design

QNN-Gen is designed to serve as a useful abstraction for understanding and implementing Quantum Neural Networks (QNNs) or Parameterized Quatum Circuits. The structure of the code is classes is intended to mirror the theoretical structure of QNNs. The choices one has to make when constructing a QNN is reflected in QNN-Gen through the use of particular classes and their attributes.

Furthermore, QNN-Gen is designed to balance both ease-of-use and configurability.

High-Level Abstraction

We use a high-level abstraction of QNNs to break them down into three main steps:

  • Encoding input data
  • Choice of model architecture or ansatz
  • Measurement and post-processing

QNN-Gen matches this abstraction in code with the abstract base classes Encode, Model, and Measurement. Respectively, in the encode.py, model.py, and measurement.py files you can find these abstract base classes as well as several derived classes. To construct a QNN, you simply need to make your choices of modeling decisions and instantiate the corresponding derived classes.

Examples

We strive to make QNN-Gen as easy-to-use as possible. From the code snippet below you can see that it requires only 3 lines of code using QNN-Gen to create a simple QNN.

import qnn_gen as qg
import numpy as np

x = np.array([1, 0, 0, 1])

encoder = qg.BasisEncoding()
model = qg.TreeTensorNetwork()
full_circuit = qg.combine(x, encoder, model)

Which produces the circuit:

Note that the angels for the TreeTensorNetwork model are initialized randomly if they are not provided as an argument.

You may wonder what happened to the measurement object. First we note that in many cases the choice of a particular model implies which measurements and outputs are sensible. In the case that no Measurement object is passed to qg.combine, in the background QNN-Gen looks to the default_measurement function of the model. For the above example, the following code is equivalent.

import qnn_gen as qg
import numpy as np

x = np.array([1, 0, 0, 1])

encoder = qg.BasisEncoding()
model = qg.TreeTensorNetwork()
measurement = qg.Expectation(qubits=2)
full_circuit = qg.combine(x, encoder, model, measurement)

To run the QNN and get predicitions on a toy dataset you can use qg.run:

X = np.array([[1, 0, 0, 0],
              [0, 1, 0, 0],
              [0, 0, 1, 0],
              [0, 0, 0, 1],
              [1, 0, 0, 0]])

predictions = qg.run(X, encoder, model, measurement)

Which will produce a numpy array with 5-elements corresponding to the predictions for the 5 input data points. For this initatiations of the model parameters:

For more examples, checkout the examples/ folder. Inside, you will find python files and jupyter notebooks which demonstrate both the ease-of-use and configurability of QNN-Gen.

Contributing

QNN-Gen is designed modularly with abstract base classes. We welcome users to create their own class for a different encoding, model/ansatz, or measurement transformation and share them to be potentially added in to QNN-Gen.

Project details


Release history Release notifications | RSS feed

This version

0.0

Download files

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

Source Distribution

QNN-Gen-0.0.tar.gz (14.9 kB view details)

Uploaded Source

File details

Details for the file QNN-Gen-0.0.tar.gz.

File metadata

  • Download URL: QNN-Gen-0.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.4.2 requests/2.24.0 setuptools/50.0.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.6.5

File hashes

Hashes for QNN-Gen-0.0.tar.gz
Algorithm Hash digest
SHA256 298cc7aa22cf54c912bbdf362cab0384ccf357dbc45d26bbc5bc13a8710a65b7
MD5 3176aaf571f82cf40fc0c2f5de4205c1
BLAKE2b-256 94036ce49d7b35816abda090958d9dd6c9aeab558fa755ea3d98be33c8006233

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