Keywords: Quantum Machine Learning; Generative Adversarial Networks; Evolutionary Algorithm; Ansatz Search; Hybrid Quantum-Classical System; Quantum GAN.
This repository contains the code for the EWGAN-GP model, developed as part of the thesis project Evolutionary Optimization for Hybrid Quantum Image Generation GAN, submitted in partial fulfillment of the requirements for the degree of Master of Science of Data Science for Decision Making at the Department of Advanced Computing Sciences of Maastricht University.
Click here to read the complete thesis.
This work investigates the effectiveness of a quantum mutation-based evolutionary search strategy for identifying better-performing ansatze, evaluated based on image quality and the number of required parameters. The ansatze are used as generators in a hybrid quantum-classical GAN for generating 28 × 28 grayscale MNIST images of digits 0 and 1. The results highlight the feasibility of using architectures that differ from the standard, hardware-efficient ansatz to generate images of comparable quality to the current state-of-the-art, and the evolutionary algorithm’s potential in discovering superior configurations.
Below a plot of original data and generated images with various models:
a) Original 0 and 1 digit images from the MNIST datasets.
b) Images generated with a fully classical model.
c) Images generated with the EWGAN-GP (the model in this repository).
d) Images generated with State of the Art PQWGAN model.
![]() a) |
![]() b) |
![]() c) |
![]() d) |
numpy==1.23.5pandas==2.2.2matplotlib==3.8.4scipy==1.13.0tensorflow==2.16.1torch==2.2.2seaborn==0.13.2It is recommended to use a virtual environment for managing dependencies. To set up and activate a virtual environment:
python -m venv ewgan_venv
source ewgan_venv/bin/activate # On Windows use `ewgan_venv\Scripts\activate`
To install the required libraries, run:
pip install -r requirements.txt
The code assumes the following:
Note: This choice is based on findings from the PQWGAN paper, where horizontal patches were observed to work well for the GAN.
To run the pipeline with default values, simply change the directory to this project’s and run the command:
python main.py
This will automatically do the following:
\input folder.\output folder.Refer to the thesis document for detailed information on the functioning of the algorithm.
The main source for how to structure a GAN and WGAN, including architecture structuring, and gradient penalty function, was taken from Erik Linder-Norén’s GitHub repo of PyTorch implementations of Generative Adversarial Networks: PyTorch-GAN, licensed under MIT license.
This work is based on the Patch Quantum Wasserstein GAN (PQWGAN), introduced by Tsang et al. in the paper Hybrid quantum-classical generative adversarial network for high resolution image generation, available here.
This work builds on the PQWGAN work, by introducing an evolutionary algorithm for ansatz search, aimed at identifying ansatz architectures tailored to a specific application, in this case generation of digits images, therefore taking a step further from the more commonly employed application-agnostic hardware-efficient ansatz. My thanks go to Vincenzo Lipardi for the valuable ideas, brainstorming sessions, and support during the development and testing of this algorithm, and to Menica Dibenedetto for her guidance, insights, and ongoing encouragement.