qc-str
None
view repo
Machine learning (ML) classification tasks can be carried out on a quantum computer (QC) using Probabilistic Quantum Memory (PQM) and its extension, Parameteric PQM (P-PQM) by calculating the Hamming distance between an input pattern and a database of r patterns containing z features with a distinct attributes. For accurate computations, the feature must be encoded using one-hot encoding, which is memory-intensive for multi-attribute datasets with a>2. We can easily represent multi-attribute data more compactly on a classical computer by replacing one-hot encoding with label encoding. However, replacing these encoding schemes on a QC is not straightforward as PQM and P-PQM operate at the quantum bit level. We present an enhanced P-PQM, called EP-PQM, that allows label encoding of data stored in a PQM data structure and reduces the circuit depth of the data storage and retrieval procedures. We show implementations for an ideal QC and a noisy intermediate-scale quantum (NISQ) device. Our complexity analysis shows that the EP-PQM approach requires O(z log_2(a)) qubits as opposed to O(za) qubits for P-PQM. EP-PQM also requires fewer gates, reducing gate count from O(rza) to O(rzlog_2(a)). For five datasets, we demonstrate that training an ML classification model using EP-PQM requires 48 a>2. EP-PQM reduces circuit depth in the range of 60 the dataset. The depth decreases further with a decomposed circuit, ranging between 94 EP-PQM requires less space; thus, it can train on and classify larger datasets than previous PQM implementations on NISQ devices. Furthermore, reducing the number of gates speeds up the classification and reduces the noise associated with deep quantum circuits. Thus, EP-PQM brings us closer to scalable ML on a NISQ device.
READ FULL TEXT VIEW PDFNone
Nowadays, classical algorithms play an important role in finding information in data [zhou2017machine]. However, due to the large amount of data that we have today, some problems require a lot of resources to be solved [zhou2017machine]. Recently, quantum computing emerged as the most promising candidate for solving problems with large data. Quantum computers (QCs) use quantum mechanical properties, such as superposition and entanglement, to perform computations. Machine learning (ML) is a promising field where QCs, specifically near-term intermediate scale (NISQ) devices, can have potential applications. The purpose of quantum ML is to build quantum-enhanced ML models [schuld2015introduction, biamonte2017quantum]. These algorithms have proved to be faster than classical algorithms for a variety of tasks, including supervised and unsupervised ML [russell2016artificial, yom2004advanced, liu2021rigorous]
[4579244], and support vector machine
[rebentrost2014quantum]. For review on quantum ML, see Refs. [mishra2021quantum, li2021introduction].In this paper, we propose an enhancement to a quantum ML model that belongs to the quantum associative memory family of models [ventura2000quantum, pqmct, trugenbergercarlofull, sousa2020parametric]. Specifically, we focus on Probabilistic Quantum Memory (PQM) [pqmct, trugenbergercarlofull], which computes the Hamming distance, deemed , between an -bit input pattern and a database of patterns of length .
PQM has strong characteristics, such as storing and simultaneously analyzing patterns while using only qubits.
Alas, PQM also has some flaws. For example, suppose we have multiple input patterns to compare to the database of patterns. The comparison is made one input string at a time. This means that we need to reload the database into a QC after every comparison because measuring collapses the state of the QC [brun2003comment, schuld2014quantum]. Since the reloading cost is , it may outweigh the benefits of PQM, making it more efficient to compute on a classical computer. In addition, PQM is not a complete model [dunjko2018machine]
. Nonetheless, it may be useful for specialized tasks; e.g., one PQM execution may be sufficient for evaluating the artificial neural network architectures probabilistically without having to initialize the weights
[dos2018quantum].PQM can also be used for pattern classification task [dossantos2019wnn, sousa2020parametric]
. This is done by computing the probability that an input pattern belongs to a given database of patterns. However, the current approach for codifying patterns as binary strings may be inefficient. Let us look at two examples.
Suppose that each of the pattern’s features have only two attributes. In this case, we can efficiently codify the value of a feature using a single bit per feature.
What if we have more than two attributes? Let us use to represent the number of distinct attributes. To codify attributes, we can either use one-hot encoding or label encoding. In one-hot encoding, a single feature is represented by binary variables, while label encoding maps the attributes to integers. Therefore, one-hot encoding requires bits to represent a feature, while label encoding only needs bits, where denotes ceiling function. Thus, label encoding is more efficient than one-hot encoding. This difference is significant as real-world dataset (e.g. NSL-KDD [tavallaee2009kdd]) may contain hundreds of distinct attributes. For example, one-hot encoding requires 100 bits for a feature with 100 distinct attributes, whereas label encoding requires only 7 bits. This exponential decrease in the number of qubits and gates may make NISQ devices capable of processing complex multi-attribute patterns.
Consider patterns containing three features: an input pattern “A A A” and a database with two patterns = “B B B” and = “C C A”. We would like to compute the distance between and two patterns in the database. It is obvious that and .
Let us now demonstrate how the above example is implemented using PQM. As PQM operates at the bit level, the patterns must be converted to bit strings. We will use the label encoding to represent the three attributes, which requires two bits per attribute. Suppose that “A” is codified as “00”, “B” as “01”, and “C” as “11”. This encoding converts the patterns to the following bit strings: “00 00 00”, = “01 01 01”, and = “11 11 00”. PQM operates on individual bits, thus and .
As we can see, , but . Consequently, label encoding, while efficiently utilizing memory, may lead to erroneous results.
To overcome this problem, we must resort to one-hot encoding, in which attributes are codified as follows: “A” as “100”, “B” as “010”, and “C” as “001”. The patterns will now be represented by “100 100 100”, = “010 010 010”, and = “001 001 100”. PQM will yield and . Note that (see Appendix A for details); thus, one-hot encoding yields the desired values of .
Therefore, one-hot encoding allows PQM to compute correctly, whereas label encoding does not. However, one-hot encoding consumes more space: nine qubits will be required instead of six.
Based on the above examples, to compute correctly, it appears that PQM can only use one-hot encoding for features with multiple attributes. Consequently, the pattern must be represented using a large amount of space. Modern QCs, however, have a small number of qubits and limited coherence. Therefore, we need to find a way to use label encoding to reduce space constraints and utilize qubits more efficiently.
In this paper, our contribution is as follows. We generalize the PQM algorithm to compute the Hamming distance for features codified with label encoding. Specifically, we improve the parametric PQM (P-PQM) classification algorithm designed for modern noisy intermediate-scale quantum (NISQ) computers [sousa2020parametric] to use fewer qubits and quantum gates. This efficient version of P-PQM, which we call EP-PQM, results in
Space savings, as for features the number of required qubits reduces from to for ;
Improved computational efficiency, as the amount of quantum gates needed to execute the PQM algorithm is proportional to the number of bits required to represent a pattern. The number of gates reduces from to .
With EP-PQM requiring fewer qubits and gates to implement PQM than P-PQM, it becomes a better candidate for applications in NISQ devices.
In this section, we review the PQM and P-PQM algorithms. The PQM [pqmct, trugenbergercarlofull] algorithm introduces a data structure that allows computing the distance at the bit level between a binary input pattern and all other binary patterns stored in a superposition state. PQM has two parts: storing information and retrieving information, discussed in Sections 2.1 and 2.2, respectively. The core quantum computing fundamentals needed to implement these algorithms are introduced in Appendix B.
To store information, PQM will take a dataset of binary patterns, each of bits and store them in a superposition state with equal probability. Given an input, to retrieve information, the memory quantum state is rotated within the subspace defined by the stored patterns. The resulting amplitudes are peaked on the stored patterns which are closest in Hamming distance to the input.
P-PQM is similar in nature to PQM, but adds an extra parameter that may improve ML classification.
This section recaps the existing PQM and P-PQM data storage processes, leveraging the same algorithm.
Formally, the storing information part of the algorithm receives a dataset of binary patterns, each containing bits: . To store the patterns, three quantum registers are needed: the input register , the memory register , and the auxiliary two-qubit register . The input register state will hold every pattern of length . is the memory register which will store each pattern by the end of the algorithm. The auxiliary two-qubit register state is used to keep tabs on which patterns are stored in memory and which ones need to be processed. All three quantum registers are initialized in the state and the algorithm initial state is
(1) |
The storage process loads each pattern (represented as a binary string) into and then stores them in in a superposition with equal probabilities. Once the patterns are loaded into
, they will be processed to find the closest pattern match as we will discuss in Section
2.2.The storage process is given in Algorithm 1, see Ref. [sousa2020parametric] for an in-depth explanation of the storing algorithm. This algorithm uses common quantum computing gates recapped in Appendix B. In addition to these gates, Step 7 of the algorithm uses a two-qubit control gate , which adds a pattern to memory register with uniform amplitudes. It is defined as follows:
where and …, and
Thus,
The final result of the algorithm is the state
(2) |
Note that in the retrieval phase, we are only concerned with the memory-register state .
PQM and P-PQM retrieval processes — described in Sections 2.2.1 and 2.2.2, respectively — are similar. PQM retrieval algorithm has only implementation for fault-tolerant QCs, while P-PQM also has an implementation designed for NISQ devices [sousa2020parametric].
The algorithm for retrieving information relies on the memory register in state (i.e., the output of the storage algorithm). This state is then further manipulated to perform pattern analysis as described below.
PQM uses the Hamming distance between a target pattern and all patterns, which are stored in a superposition, to indicate probabilistically the chances of the target pattern being in the memory. This algorithm uses three quantum registers, namely , , and :
(3) |
The target pattern, deemed and represented by bits , is loaded into register state ; contains all the stored patterns from the storage algorithm; and contains a control qubit initialized in state . Once the input has been loaded on to and the stored patterns are in , the full initial quantum state is
(4) |
where is the total number of stored patterns, are qubits used to store corresponding bits of the target pattern , and is the -th stored pattern.
The retrieval process is summarized in Algorithm 2. In Step 1, we apply the Hadamard gate on to the control qubit to get
(5) |
Step 2 sets the -th qubit in register to if the -th qubit of and are the same or to if they differ.
Step 3 computes between the target pattern and all patterns in . The number of zeros in (representing the qubits that differ between memory and target string) is computed. Operator , used in this step, is defined as
(6) |
where denotes unit imaginary number. First, is applied to each qubit in . Then (which is to the power of ) is applied to each qubit in if the qubit is in state . This control operator is denoted by . As per [pqmct], is formally defined as
Step 4 reverts register to its original state and the Hadamard gate h is applied to the control qubit in ; this operation is denoted by .
Step 5 measures register . A target pattern similar to the stored patterns increases the probability of measuring . Otherwise, if the target pattern is dissimilar, then the probability of increases. If is measured and the output is (Step 6), then measuring the qubits in the memory register (in Step 7) will return the binary pattern from the set of stored patterns that produced the minimum with the target pattern in a given run of the algorithm.
In a nutshell, P-PQM operates as the PQM, but with the addition of a scale parameter in the retrieval algorithm. The parameter is used to compute weighted , which may improve performance of the classifier [sousa2020parametric].
To integrate into the retrieval algorithm, Eq. (6) is redefined as
(7) |
Note that the quantum circuit depth and complexity are independent of , and that P-PQM reduces to PQM when . Let us give a brief summary of both fault-tolerant and NISQ implementations (see [sousa2020parametric] for additional details).
The NISQ implementation of the P-PQM retrieval algorithms is shown in Algorithm 3. This implementation requires only two registers, namely, and :
(8) |
and the input is stored classically. Once the stored patterns from the storing part of the algorithm are in , the full initial quantum state is:
(9) |
Because the input is stored classically, all the control operators from the input register to the memory register are removed from the circuit and replaced with a x operator. Essentially, the input pattern is processed dynamically without the need for a dedicated register. In the NISQ implementation [sousa2020parametric], Steps 2 and 4 of the fault-tolerant implementation (Algorithm 2) are modified. Specifically, they are replaced by Steps 2–4 and 6–8 of Algorithm 3. In this NISQ implementation, rather than applying x based on cnot to each qubit, we examine each bit in on the classical computer and apply x only if . This leads to “inversion” of logic; thus, we are now interested in measuring when rather than when (compare Steps 6–7 of Algorithm 2 with Steps 11–12 of the Algorithm 3).
PQM- and P-PQM-based ML have probabilistic nature. We need to run the storage algorithm once and the retrieval algorithm times to get measurements. We collect measurements of for PQM-based ML classification (whether PQM or P-PQM). Suppose we measure instances when (for fault-tolerant Algorithm 2) or when (for NISQ Algorithm 3). Then the affinity of an input pattern belonging to a given database of patterns, deemed , is given by . The closer is to — the closer the input pattern is to the database of patterns.
To infer the class/label of an input pattern, an analyst needs to construct individual pattern databases for each class/label. Next, the analyst will compute for each database. Finally, the analyst will assign a label to the input pattern based on the label of the database with the highest . In this paper, we do not compute as our goal is to improve the storage and retrieval process used to obtain individual measurements. To learn more about PQM-based ML classification, see Ref. [sousa2020parametric].
Note that the last two steps of Algorithms 2 and 3 suggest to measure the values of specific patterns in the database. On an ideal QC, we can get rid of these steps, as all the required information needed to compute would be given to us by measuring qubit . However, for NISQ devices, the situation is different: we may end up with measuring a pattern that has not been stored in the database. This happens due to a noisy nature of NISQ devices. In this case, we may need to implement an additional post-processing scheme. For example, one may assume that information about the value of is important and should be included in the computation of independent of the value of the pattern. Another approach would involve discarding the measurements of patterns that have not been present in the database. Answering this question is outside of the scope of this paper.
In this section, we cover our extension of P-PQM. Storing of information is discussed in Section 3.1, retrieval — in Section 3.2. For both storage and retrieval, we design fault-tolerant and NISQ implementations. Both of these implementations of EP-PQM typically require fewer qubits and gates than PQM and P-PQM implementations, as we will demonstrate below.
For a fault-tolerant implementation, we will reuse the PQM and P-PQM storage procedures shown in Algorithm 1.
EP-PQM storage procedure suitable for NISQ device is given in Algorithm 4. The latter requires two registers, the memory register with qubits and an auxiliary two-qubit register , as defined in Section 2.1. The algorithm starts with the following initial state
(10) |
where all the qubits in memory register are in state and the auxiliary register is in state . Since in EP-PQM the input patterns do not require a dedicated register, as they can be stored in a classical computer, this algorithm requires less qubits for the storage part. Indeed, comparing Eqs. (10) and (1), we see that EP-PQM storage part uses qubits versus qubits for PQM and P-PQM. After execution of Algorithm 4, the final state is a superposition of the input patterns with equal probabilities:
(11) |
In Algorithm 4, since the input pattern is stored classically, all the control operators acting on the input register are removed. Instead, we can classically check if the input pattern consists of 0 or 1. As a result, Steps 4, 5, 9, and 10 of Algorithm 1 are changed. These changes can be seen in Steps 3–7, and 11–15 of Algorithm 4. Steps 3–7 are used to make a copy of the bits of to the memory register, if the is flagged as , and then fill with ’s all the bits in the memory register which are equal to the respective bits in . Steps 11–15 will reverse the work done in Steps 3–7.
PQM outputs the probability of a target pattern being close to patterns in the database at the bit level. As discussed in Section 1, this approach is ineffective if we compute for symbols represented by multiple bits. For this reason, we extend the information retrieval part of PQM given in Algorithm 2.
Our extension generalizes the PQM algorithm to compute for features codified with label encoding. The extension requires four registers, namely, , , , and :
(12) |
The register is used to compare features. The number of qubits in is equal to the number of features in the pattern, deemed . Note that , where is the number of bits required to represent an attribute of a feature, i.e., . The -th qubit in register is set to if the binary string of length that represent -th feature of is the same as the corresponding binary string in . With included, the initial quantum state for retrieval of information is
(13) |
where all qubits in register are initially in state and the register in state .
With this extension, the retrieval algorithm is changed, as shown in Algorithm 5. The first and second steps are the same as the original Algorithm 2. In Step 3, results from Step 2 are used to update register . Given that each symbol is represented by a binary string of length and each input is of length , Step 3 will set the -th qubit in to . This will happen if the binary string of length , that represent the -th symbol of , is not the same as the corresponding binary string in . With register updated in Step 3, can be used in place of for Step 4. In Step 4, we use operator instead of , which is defined as
We use to calculate at the feature level. In Steps 5 and 6, inverse transformations of Steps 2 and 3 are applied and h gate is applied to the control qubit. In Step 7, is measured. If is measured in state , it means that the input is close to all stored patterns in the dataset. This probability is peaked around those patterns which have the smallest to the input at the feature level. The highest probability of retrieval thus occurs for patterns which are most similar to the input at the feature level. Finally, Steps 7–9 are identical to Steps 5–7 of Algorithm 2.
Akin to the NISQ implementation [sousa2020parametric], we decided to store the input pattern classically. This implementation requires only three registers: , , and , with , , and qubits, respectively:
(14) |
The initial quantum state for retrieval of information is
(15) |
The post-processing for EP-PQM is the same as that for PQM and P-PQM. We refer the reader to Section 2.3 for details.
NISQ version of the EP-PQM can be implemented on any modern NISQ architecture. We introduce a reference implementation on QisKit [Qiskit]
, a Python-based open-source software development kit for coding in OpenQASM and leveraging the IBM QCs. The code is given in
[dat:github]; it is based on our PQM-based string comparison approach [khan2021string].Similar to the QisKit Aqua [AquaAlgo12:online] library, we wrap OpenQASM invocations into a Python class so that a programmer without any QC coding experience can leverage the algorithm from any Python program. The code can be executed in a simulator on a personal computer or on the actual IBM QC.
As discussed above, all the algorithms operate on -bit patterns, but depends on the value of and the type of encoding (one-hot or label). Suppose we want to encode a pattern containing features with distinct attributes.
The case when is trivial because for any string. For the case when , formalizing Examples 1.1 and 1.2, we may say that for PQM and P-PQM, which have to use one-hot encoding,
(16) |
and for EP-PQM, which can use label encoding,
(17) |
In other words, when , all algorithms require bits to represent a pattern, and when , EP-PQM requires fewer bits and qubits.
On an ideal QC, based on Eqs. (1) and (3), PQM and P-PQM require qubits for storage and qubits for retrieval, making a total of qubits [pqmct]. In practice, one can perform the storage and retrieval algorithms for PQM and P-PQM on a single circuit. This will lead to a reduction in the number of qubits to [sousa2020parametric].
In EP-PQM, we stick to the conceptually similar approach and, based on Eqs. (10) and (12), use qubits. In the fault-tolerant implementation, EP-PQM requires qubits for storage and for retrieval. During storage procedure, we need register with two qubits. During retrieval, register is not needed, thus its qubits can be reassigned. We can reuse one of these qubits for register and one qubit as part of the register . Thus, we need only qubits in total.
Based on Eqs. (16) and (17), in the case, PQM and P-PQM will require bits while EP-PQM will need bits. When the savings start to emerge. EP-PQM needs qubits, while PQM and P-PQM encoding need qubits. Asymptotatically, this gives a reduction from , in the PQM and P-PQM cases, to , in the EP-PQM case.
If we use one circuit for both the storage and retrieval algorithms, P-PQM’s NISQ implementation^{1}^{1}1As mentioned in Section 2.2, PQM does not have a NISQ implementation., based on Eqs. (1) and (8), requires qubits. EP-PQM, based on Eqs. (10) and (14), uses qubits (as in the fault-tolerant implementation above, we reassign qubits).
In the fault-tolerant implementation, EP-PQM requires lesser number of bits and qubits than PQM and P-PQM when . In the NISQ implementation, EP-PQM is more efficient than PQM and P-PQM for all values of .
Our algorithm’s time complexity is proportional to the depth of the circuit for storage and retrieval. For now, we assume that different gates have the same time complexity (we will examine each gate type in Section 3.5.3).
In the fault-tolerant implementation, all three algorithms use Algorithm 1 to store the data, which requires gates.
PQM and P-PQM retrieval, based on Algorithm 2, need gates. EP-PQM retrieval, based on Algorithm 5, needs gates.
Consequently, the combined number of gates for storage and retrieval is for all three algorithms. As in the case of space complexity, discussed above, the savings are driven by the encoding schema. Since for one-hot encoding and for label encoding , the number of gates for PQM and P-PQM is , while for EP-PQM it is only .
PQM does not have a NISQ implementation, thus we focus on P-PQM and EP-PQM. The storage part of P-PQM, as in the fault-tolerant case, is governed by Algorithm 1, which, as discussed above, requires gates. EP-PQM storage is given in Algorithm 4; it still needs gates. As in the fault-tolerant case, the savings will come from the encoding schema, yielding gates for P-PQM and gates for EP-PQM.
In both fault-tolerant and NISQ cases, EP-PQM becomes more efficient than PQM and P-PQM with the growth of .
Complexity-wise, not all gates are created equal. Some gates increase complexity more than others. For example, on a NISQ device, c^{2}not gate requires more native gates than x gate, which increases complexity.
Algorithm 1 governs the data storage procedures for all three algorithms, except for the EP-PQM NISQ implementation, which is governed by Algorithm 4. Table 1 shows how many gates are required to implement these algorithms. When comparing the number of individual gates, we have to be mindful of the encoding, as varies as per Eqs. (16) and (17), where and denote in one-hot and label encoding cases, respectively.
The parameter denotes a fraction of 1-bits in the database. The largest number of gates will be needed when .
Algorithm 4 requires fewer control gates than Algorithm 1. Table 1 shows that it does not need any c^{2}not gates. The number of cnot gates will vary with , , and . Let us analyze this variation by exploring under what conditions the number of cnot gates of EP-PQM is smaller than the number of P-PQM gates. That is, when does the following inequality hold:
(18) |
All Fault-tolerant and P-PQM NISQ | EP-PQM NISQ | |
---|---|---|
Gate | Algorithm 1 | Algorithm 4 |
cnot | ||
c^{2}not | ||
c^{n}not | ||
x | ||
cs |
For and using Eqs. (16) and (17), the inequality (18) becomes
This inequality never holds, as . However, P-PQM and EP-PQM have the same number of cnot gates when .
In the case, Eq. (18) becomes
This inequality holds when for all . Thus, EP-PQM requires lesser number of cnot gates when .
To understand x gates count, we need to analyze the following inequality:
(19) |
When , using Eqs. (16) and (17), Eq. (19) simplifies to
This implies that P-PQM and EP-PQM have the same number of x gates when . For other values of EP-PQM outperforms P-PQM (when ).
Let us now explore case, where Eq. (19) becomes
(20) |
This inequality will hold for all . Thus, EP-PQM needs lesser number of x gates than P-PQM (when ).
In summary, we can say that EP-PQM will use the same number of gates as P-PQM when and (which is an extreme and rare case). For all other scenarios, EP-PQM will need lesser number of x gates than P-PQM.
The comparison of the number of specific gate required to retrieve data based on Algorithms 2, 3, 5, and 6 is given in Table 2. The parameter denotes the fraction of the bits in the input pattern that are 1’s.
Fault-tolerant | NISQ | |||
(P-)PQM | EP-PQM | P-PQM | EP-PQM | |
Gate | Algorithm 2 | Algorithm 5 | Algorithm 3 | Algorithm 6 |
cnot | ||||
c^{d}not | ||||
x | ||||
or | ||||
or | ||||
h |
A few observations. Table 2 suggests that the retrieval phase requires lesser number of gates than storage phase (as it is independent of ). NISQ versions of the algorithms require the same or lesser number of gates than their fault-tolerant counterparts; this is expected as NISQ approaches are designed with the focus on performance.
For both fault-tolerant and NISQ, EP-PQM requires additional c^{d}not gates than PQM and P-PQM. EP-PQM needs times less and gates than corresponding PQM and P-PQM counterparts ( and ) for .
For the fault-tolerant implementations, when , PQM and EP-PQM will need the same number of cnot gates (based on Eqs. 16 and 17). When , EP-PQM will need lesser number of cnot gates:
For the x gates, when , based on Eqs. (16) and (17), P-PQM is more efficient than EP-PQM:
When , the inequality becomes
This inequality holds for . Thus, EP-PQM needs lesser number of x gates when .
For the NISQ implementations, the number of x gates will vary with . For the case
Thus, for , if then P-PQM needs lesser number of gates than EP-PQM, and if — vice versa. If , the number of gates is identical.
For the case, EP-PQM will need lesser number of x gates than P-PQM when
(21) |
The values of the inequality’s left-hand-side are given in Figure 1. The inequality holds for different values of (in general, non-monotonically decreases with the increase of ). In other words, as increases, EP-PQM will require fewer x gates for a wider variety of input patterns. For example, when EP-PQM will require fewer x gates for any input pattern with more than 40% of bits set to 1, and when — for any input pattern with more than 20% of bits set to 1.
The principles of label encoding on a classical or a quantum computer are the same. Label encoding can, for instance, be applied directly to nominal and ordinal data. This method can also be applied to numeric data if they are mapped to labelled intervals.
So far, we were operating under the implicit assumption that each feature in an input dataset has the same number of attributes. However, in practice, this is often not the case. Our current (implicit) workaround is to set the number of characters in the alphabet to the maximum distinct number of attributes of any feature in the dataset.
For example, one feature may have two distinct attributes and another feature — 100 distinct attributes. In this case we will use seven bits (i.e., ) to represent each of the features.
To use only the minimal number of bits needed to represent each feature, we need to alter Steps 5 and 7 of Algorithms 4. Specifically, we need to replace^{2}^{2}2Gate replacement is all that is needed for ML classification task. To use this approach for computing the value of on a classical computer, we also need to alter the trigonometric formulas [khan2021string, Eqs. 2 and 3]. the c^{d}not gate for -th feature with c^{dj}not, where is the number of bits needed to represent an attribute of the -th feature.
In this paper, we focus on the Quantum ML classification use case. However, the same principles can be applied to any use case requiring encoding of data with multiple attributes.
For example, by using this approach, we can efficiently codify strings where characters are drawn from an alphabet with a large number of characters. A string may represent anything from mRNA sequences in bioinformatics to software log records in software engineering [khan2021string].
In order to compare P-PQM with EP-PQM, we show the number of qubits and gates necessary to perform classification on five datasets from the UCI Machine Learning Repository [dua2017uci] (which were also used by the authors of P-PQM [sousa2020parametric]). Summary statistics for the datasets are given in Table 3. Data are encoded using one-hot encoding in the P-PQM case, whereas label encoding is used in the EP-PQM case.
Dataset | Class/Label name | |||
---|---|---|---|---|
Balance Scale [uci:balancescale, paper:balancescale] | R | 262 | 4 | 5 |
Breast Cancer [uci:breastcancer, paper:breastcancer] | 2 | 412 | 9 | 11 |
SPECT Heart [uci:spectheart, paper:spect] | 1 | 36 | 22 | 2 |
Tic-Tac-Toe Endgame [uci:tictactoe, paper:tictactoepaper] | positive | 558 | 9 | 3 |
Zoo [uci:zoo, paper:zoopaper] | 1 | 40 | 16 | 6 |
Sousa et al. [sousa2020parametric] tested the performance of ML models using a 10-fold cross-validation approach, which assesses how well the training results generalize to previously unexplored data. In this approach, a dataset is divided into ten equal subsets. Then, nine subsets are used to train the model and one to validate the training results. The process is repeated ten times, with each of the subsets being used for validation only once.
In order to mimic this approach, we sample 90% of observations (i.e., patterns) from each dataset, referred to as . The observations in the dataset belong to different classes. Let us assume the dataset has distinct classes/labels. We group observations by labels, creating databases of observations. We then focus on of the databases with the most observations (as it represents the hardest task), since it will require the deepest quantum circuit for a given dataset. Let us look at a toy example.
Consider a dataset with three classes/labels and 1000 observations. We sample 90% of observations, i.e., . Suppose 500 observations belong to label 1, 300 observations — to label 2, and 100 observations — to label 3. We will focus only on the database of observations for label 1, as it is the largest.
We implement the quantum circuit needed to store and retrieve data using P-PQM (Algorithms 1 and 3) and EP-PQM (Algorithms 4 and 6). All quantum algorithms are implemented using Qiskit v0.33.1 [Qiskit]. The results for the quantum-circuit-based implementation are shown below; the results for the Quantum Simulator backend can be found in Appendix C.
For each dataset’s database with the most observations, we compute the quantum circuit depth and the number of gates needed to execute NISQ storage and retrieval algorithms. Finally, we perform a shallow decomposition of this circuit (by calling “decompose()” methods of the QisKit quantum circuit) and obtain the set of gates (shown in Table LABEL:tbl:low_gates_decomposed).
Table 3 contains high-level statistics for the datasets under study. The datasets have a diverse structure. For instance, SPECT Heart dataset has only two features and will be stored using binary variables for both P-PQM and EP-PQM. The rest of the algorithms have between and . Thus, for P-PQM we will encode the attributes using one-hot encoding and for EP-PQM — using label encoding.
Table 4 shows the number of qubits and quantum circuit depths. In addition, we compute relative resource savings while treating the resources needed for P-PQM as a baseline. The number of qubits used by P-PQM and EP-PQM in SPECT Heart is the same^{3}^{3}3For this implementation of P-PQM and EP-PQM, to simplify the code, one qubit from was reassigned to , but the second qubit of was not reassigned to . EP-PQM therefore requires one extra qubit in comparison with the theoretical requirement: instead of ., which is expected as . Label encoding reduces the number of qubits required by 48% to 77% in the rest of the datasets.
Peculiarly, quantum circuit depth is reduced for all datasets by 60% to 96%, showing the effectiveness of EP-PQM even for datasets with . The savings are even more evident after decomposition: the decomposed quantum circuit depth is reduced by 94% to 99%. These additional savings can be explained by the fact that many gate types (especially multi-controlled ones) require a lot of native gates to be implemented, thus increasing the quantum circuit depth.
As discussed in Section 3.5.3, to understand efficiency of the algorithms, we need to asses the count of specific gates. This information is given in Table LABEL:tbl:low_gates.
We will use typewriter font to reference the gates used in the QisKit’s implementation of the circuit. A number of gates are readily available. The cnot gate is implemented using cx. The c^{}not gates, where is the number of control qubits, will be implemented using cx when there is one control qubit, ccx when there are two control qubits, mcx when there are 3 or 4 control qubits and mcx_gray when there are more than or equal to 5 control qubits. The h gate is implemented using h, and x gate is implemented using x.
According to the table, EP-PQM significantly reduces the number of control gates cx, ccx, and mcx_gray by 58.7% to 100.0%. For three datasets in EP-PQM with , a small number of mcx control gates (, from 8 to 32) were added to implement c^{d}not for three datasets with ; for P-PQM, no mcx gates were required.
The EP-PQM approach results in significant reductions in other gates (namely, unitary and cunitary^{4}^{4}4 unitary denotes a custom unitary gate and cunitary is a controlled version of a custom unitary gate. QisKit simulator gates which cover algorithmic , , , , and cs gates) from 3.1% to 90.9% for all datasets except for SPECT Heart dataset where the number of gates was identical to the P-PQM algorithm.
For all datasets, EP-PQM reduces the number of x gates by 53.2% to 76.2%.
The count of gates obtained using shallow decomposition of the quantum circuit is given in Table LABEL:tbl:low_gates_decomposed. Decomposition of the circuit of the Breast Cancer dataset yielded gates c3sx, cu1, rcccx, and rcccx_dg not found in circuits of other datasets. To facilitate comparison with other datasets, we further decomposed these gates using “decompose([‘c3sx’, ‘rcccx’, ‘rcccx_dg’]).decompose(‘cu1’)”. This results in all datasets containing the same gates.
The savings are even more pronounced. For cu, cx, h, measure, t, tdg and u3 the number of gates reduced by 32.1% to 100.0%. Also, the number of phase gates, p, reduced by 66.7% and 90.9% for Tic-Tac-Toe Endgame dataset and Breast Cancer dataset respectively.
The number of gates for p in the Balance Scale dataset and Zoo dataset increased by 520.0% and 416.7% respectively and the number of u2 gates (where u2 is a single qubit gate) increased by 7200.0% for the Breast Cancer dataset. While the relative increase is significant, the absolute increase is relatively small — there are only a few hundred gates added. The number of single qubit gates u1 increased from 0 to 774 (as above, this number is small).
Overall, our experiments confirm our theoretical analysis and show that EP-PQM leads to a significant reduction in gate count compared to P-PQM. Consequently, EP-PQM is more applicable for NISQ devices due to a reduction in quantum circuit depth.
In this paper, we extend the PQM-based ML classification algorithm designed for use in NISQ devices. The original approach provided correct classification using one-hot encoding. We extend this approach to enable label encoding, which reduces space complexity (i.e., qubit count) from to and decreases the number of gates in the quantum circuit from to .
By simulating ML classification on five datasets (using QisKit QC Simulator) and analyzing the resulting circuit, we verified our theoretical analysis. Depending on the dataset, EP-PQM quantum circuit depth saving range between 60% and 96%. Similarly, EP-PQM reduces the corresponding decomposed quantum circuit depth between 94% and 99%. Qubit count was reduced by 48% to 77% for datasets with .
A reduction in space requirements makes it possible to load larger datasets into a QC. Furthermore, reducing the number of gates helps speed up classification and decrease noise associated with deep quantum circuits.
We are grateful to Compute Canada for providing access to computers with large amounts of memory. We would like to acknowledge Canada’s National Design Network (CNDN) for facilitating this research, specifically through their member access to the IBM Quantum Hub at Institut quantique.
Suppose there are two patterns and , containing features with attributes. Further suppose that and represented using one-hot encoding. Thus, -th feature will be represented by -bit string.
Let the Hamming distance be denoted by and the Hamming distance computed when comparing patterns encoded using one-hot encoding be denoted by . When performing pair-wise comparison, , when and are identical. The similarity ends when . By definition
Comments
There are no comments yet.