Skip to main content

QLIME (Quantum Local Interpretable Model-agnostic Explanations) is a Python library for interpreting quantum neural networks using local surrogate models.

Project description

Description

This library is intended for defining regions of non-interpretability for quantum learning models. The current versions is limited in scope as it extends a specific example introdcued in the research paper: https://arxiv.org/abs/2308.11098

User guide

You can find below a sample client python script calling quantumlime.

from sklearn.model_selection import train_test_split
from sklearn.datasets import load_iris
import numpy as np
import quantumlime

# Load the Iris dataset
iris = load_iris()
# Normalize the data by subtracting the minimum value and dividing by the maximum value
iris.data = (iris.data - iris.data.min()) / iris.data.max()

# Use the first two classes of the Iris dataset only (100 of 150 data points)
X_train, X_test, Y_train, Y_test = train_test_split(
    iris.data[0:100, [0, 1]],
    iris.target[0:100],
    test_size=0.75,
    random_state=0)

a = 2.5
c = 0.25
maxiter = 1e3
shots = int(1e4)
alpha = 0.602
gamma = 0.101

f = lambda x: quantumlime.objective(x,X_train,Y_train,shots=shots) # Objective function
x0 = np.pi*np.random.randn(4)

xsol = quantumlime.spsa(f, x0, a=a, c=c,
            alpha=alpha, gamma=gamma,
            maxiter=maxiter, verbose=True)

# Explain the local behavior of the model
quantumlime.region_of_indecision(1,X_train,xsol, lambda x : quantumlime.qnn(x,xsol))
# Explain the local behavior of the model at a local region of value
quantumlime.region_of_indecision(2,X_train,xsol, lambda x : quantumlime.qnn(x,xsol), local_region = 0.05)

Administration Guide

Bump version

Bumping a version requires bumpver. If bumpver is not installed yet use

pip install bumpver

Bump Z in X.Y.Z

bumpver update --patch

Bump Y in X.Y.Z

bumpver update --minor

Bump X in X.Y.Z

bumpver update --major

Publish to the TEST Pypi repository

Once the version number has been properly bumped use (note your credentials must be properly setup into your $HOME/.pypirc file:

rm -rf dist/
python -m build
twine upload -r testpypi dist/*

Publish to the PROD Pypi repository

Once the version number has been properly bumped use (note your credentials must be properly setup into your $HOME/.pypirc file:

rm -rf dist/
python -m build
twine upload -r pypi dist/*

Project details


Download files

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

Source Distribution

quantumlime-1.9.0.tar.gz (9.8 kB view hashes)

Uploaded Source

Built Distribution

quantumlime-1.9.0-py3-none-any.whl (12.9 kB view hashes)

Uploaded Python 3

Supported by

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