This repository contains two parts:
- An implementation for computing the Lipschitz constant of a quantum decision model (See Algorithm 1 in the paper).
- Experiment codes and data for CAV2022 Artifact Evaluation (See Section 6 in the paper).
- Python3.8.
- Python libraries:
- Cirq for representing (noisy) quantum circuits.
- Tensornetwork for manipulating tensor networks.
- Numpy for linear algebra computations.
- Jax for just-in-time (JIT) compilation in Python.
- Tensorflow Quantum for training quantum decision models.
- dice-ml for DiCE adult income dataset.
We recommend the users to use Conda to configure the Python environment.
- Follow the instructions of Miniconda Installation to install Miniconda.
- Clone this repository and cd to it.
git clone https://github.com/Veri-Q/Fairness.git && cd Fairness
- Use Conda to create a new Conda environment:
conda create -n qfairness python=3.8.12
- Activate the above environment and use pip to install required libraries in
requirements.txt
.conda activate qfairness pip install -r requirements.txt
This repository provides a Dockerfile. The user can directly built a docker image from this Dockerfile and use it.
- Clone this repository and cd to it.
git clone https://github.com/Veri-Q/Fairness.git && cd Fairness
- Build docker image.
docker build -t qfairness .
- Run the built image.
docker run -t -i qfairness /bin/bash
🟥 For CAV2022 Artifact, we also provide a Docker image qfairness.tar
on Zenodo. The user can load this image and run it directly:
docker load -i qfairness.tar && docker run -i -t qfairness /bin/bash
The file qlipschitz.py
in this repository is the implementation of Algorithm 1 in the paper. It provides a function lipschitz
that accepts a quantum decision model and outputs the model's Lipschitz constant as defined in the paper. The usage of lipschitz
in Python is as follows:
from qlipschitz import lipschitz
# ...
k = lipschitz(model_circuit, qubits, measurement)
# model_circuit: the (noisy) quantum circuit descried by Cirq; It expresses the super-operator $\mathcal{E}$ in the quantum decision model.
# qubits: all (cirq) qubits used in the model; usually, qubits = model_circuit.all_qubits()
# measurement: a single qubit measurement (2x2 Hermitian matrix) on the last one of all qubits in the model; It expresses the measurement $M$ at the end of the model.
# ...
For example,
import cirq
import numpy as np
from qlipschitz import lipschitz
qubits = cirq.GridQubit.rect(1, 1)
model_circuit = cirq.Circuit(cirq.X(qubits[0])**0.5, cirq.depolarize(0.01)(qubits[0]))
measurement = np.array([[1., 0.], [0., 0.]])
k = lipschitz(model_circuit, qubits, measurement)
print('The Lipschitz constant is ', k)
🟥 Notice: Due to the inherent randomness in the training of quantum models, the results of repeated experiments may be numerically inconsistent.
We provide two scripts evaluate_finance_model_gc.py
and evaluate_finance_model_dice.py
to reproduce Table 1 in the paper. These two scripts will train a quantum decision model based on the given arguments (<noise_type>
and <noisy_probability>
) and compute the Lipschtiz constant of the trained model:
-
For German Credit in Table 1
python evaluate_finance_model_gc.py <noise_type> <noisy_probability>
-
For Adult Income (DiCE) in Table 1
python evaluate_finance_model_dice.py <noise_type> <noisy_probability>
where <noisy_probability>
is the probability of noise that can be valued at 0.0
, 0.01
, 0.001
and 0.0001
; <noise_type>
is the type of noise that has four options: phase_flip
for phase flip noise, depolarize
for depolarize noise, bit_flip
for bit flip noise and mixed
for mixed noise, which is the mixture of the three aforementioned noises.
For example, running python evaluate_finance_model_gc.py depolarize 0.0001
can reproduce the results of German Credit and Depolarize noise with probability 10^(-4) in Table 1.
🟥 Since TensorFlow Quantum is inefficient in training noisy models, we provide trained parameters for German Credit. The users can load the parameters and reproduce the part of German Credit in Table 1 by the script evaluate_trained_model_gc.py
.
For example, run command python evaluate_finance_model_gc.py depolarize 0.0001
can reproduce the Lipschitz constant and evaluate the time of German Credit and Depolarize noise with probability 10^(-4) in Table 1.
We provide a script evaluate_qcnn_model.py
to reproduce Table 2 in the paper.
python evaluate_qcnn_model.py <qubits_num> <noise_type>
where <qubits_num>
is the number of qubits (integer), and again, <noise_type>
is the type of noise that has four options: phase_flip
for phase flip noise, depolarize
for depolarize noise, bit_flip
for bit flip noise and mixed
for the mixed one.
For example, running command python evaluate_qcnn_model.py 25 depolarize
can reproduce the results of 25 Qubits and Depolarize noise in Table 2.
🟥 The server used in our experiments has 2048GB of memory. For the users who do not have a server with the same memory, you can test on a smaller number (10-15) of qubits.