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 (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.
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.
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.
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.
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.
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.
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.
We put the parents and offsprings together and form a population for the next generation, which is how the Genetic Algorithm is done.
We use the moon shape data generated by Sklearn, the datapoints are scaled between [-1,1]. Please check demo.ipynb for more information.
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.
https://algodaily.com/lessons/introduction-to-genetic-algorithms-in-python
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