Code Monkey home page Code Monkey logo

robustness's Introduction

VeriQRobust

Python Toolbox for Robustness Verification of Quantum Classifiers

This toolbox is implemented on Python and can verify the robustness of quantum machine learning algorithms with respect to a small disturbance of noises, derived from the surrounding environment.

Requirements


This toolbox makes use of Numpy and an SDP solver โ€” CVXPY: Python Software for Disciplined Convex Programming.

Installation


VeriQ can be installed on Unix and Linux. The following installation instruction is based on Ubuntu 18.04.
  1. The installation of VeriQ requires BLAS and LAPACK. Cmake and pip3 are also needed.
sudo apt install -y libblas-dev liblapack-dev cmake python3-pip
  1. Because the default version of Python in Ubuntu 18.04 is Python3.6, Numpy should be installed first.
pip3 install numpy
  1. Install CVXPY.
pip3 install cvxpy
  1. Besides, our demonstration file batch_check.py uses a Python library PrettyTable for printing a format table summarizing the numerical results, and matplotlib is also needed to be installed for generating visualized adversary examples for the classification of MNIST.
pip3 install prettytable matplotlib
  1. Clone or download the VeriQ toolbox from VeriQ. All files must be saved in the same location.
git clone https://github.com/j68249959/VeriQ

Running Tests and Examples


To implement robustness verification on VeriQ, we assume that the user has already trained a quantum classifier which consists of a quantum circuit with a measurement at the end. The quantum circuit and the training data have been saved as a NumPy data file.

Robustness Verification

The user can use the following script to run VeriQ for robustness verification of quantum classifiers.

python3 batch_check.py <data_file> <robustness_unit> <experiment_number> <state_flag>

There are four arguments are inputted by users. The first one <data_file> is a NumPy data file that consists of a (well-trained) quantum classifier and corresponding training dataset. The NumPy data file can be directly obtained by the data of the classifiers trained on the platform --- Tensorflow Quantum of Google. The second argument <robustness_unit> is the unit of the robustness verification parameter. The third argument <experiment_number> represents the number of robustness verification with increasing robustness verification parameters by unit <robustness_unit>. For example, if <robustness_unit> and <experiment_number> are 1e-3 and 4, respectively, then 1e-3, 2e-3,3e-3, 4e-3-robustness of the quantum classifier to be checked one by one. The last one <state_flag> indicates the considering quantum data in robustness verification, where the value of <state_flag> is mixed or pure referring to mixed states and pure states, respectively.

For simplicity, the user can try the following commands in bash for robustness verification of four quantum classifiers.

  1. Quantum Bits Classifications
python3 batch_check.py binary_cav.npz 1e-3 4 mixed
  1. Quantum Phase Recognition
python3 batch_check.py phase_recog_cav.npz 1e-4 4 mixed
  1. Cluster Excitation Detection
python3 batch_check.py excitation_cav.npz 1e-4 4 mixed
  1. The Classification of MNIST
python3 batch_check.py mnist_cav.npz 1e-4 4 pure

Adversarial Examples Generation

The user can use the following script to obtain the adversarial examples of MNIST classification, which are found by VeriQ. The results are generated into .png files.

python3 generate_adversary.py

The models of the above classifiers can be found in the Figures file.

Experimental Results


After running tests, you will get the following results (also see in the Experimental_Results file). It is worth noting that the verification time is depending on the performance of your computer devices.
  1. Quantum Bits Classifications avatar
  2. Quantum Phase Recognition avatar
  3. Cluster Excitation Detection avatar
  4. The Classification of MNIST avatar
  5. Adversarial Examples

avatar

avatar

robustness's People

Contributors

j68249959 avatar njuwfang avatar veri-q avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.