EP-PQM: Efficient Parametric Probabilistic Quantum Memory with Fewer Qubits and Gates

by   Mushahid Khan, et al.

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.



There are no comments yet.


page 16


Incremental Data-Uploading for Full-Quantum Classification

The data representation in a machine-learning model strongly influences ...

Parametric Probabilistic Quantum Memory

Probabilistic Quantum Memory (PQM) is a data structure that computes the...

Quantum pixel representations and compression for N-dimensional images

We introduce a novel and uniform framework for quantum pixel representat...

Quantum Garbled Circuits

We present a garbling scheme for quantum circuits, thus achieving a deco...

Ray-based framework for state identification in quantum dot devices

Quantum dots (QDs) defined with electrostatic gates are a leading platfo...

Code Repositories

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

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]

, reinforcement learning


, 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 


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.

Example 1.1.

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.

Example 1.2.

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

  1. Space savings, as for features the number of required qubits reduces from to for ;

  2. 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.

The rest of the paper is structured as follows. Section 2 recaps the PQM and P-PQM algorithms [sousa2020parametric]. In Section 3, we introduce the EP-PQM. Section 4 provides sample experiments with ML datasets. Finally, in Section 5 we present our final remarks and conclusions.

2 Probabilistic Quantum Memory (PQM)

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.

2.1 PQM and P-PQM: Storing Information

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


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 


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


The final result of the algorithm is the state


Note that in the retrieval phase, we are only concerned with the memory-register state .

input : The initial state given in Eq. (1)
output : Return defined in Eq. (2)
2 foreach  do
3       Load into quantum register
12       Unload from quantum register
The final state after completion of the for-loop will be
Algorithm 1 PQM and P-PQM storage algorithm [sousa2020parametric]. In control gate qubits act as controls and qubit is a target. For more details, see Appendix B.

2.2 PQM and P-PQM: Retrieving Information

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].

2.2.1 PQM: Retrieving Information

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 :


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


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.

input : The initial state given in Eq. (4)
output : 1) The value of and 2) one of the stored patterns that has minimum with the target pattern in a given run
5 Measure qubit
6 if  then
7       Measure the memory to obtain the desired state.
Algorithm 2 PQM retrieval algorithm — fault-tolerant implementation [sousa2020parametric].

The retrieval process is summarized in Algorithm 2. In Step 1, we apply the Hadamard gate on to the control qubit to get


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


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.

2.2.2 P-PQM: Retrieving Information

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


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).

Fault-tolerant implementation.

The algorithm for the quantum implementation of the P-PQM retrieval procedure is almost identical to the PQM one (shown in Algorithm 2). The only difference is that Eq. (6) is replaced with Eq. (7). The input into the algorithm, as in the PQM case, is given by Eq. (5).

NISQ implementation.

The NISQ implementation of the P-PQM retrieval algorithms is shown in Algorithm 3. This implementation requires only two registers, namely, and :


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:


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).

input : The initial state given in Eq. (9)
output : 1) The value of and 2) one of the stored patterns that has minimum with the target pattern in a given run
2 foreach  do
3       if  then
8 foreach  do
9       if  then
14 Measure qubit
15 if  then
16       Measure the memory register to obtain the desired state.
Algorithm 3 P-PQM retrieval algorithm — NISQ implementation [sousa2020parametric].

2.3 Post-processing on classical computer

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.

3 Ep-Pqm

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.

3.1 EP-PQM: Storing Information

Fault-tolerant implementation.

For a fault-tolerant implementation, we will reuse the PQM and P-PQM storage procedures shown in Algorithm 1.

NISQ implementation.

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


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:

input : The initial state given in Eq. (10)
output : Return defined in Eq. (11)
1 Prepare the initial state
2 foreach  do
       /* denotes the -th bit of the -th pattern . */
3       foreach  do
4             if  then
6            else
12       foreach  do
13             if  then
15            else
The final state after completion of the for-loop will be
Algorithm 4 EP-PQM storage algorithm — NISQ implementation.

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.

3.2 EP-PQM: Retrieving Information

Fault-tolerant implementation.

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 :


