3.2.2. Quantum Chromosome Encoding
In traditional evolutionary algorithms (e.g., genetic algorithms), chromosome encoding typically adopts binary encoding, real number encoding, or symbolic encoding, which directly maps input data to the variable values in the solution space of the problem. For instance, binary encoding represents a chromosome as a string composed of zeros and ones and defines the characteristics of an individual through the position and value of the genes. Although this encoding method is simple and easy to implement, it has a few limitations. First, the expressive power of traditional encoding is restricted by the encoding length, where longer encodings increase the computational complexity, whereas shorter encodings can yield insufficient solution accuracy. Second, a fixed representation of chromosomes makes them prone to fall into a local optimum when handling complex problems, and due to the limited expressive power, it is challenging to explore the solution space of multimodal problems efficiently. By contrast, the quantum chromosome encoding method uses the superposition state of qubits and quantum gate operations to represent the solution space. Quantum chromosomes describe an individual’s state using the probability amplitudes of qubits and can simultaneously represent multiple possible solutions. This ability to use parallel representation significantly enhances the search scope. In this study, a quantum chromosome is encoded using 40 qubits, and the qubits on a chromosome can be referred to as genes. Each qubit on a quantum chromosome is not fixed at zero or one but is in an uncertain state. A quantum chromosome can be defined as follows:
where
n represents both the length of a quantum chromosome and the number of qubits;
, where
and
represent the probability amplitudes of the
ith qubit being zero and one, respectively.
Therefore, a quantum chromosome can also be expressed by
Since a qubit has a state of both zero and one simultaneously before it collapses into a definite state upon observation, it is necessary to analyze the quantum population to obtain definite quantum individuals. The quantum population initialization and observation algorithm is presented in Algorithm 1.
In this study, it is assumed that each individual in the quantum population has 40 genes, which is equivalent to 40 qubits, so there are a total of
possibilities. Furthermore, since two qubits can be regarded as a whole, 40 qubits denote 20 qubit pairs. Considering that two qubits can represent the four states of
,
,
, and
, for the above-mentioned combinations, four different decoding methods are designed in the quantum circuit, as shown in
Table 1.
Algorithm 1 Quantum population initialization and observation. |
- Input:
The size of quantum population N, the length of a quantum chromosome L, empty quantum population; - Output:
observed quantum population ;
- 1:
for q in do - 2:
- 3:
- 4:
while do - 5:
- 6:
- 7:
- 8:
if then - 9:
- 10:
else - 11:
- 12:
end if - 13:
- 14:
end while - 15:
end for - 16:
return
|
The final quantum state of each qubit pair denotes the selected quantum gate. For instance, if the first and second gene positions are observed to be both zeros, then an gate will be placed at the first qubit and the auxiliary qubit position when creating a quantum circuit; if the two positions are zero and one, then a gate will be placed, and so on. The second and third gene positions correspond to placing an appropriate gate at the second qubit and the auxiliary qubit position in the circuit. This process continues until all the gene positions of a quantum chromosome are defined, which indicates that the quantum circuit architecture is decided. It can be seen that there are at most 20 quantum gates in the quantum circuit, which might also include non-parameter and identity gates. In this study, the quantum gates in the encoding layer are neglected, and only the number of trainable gates is considered.
The fitness value represents an indicator that measures an individual’s ability to adapt to a specific environment, and the fitness evaluation process is a standard method for assessing an individual’s overall quality. The level of an individual’s fitness directly defines their superiority or inferiority. However, to determine the superiority or inferiority of an individual, two key calculation steps should be conducted: (1) calculate the objective function value, which denotes the result of the individual after the encoding process; (2) construct a suitable fitness function based on the objective function values according to the specific rules to determine the fitness score of the individual. The fitness value not only reflects an individual’s performance in a given task but also plays a role in the screening and optimization tasks throughout the evolutionary process. In this study, the image classification task is considered, so the accuracy of a model on the test dataset is used as a direct indicator in the fitness evaluation of individuals. In each iteration of the evolutionary algorithm, each individual (i.e., a circuit) is trained and applied to the test dataset. The performance of each individual on the test dataset is recorded as a fitness score. Based on the obtained fitness score values, a selection operation is performed, prioritizing the retention of individuals with high accuracy while eliminating individuals with poor performance. This process guides the population toward a better solution. As the evolutionary algorithm iterates, individuals with low fitness values are eliminated, so the overall fitness score of the population gradually improves with time. The pseudo-code of the fitness evaluation algorithm for a quantum population is presented in Algorithm 2.
Algorithm 2 Fitness evaluation of quantum population. |
- Input:
A quantum population by observed Q, the number of training epochs N; - Output:
A fitness value of a quantum population
- 1:
for q in Q do - 2:
- 3:
Embed classical data to the quantum state by the encoding layer - 4:
Decode q to a circuit architecture with parameters defined by - 5:
while do - 6:
Initialize parameters of quantum gates in the quantum circuit - 7:
Train the parameterized quantum circuit using the Adam optimizer - 8:
Calculate the loss and updating parameters - 9:
Evaluate the model performance and calculate accuracy - 10:
- 11:
end while - 12:
Preserve maximum and convert to fitness - 13:
end for - 14:
return
|
In Algorithm 2, before the loss value is calculated, the expected value obtained by the measurement process of the Pauli
Z basis described before is not directly used in the loss calculation process. The expected value obtained by the measurement ranges from −1 to 1, whereas the label values of the dataset are all positive, but they are converted to zeros and ones before being input into the quantum circuit. Therefore, the expected value of the measurement needs to be transformed into a probability distribution using the sigmoid function. In this study, the binary cross-entropy loss function is selected; this function measures the difference between the predicted probability distribution of a model and the true labels, and it is suitable for binary classification problems where the output is either zero or one. The binary cross-entropy loss function is expressed as follows:
where
y represents the true label of data (0 or 1), and
is the predicted probability of the model for these data; when
, the loss is mainly determined by the first term in the above-mentioned equation, that is,
, and the loss gradually decreases; otherwise, the loss gradually increases.
3.2.3. Quantum Population Updating
In evolutionary algorithms, population update is a fundamental step to complete the algorithm iteration and optimization process. The population update process mainly includes three basic operations: selection, crossover, and mutation. First, the selection operation screens individuals based on their fitness values, where individuals with higher fitness have a higher possibility of being selected for the next generation. Common selection methods include the roulette wheel selection method and the tournament selection method, which ensure that genetic information on superior individuals is retained and passed on using different strategies. Then, the crossover operation exchanges gene segments between the selected individuals. Through the crossover operation, the superior genes of individuals are combined to generate new individuals, which helps to explore the solution space and increase the population’s diversity. The implementation methods of crossover are diverse, including the single-point crossover method, the multi-point crossover method, and the uniform crossover method. Finally, the mutation operation randomly alters the genes of the individuals. The mutation operation is a random perturbation in the population’s update, which can break the local optimal state of the population and, thus, prevent the algorithm from converging prematurely.
During the update process of the quantum evolutionary algorithm, the population adjustment is mainly achieved through the unique quantum rotation gate adjustment using quantum theory. The proposed AQEA employs two adaptive quantum rotation gate angle strategies for rotation update and introduces a quantum
X gate to achieve the quantum population’s mutation; in addition, the quantum catastrophe idea is adopted to assist the algorithm in escaping from a local optimum with a certain probability after getting trapped in it [
52,
53] and to continue to search the global solution.
In the quantum evolutionary algorithm, quantum transformation matrices are used to achieve changes between the quantum superposition states and entangled states. The generation result of offspring individuals is not defined by the genes of the parent generation but by the probability amplitude of their states. The quantum rotation gate is mainly used to perform the generation process, and the rotation angle of the quantum rotation gate is used to calculate the probability of the chromosome mutation operation as follows:
where
is the rotation angle and can typically be determined from
Table 2.
In
Table 2,
represents the
ith gene position of the chromosome to be updated;
is the
ith gene position of the best chromosome in the current generation;
and
are the fitness values of the chromosome to be updated and the best chromosome in the current generation, respectively;
indicates the rotation direction of the quantum rotation gate, which ensures that the chromosome to be updated rotates toward the direction of the best individual.
The proposed method adjusts the quantum bit amplitudes
and
at the corresponding positions by comparing the fitness value of the chromosome to be updated with that of the best individual in the current generation each time. The updated probability amplitudes are denoted by
and
, and the entire process can be expressed as follows:
Each qubit of each individual in the population satisfies the normalization condition, so the above-mentioned formula can also be rewritten as follows:
According to the above-mentioned expression, the quantum chromosome after rotation update still satisfies the normalization condition. Moreover, the sign and magnitude of the rotation angle have a significant impact, playing a crucial role. Namely, if the rotation angle is too small, that is, the adjustment amplitude is too small, the search range can be reduced, which may result in slow convergence of the algorithm; by contrast, if the rotation angle is too large, then the adjustment amplitude is also too large, and the search range will be expanded, which may cause the algorithm to experience premature convergence and miss the optimal solution.
Considering that the quantum chromosome length in this paper is 40, which represents possible solutions, searching for the optimal solution in such a complex search space is challenging. Therefore, this paper employs the proposed AQEA method to divide the genes in the quantum chromosome into two parts, and applies two dynamic rotation angle strategies to the probability amplitudes of qubits in the first and second halves of the genes.
For the first half of the genes, the rotation angle is calculated by
where
n represents the current generation of the evolution process,
is the maximum number of evolution generations, and
.
According to the above-mentioned formula, the rotation angle is related to the number of evolution generations. As the number of evolution generations increases, the rotation angle decreases, and the search space reduces, eventually reaching the convergence state.
For the latter half of the genes, the rotation strategy is defined as follows:
where
,
;
represents the fitness value of the individual to be updated;
is the fitness value of the best individual in the current generation;
is a natural number.
When the difference between the and values is very small and the value is large, the value of will be much less than , and the overall rotation angle will be less than . This will significantly reduce the search range, making the algorithm prone to falling into a local optimum and being unable to escape from that state. However, by introducing , which is a fixed value and can be dynamically adjusted during the evolutionary process, and by setting its value appropriately, it can be ensured that the rotation angle is not too small even when the value is close to the value. This can maintain an exploration ability and effectively alleviate the problem of a narrow search range caused by a small rotation angle, thus improving the overall performance of the algorithm. Based on all the aforementioned, the quantum population updating algorithm is developed, and its pseudo-code is given in Algorithm 3.
In Algorithm 3, the update rule based on the two rotation strategies is improved. Namely, when the individual to be updated is not the optimal individual, but some of its genes are the same as those of the best individual at the corresponding positions, then the probability amplitude of the corresponding individual in the previous generation can be directly continued, and there is no need to perform rotation updates. Only the gene positions with different states from those of the best individual need to be used for optimization. This not only simplifies the judgment logic but also reduces the implementation complexity of the algorithm. In addition, since the quantum rotation strategy targets only half of the genes at each iteration, the other half of the genes directly copy the state of the previous generation.
Algorithm 3 Quantum population updating. |
- Input:
An evaluated quantum population Q, a size of quantum population N, the length of a quantum chromosome L, the probability of mutation , a catastrophic factor , the population fitness value F, the maximum generation T - Output:
updated quantum population
- 1:
Rank population individuals according to their fitness values - 2:
Record the fitness value of the best individual - 3:
if count of then - 4:
for do - 5:
if then - 6:
if then - 7:
Update the population using the first quantum rotation strategy - 8:
end if - 9:
else - 10:
Initialize the probability P randomly in the range of and mutate - 11:
end if - 12:
end for - 13:
Obtain quantum subpopulation - 14:
for do - 15:
if then - 16:
if then - 17:
Update the population using the second quantum rotation strategy - 18:
end if - 19:
else - 20:
Initialize the probability P randomly in the range of and mutate - 21:
end if - 22:
end for - 23:
Obtain quantum subpopulation - 24:
Merge quantum subpopulation and to update - 25:
else - 26:
Retain the best individual and reinitialize the other individuals - 27:
end if - 28:
Return updated quantum population
|