Skip to content

doggydoggy0101/Genetic_quantum_feature_map

Repository files navigation

Effects of fitness function in genetically auto-generated quantum feature maps

This is an unofficial implement for the paper: Automatic design of quantum feature maps. In addition, it also verify and support the implementations in our new manuscript: Effects of fitness function in genetically auto-generated quantum feature maps. We have figured out some new functions including the adjustment on the multi-fitness function and introduced penalty weight with experiments on different data. We have also done some more investigation on optimizing circuits while remaining high accuracy.

Genetic Algorithm

Genetic Algorithm (GA) is a nature-inspired algorithm that has extensively been used to solve optimization problems. It does not guarantee to always find the exact optimal solution; however, it may find a near-optimal solution in a limited time.

GA is an evolutionary algorithm and is inspired by the process of natural selection.

Chromosome

A chromosome/DNA is a candidate/potential solution to the problem being solved. We define gates per five bits from binary strings to generate quantum circuits as shown in the figure below.

Population

A set of solutions participating in the process of optimization is called population. We use the number of CPUs in order to effeiciently multi-process in our example.

Fitness

This is also consider as objective function or cost function. We pass a solution to this function and this function returns the fitness of that solution. We aim to both maximize the accuracy and minimize the ansatz size, we define multi-objective fitness function as shown in the figure below.

Matting pool

The matting pool chooses the parents for the next generation. The simplest method is to first determine the pool size and then choose the best chromosomes based on the pool size.

Crossover operation

This is the reproduction phase which mimics the sexual reproduction mechanism of natural selection. The genetic information of two individuals called parents selected through matting selection is exchanged to produce new individuals called offspring. We randomly chooses two chromosome from the matting pool as parents for each offspring.

Mutation operation

This operator also mimics the biological mutation operator. Although, children inherit 99% of characteristics from their parent but mutation allows to introduce new traits in the genetic information of an individual. We set a probability at 66.6% to randomize a chromosome and simply do a bit flip.

Generation

We put the parents and offsprings together and form a population for the next generation, which is how the Genetic Algorithm is done.

Results

Toy data

We use the moon shape data generated by Sklearn, the datapoints are scaled between [-1,1]. Please check demo.ipynb for more information.

Fitness, gate size, accuracy:

Comparing kernels

The circuit can be optimized if the gates share the same rotation axis and parameter, and can be combined to a single rotation gate with addition angles. We compare the quantum kernel result with linear kernel and Gaussian kernel, and has perfect accuracy with simple uncorrelated circuit.

Reference

S. Altares-L´opez, A. Ribeiro, J.J. Garc´ıa-Ripoll, Automatic design of quantum feature maps, Quantum Science and Technology, vol. 6, no. 4, 2021.

https://algodaily.com/lessons/introduction-to-genetic-algorithms-in-python

Note

For some reason multiprocessing does not always work with objects not defined in an imported module. Install multiprocess and replace multiprocessing with multiprocess in your imports if you get stuck using multiprocessing.

https://stackoverflow.com/questions/41385708/multiprocessing-example-giving-attributeerror

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published