Registers , , and are the same as in Eq. (3), i.e., the PQM case discussed in Section 2.2.1.

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


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.

input : The initial state given in Eq. (13)
output : 1) The value of and 2) one of the stored patterns that has minimum with the target pattern in a given run
7 Measure qubit
8 if  then
9       Measure the memory register to obtain the desired state.
Algorithm 5 EP-PQM retrieval algorithm — fault-tolerant implementation.
NISQ implementation.

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:


The initial quantum state for retrieval of information is


Also, to further reduce the complexity of the circuit, we removed the x gates from Steps 3 and 5 of Algorithm 5. As in Algorithm 3, this results in measuring when is in state . As a result, Algorithm 5 changes to Algorithm 6.

input : The initial state given in Eq. (15)
output : 1) The value of and 2) one of the stored patterns that has minimum with the target pattern in a given run
2 foreach  do
3       if  then
6      else
12 foreach  do
13       if  then
16      else
20 Measure qubit
21 if  then
22       Measure the memory register to obtain the desired state.
Algorithm 6 EP-PQM retrieval algorithm — NISQ implementation.

3.3 Post-processing on classical computer

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.

3.4 Implementation

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.

3.5 Complexity analysis

3.5.1 Space complexity (qubits count)

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,


and for EP-PQM, which can use label encoding,


In other words, when , all algorithms require bits to represent a pattern, and when , EP-PQM requires fewer bits and qubits.

Fault-tolerant implementation.

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.

NISQ implementation.

If we use one circuit for both the storage and retrieval algorithms, P-PQM’s NISQ implementation111As 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).

Based on Eqs. (16) and (17), if , EP-PQM will require one less qubit than P-PQM: instead of . And when , P-PQM require qubits, while EP-PQM needs only . Asymptotatically, this again gives a reduction from to .


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 .

3.5.2 Time complexity: overall number of gates

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).

Fault-tolerant implementation.

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 .

NISQ implementation.

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 .

3.5.3 Specific gates

Complexity-wise, not all gates are created equal. Some gates increase complexity more than others. For example, on a NISQ device, c2not 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 c2not 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:

All Fault-tolerant and P-PQM NISQ EP-PQM NISQ
Gate Algorithm 1 Algorithm 4
Table 1: Gate count for storage algorithms.

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:


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


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
Gate Algorithm 2 Algorithm 5 Algorithm 3 Algorithm 6
Table 2: Gate count for retrieval algorithms. (P-)PQM stands for “PQM and P-PQM”.

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 cdnot 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


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.


Figure 1: The z-axis of this contour plot depicts the values of , defined in Eq. (21). Blue line denotes the boundary where . Above the blue line, P-PQM requires more x gates than EP-PQM; below it, P-PQM requires fewer x gates.

3.6 Remarks

3.6.1 Label encoding

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.

3.6.2 Attributes

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 replace222Gate 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 cdnot gate for -th feature with cdjnot, where is the number of bits needed to represent an attribute of the -th feature.

3.6.3 Other use cases

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].

4 Experiments

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
Table 3: Datasets’ description (based on 90% of the observations) of the class/label having the maximum number of observations.

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.

Example 4.1.

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 same333For 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.

! Number of Qubits Quantum Circuit Depth Decomposed Quantum Circuit Depth Dataset P-PQM EP-PQM Savings P-PQM EP-PQM Savings P-PQM EP-PQM Savings Balance Scale 42 18 57% 12,338 2,899 77% 108,510 4,515 96% Breast Cancer 200 47 77% 84,563 9,776 88% 821,728 12,407 98% SPECT Heart 46 46 0% 1,862 747 60% 16,390 982 94% Tic-Tac-Toe Endgame 56 29 48% 34,069 8,478 75% 309,188 11,847 96% Zoo 194 66 66% 8,060 334 96% 77,554 629 99%

Table 4: Comparison of the number of qubits and quantum circuit depth for class/label with maximum number of observations. A comma separates groups of thousands.

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 cnot 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 cdnot 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 cunitary444 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.

5 Summary

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.

Appendix A One Hot Encoding and : Relationship

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