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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for quantumlime-1.9.0-py3-none-any.whl
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 | c0597a2348dea875a858411809458e56156fdda234dca3c22a89db4e207f6ca3 |
|
| MD5 | 8deb3e83c71a2261c39ad771a5841403 |
|
| BLAKE2b-256 | 12049e6e188e8a934b103643f00e3ac4dc3f67bb4e690bf4944066178d9d8a97 |