A quantum Hopfield associative memory implemented on an actual quantum processor

In this work, we present a Quantum Hopfield Associative Memory (QHAM) and demonstrate its capabilities in simulation and hardware using IBM Quantum Experience.. The QHAM is based on a quantum neuron design which can be utilized for many different machine learning applications and can be implemented on real quantum hardware without requiring mid-circuit measurement or reset operations. We analyze the accuracy of the neuron and the full QHAM considering hardware errors via simulation with hardware noise models as well as with implementation on the 15-qubit ibmq_16_melbourne device. The quantum neuron and the QHAM are shown to be resilient to noise and require low qubit overhead and gate complexity. We benchmark the QHAM by testing its effective memory capacity and demonstrate its capabilities in the NISQ-era of quantum hardware. This demonstration of the first functional QHAM to be implemented in NISQ-era quantum hardware is a significant step in machine learning at the leading edge of quantum computing.

Since the advent of quantum computing, one of the primary applications which has piqued the interest of both academia and industry is quantum machine learning [1][2][3][4] . With the characteristics of quantum computing driven by superposition and entanglement of quantum states, quantum computing can create and model patterns in data which cannot be easily created in classical computing. Additionally, quantum parallelism allows for quantum gates to evaluate outputs of functions with multiple inputs simultaneously 5 . Quantum machine learning is therefore expected to produce significant speedup in machine learning algorithms 3 . Already, quantum machine learning models have been developed for generic quantum neural networks [6][7][8] , quantum dynamic neural networks 9 , continuous-variable quantum neural networks 10 , quantum convolutional neural networks 11,12 , and quantum Hopfield neural networks 13 . In large part, quantum machine learning research has recently been centered around the use of variational quantum algorithms as machine learning models [14][15][16][17] due to their high expressibility and rapid trainability compared to classical networks 17 . Extensive research has also been done at the intersection of classical and quantum machine learning to create hybrid machine learning techniques [18][19][20] , as well as in techniques for training quantum neural networks 21 and in machine learning using quantum-enhanced feature spaces 22 .
The characteristics of quantum computing are of particular interest for Hopfield network 23 applications 6,13,24,25 . Hopfield networks become intractable to compute classically due to their fully connected nature, though a recent paper claims "Hopfield networks is all you need" 26 for many complex machine learning tasks. With quantum computing, significant improvements in time and memory overhead for Hopfield networks have been claimed through algorithmic advantages, training from a superposition of input states and parallel computation 6,13 , resulting in theorized polynomial or exponential capacity improvements for some quantum associative memory designs 24,25,27 .
Several studies theorize quantum associative memories with improved capacity 24,27 , though neither have been implemented in hardware. The original design in 1998 27 utilizes both spin-1 2 and spin-1 qubits to demonstrate a theoretical associative memory, and a more recent design 24 involves long-range interactions of fully-connected qubits to generate a unitary evolution over time. Another approach implements a quantum neuron to perform pattern recognition 28 , but this design does not follow Hopfield dynamics and has not been extended to an associative memory system.
In the NISQ era of quantum computing 29 , quantum computers are limited by their low number of qubits and their high vulnerability to noise and quantum errors. Therefore, implementation of quantum machine learning architectures in quantum hardware is very difficult. Of the above designs, only one has been implemented in hardware 28 .

OPEN
School of Electrical and Computer Engineering, Georgia Institute of Technology, Atlanta, GA 30332, USA. * email: nathan.miller@gatech.edu In this work, we demonstrate a Quantum Hopfield Associative Memory (QHAM) implementable in IBMQ 30 , IBM's open source development platform allowing for the implementation of quantum algorithms in quantum hardware based on superconducting qubits. We consider the effects of quantum errors in simulation via the IBMQ QASM simulator 31 , as well as in IBMQ hardware devices of up to 15 qubits. We differentiate from prior works by following Hopfield dynamics with the use of a quantum neuron and by implementing the QHAM in a format compatible with quantum gate-based circuits utilized in IBMQ. Our design can be tested on an actual quantum processor in IBMQ considering noise sources such as readout noise 32 , quantum gate errors, and qubit decoherence 33 . Both our quantum neuron and our QHAM show resilience to noise and do not require midcircuit measurement or reset operations. Thus, our QHAM implementation is the first QHAM to be successfully demonstrated in quantum hardware.

Results
Background on Hopfield associative memories. The Hopfield network, first developed by J. J. Hopfield in 1982 23 , is a type of classical neural network which has demonstrated widespread capabilities in machine learning, most notably in creating associative (content-addressable) memories. In an associative memory, one or more memory states are learned by the network and stored in the network's weight matrix w (also called the neural interaction matrix). These states can be recovered by introducing an input state to the network which is close in Hamming distance to one of the stored states, then evolving the state of the network by updating individual neurons until convergence is reached.
Consider a Hopfield network of n fully connected neurons. Let each memory state stored in the network be represented by a vector ε with elements ε i ∈ {−1, 1} , such that ε is of length n and each ε i represents the binary state of neuron i. For m stored memories ε (1:m) , the elements w ij of the network's weight matrix w can be trained using Hebbian rules such that: where ε µ i represents bit i from pattern µ and ε µ j represents bit j from the same pattern. Each element w ij represents the interaction weight between neuron i and neuron j. Note that w ij has the restriction w ii = 0, ∀i such that no neuron has a connection with itself.
Let the vector x describe the initial state of the Hopfield network with n neurons where each neuron state is represented by x i ∈ {−1, 1} . The network undergoes a series of update steps where individual neurons have their states overwritten according to the interaction of the network state x with the weight matrix w ij . Neurons are updated using the rule: where h i is the threshold of neuron i and where each i to be updated can be chosen randomly or in a predefined order. One can also define θ i = n j=1 w ij x j in order to simplify the notation, where θ i is known as the input signal to the neuron i. As successive updates occur, the state of the network will converge to a state which is a local minimum of the energy function E = − 1 2 i,j w ij x i x j + i h i x i . Each of the stored memories are local minima of this energy function, and thus the stored memories are intuitively known as "attractors" since the network state will converge to the attractor which is nearest in Hamming distance. The initial state of the network is also known as a "probe, " as it is used to search the associative memory and return the nearest attractor. In this work, we mimic these attractor dynamics in the quantum regime to create a Quantum Hopfield Associative Memory.
Background on quantum neuron design. Several artificial neuron designs have been developed to apply this classical machine learning paradigm to quantum machine learning applications 6,28,34,35 . We base our system on the quantum neuron developed by Cao et al. 6 and modify their structure for implementation in IBMQ in a single, uninterrupted quantum circuit. The basic structure of the neuron developed by Cao et al. is shown in Fig. 1. In a quantum system, each classical neuron state x i can be mapped to a qubit in state |0� or |1� . Mapping each neuron state to the probability of measuring |1� in the qubit, x i = −1 corresponds to a pure |0� state ( P(|1�) = 0 ) and x i = 1 corresponds to a pure |1� state ( P(|1�) = 1 ). Any non-classical value of x i ∈ (−1, 1) can be represented as a superposition state, such as x i = 0 being represented by |s i � = |0�+|1� √ 2 where P(|1�) = 0.5 6 . One possible mapping of classical states to quantum states in this manner is described by: The full quantum system is thus represented by |s� = |s 1 s 2 . . . s n � . In order to mimic the attractor dynamics of a classical Hopfield network, we desire an update rule similar to Eq. (2) which can update the state of a single quantum neuron |s i � based on the interaction of w ij and |s� compared to a given threshold. In order to accomplish this, Cao et al. 6 consider the quantum circuit shown in Fig. 1 which produces a rotation on a target qubit of R y (2arctan(tan 2 φ)) if the input qubit measures |0� , where R y represents a rotation generated by the Pauli Y operator around the Y-axis of the Bloch sphere. This rotation, when applied to an initial |0� state, produces a |1� measurement probability of P(|1�) = sin 4 (φ) sin 4 (φ)+cos 4 (φ) on the output qubit. This output probability is used as an analog Scientific Reports | (2021) 11:23391 | https://doi.org/10.1038/s41598-021-02866-z www.nature.com/scientificreports/ to the classical neuron, in which φ > π 4 produces P(|1�) close to 1 and φ < π 4 produces a P(|1�) close to 0, corresponding to the classical x i = ±1 states. The parameter φ relates to the classical θ parameter by: where γ is a normalization factor such that 0 < φ < π 2 . Using this construction, the threshold behavior is achieved following Eq. (2) where all h i = 0 . The function chosen for γ is: We have slightly modified γ from the Cao et al. design 6 by removing the threshold term since all h i = 0 in the Hopfield associative memory application, and by using π 4 in the numerator instead of the approximate value of 0.7. This helps to ensure that quantum states corresponding to the classical x i = 1 are as close as possible to |s i � = |1�.
The CR y (2φ i ) rotation gate in the circuit in Fig. 1 is composed of rotations of the neuron state |s i � controlled by each |s j � which depend on the neural interconnection matrix elements w ij , followed by a rotation dependent on the bias term β . The bias term β is set by: which we simplify from the original design 6 using the knowledge that all h i = 0 . When these rotations are combined, the resulting operation is a rotation R y (2φ i ) on the target qubit.
This circuit operates in a Repeat-Until-Success (RUS) 36 manner wherein a measurement of |0� on the input qubit indicates that the rotation of R y (2arctan(tan 2 φ)) has been successfully applied to the output qubit. If the input qubit measures |1� , this indicates that a rotation of R y ( π 2 ) has been applied instead, in which case R y (− π 2 ) is applied to reverse the initial rotation and the circuit is repeated. This process continues until |0� is measured on the input qubit to indicate a successful rotation of the output qubit by R y (2arctan(tan 2 φ)) . Additionally, Cao et al. introduce a recursion method for this circuit which sharpens the rotation function to R y (2(arctan(tan 2 φ)) •k ) , where k is the number of recursions. This function performs more closely to a binary activation function as in Eq. (2) and thereby reduces the error rate of the system. Throughout this work, we compare our system to the k = 1 case of this design which does not include recursion.
This quantum neuron design is used to model Hopfield attractor dynamics wherein φ > π 4 (equivalently, θ > h = 0 ) results in P(|1�) close to 1 and φ < π 4 results in P(|1�) close to 0. The derivation and characterization of this quantum neuron model is shown and described in more detail by Cao et al. 6 .
Challenges in hardware implementation. The RUS circuit design presents difficulty for implementation in quantum hardware due to its requirement of mid-circuit measurement and reset operations. The midcircuit measurements are used to perform the check for success and the reset operations are used to recycle the output qubit for successive updates. These operations are a limiting factor for the hardware implementation of many quantum algorithms, as measuring or resetting the state of a qubit can result in collapsing the wavefunction of other qubits in the system. IBMQ is one quantum development platform which has recently enabled reset operations in its newest hardware for dynamic circuit execution 37 , but avoiding qubit reset in favor of sequential circuit execution remains desirable for many quantum hardware platforms and applications.
The qubit overhead of the Cao et al. design is dependent on the use of reset operations in order to reset the ancilla qubits (the input and output qubits in Fig. 1) to |0� to recycle them for many qubit updates 6 . Should the system be implemented in hardware where reset is not available, this overhead increases from n + 2 qubits Figure 1. Quantum neuron circuit architecture based on Cao et al. 6 . The basic quantum neuron architecture designed by Cao et al. 6 utilizes controlled rotations dependent on a superposition of input states to create a controlled rotation CR y (2φ) . A measurement of |0� on the input qubit indicates that the output qubit has been rotated R y (2q(φ)) with q(φ) = arctan(tan 2 φ) . If |1� is measured, the circuit has applied R y ( π 2 ) to the output qubit, in which case this rotation is reversed and the circuit is repeated until success is achieved. www.nature.com/scientificreports/ (where n is the size of the associative memory) to n + 2u qubits, where u represents the number of updates to be performed on the system. This qubit overhead is included in Table 1.
In its basic form, the Cao et al. quantum neuron design 6 also has very high gate complexity, thereby incurring extensive time overhead upon execution. The gate complexity of this design is shown in Table 1 and derived in more detail in the Supplementary Information. The high gate complexity of the quantum neuron becomes a significant problem for the overall error rate of the system. As errors occur in each gate, the large number of gates leads to significant error in the overall output of the system as errors cascade from one gate operation to the next. A metric called quantum volume 38 describes the largest circuit of equal width and depth that a quantum computer can successfully implement. Considering the small quantum volume of modern quantum systems in the NISQ era (shown for IBMQ systems in Supplementary Information Table S1), hardware execution of a circuit as complex as an associative memory requires low circuit complexity to be successfully implementable in hardware. Reducing gate complexity thus becomes a very important factor to the design of a QHAM.

Proposed quantum neuron.
To address the challenges in the original quantum neuron design 6 , we propose a quantum neuron design which avoids mid-circuit measurement and reset operations and which improves resilience to errors in quantum hardware. In order to avoid these operations, the measurement operation on the input qubit in the neuron described in Fig. 1 is removed. In the design by Cao et al. 6 , this measurement was used for classical conditioning to determine whether or not the circuit construction must be repeated in the Repeat-Until-Success construction. By removing this conditioning step, the probability of measuring |1� at the output qubit is changed from sin 4 (φ)+cos 4 (φ) to simply sin 2 (φ) , which is the same output probability as that which is obtained by applying a rotation of CR y (2φ) . Therefore, we modify our quantum neuron from the original structure in Fig. 1 to simply be a CR y (2φ) rotation controlled by all other qubits in the system, as shown in Fig. 2 and following the same construction as the boxed CR y (2φ i ) rotation in Fig. 1.
This reduction removes mid-circuit measurement operations and significantly lowers the circuit complexity of the neuron design, as only a single multi-controlled rotation is performed rather than the full, repeated construction shown in Fig. 1. A summary of the differences between our neuron and the neuron by Cao et al. 6 is shown in Table 1. As derived in the Supplementary Information, the gate complexity of our design is only (10n − 3)u , where n is the size of the associative memory and u is the number of updates performed. By comparison, the gate complexity of the RUS neuron is [20n(f + 1) − 4f − 5]u , where f is the average number of failures in the RUS process. This significant reduction in gate complexity reduces the time overhead of the circuit and reduces the effect of cascading errors in each qubit operation. Additionally, our design can be rid of reset operations by not recycling the ancilla (target) qubit for successive updates at the cost of qubit overhead.
To update an initial qubit state |s i � to a new state |s i � ′ , the rotation by 2φ is performed on an ancilla (target) qubit initialized to state |0� , then the output of the neuron on the ancilla qubit is swapped to the qubit which held the original state using a quantum SWAP gate. An example of this circuit using an initial state of length n = 4 and performing an update of the third qubit |s 3 � followed by an update of the second qubit |s 2 � is shown in Fig. 2b. In this example, the qubit used to perform the update is not recycled in order avoid reset operations. Avoiding reset operations improves the accuracy of the neuron and allows for implementation in hardware which does not support reset operations. In order to save on qubit overhead in systems where reset is possible, one can recycle the ancilla for multiple updates by performing the CR y rotation, swapping the updated state to the desired qubit, resetting the ancilla to |0� , and performing the next update. Since the quantum neuron design requires the target qubit to be in state |0� before performing the rotations, one cannot simply perform the rotation on the desired qubit directly. However, the SWAP operation can also be avoided by reassigning the target qubit to be the |s i � ′ and discarding the qubit which originally held |s i �.
In the original neuron 6 , a majority vote of many measurements of the updated qubit is used to reassign the state to pure |0� or |1� immediately after being updated in order to achieve a binary activation function. As this requires mid-circuit measurement and repeated execution of the circuit, we leave the updated qubits in their state produced by the update between evaluation steps as shown in Fig. 2b. Since this means that the update step does Table 1. A summary of the differences between our quantum neuron and the quantum neuron designed by Cao et al. 6 . In these calculations, it is assumed that reset is unavailable and there is no recursion in the Cao et al. neuron. The parameter n represents the size of the associative memory, u represents the number of updates, and f represents the average number of failures in the RUS process. See the Supplementary Information for a more detailed analysis and derivation of gate complexity.

Mid-circuit measurement required Yes No
Qubit overhead without resets n + 2u n + u Qubit overhead with resets n + 2 n + 1

Total gate complexity O(nuf) O(nu)
Single-qubit depth  Fig. 3a. Using a noise model defined by IBMQ which models ibmq_ quito hardware noise, we observe a significant error rate particularly in the region φ < π 4 . This neuron cannot be tested in the ibmq_quito hardware because of the required mid-circuit measurement and reset operations and because of the limited size of the ibmq_quito architecture. We expect that this quantum neuron would perform significantly worse in true hardware than in noise model simulation considering the connectivity constraints in hardware mentioned leading to increased gate complexity.
The simulation and hardware accuracy of our simplified quantum neuron is shown in Fig. 3b. We observe that our updated design is more resilient to noise and hardware errors than the RUS design because it requires less gates and less qubits. The simulation results of our neuron design incorporating the ibmq_quito noise model shown in Fig. 3b almost exactly overlap with the desired output function. The hardware measurements show degradation particularly in the φ > π 4 regime, but this hardware error is much lower than the simulated error in the RUS design.  Fig. 1. (b) Quantum circuit representing two updates of a selected qubits, |s 3 � then |s 2 � . In this case, |s 3 � is updated using the state described by |s 1 s 2 s 4 � , then |s 2 � is being updated using the state described by |s 1 s ′ 3 s 4 �. www.nature.com/scientificreports/ In the original design, an activation function was applied to the rotation angle of the output state, namely arctan(tan 2 (φ)) , whereas in our design, we allow for the rotation around the Bloch sphere itself to act as an activation function, such that the probability of measuring |1� follows the non-linear function P(|1�) = sin 2 (φ) dependent on φ . This reduction results in a more gradual activation function between measuring |0� and |1� (as shown in Fig. 3) but allows for uninterrupted execution in a single quantum circuit and reduces the qubit overhead and gate complexity of the circuit. While the slope of the activation function in our neuron is more gradual, it also shows much better resilience to noise and demonstrates performance in hardware which closely models its expected output, as shown in Fig. 3. However, this more gradual slope of the activation function can reduce the accuracy of update steps where φ is close to its midpoint of π 4 .
The quantum Hopfield associative memory. To model an associative memory using our quantum neuron, an initial state vector x is given and converted to its quantum representation |s� = |s 1 s 2 . . . s n � . Given this initial state and a set of attractor states trained into the weight matrix w as described by Eq. (1), updates are performed on individually selected qubits to move the network state closer to the nearest attractor. The qubit overhead of the system with attractors and initial state of length n, which we define as q, is determined by: given that the test is performed in an environment where the qubit used for the updates can be recycled using a reset operation. However, when qubits cannot be recycled in hardware, an additional qubit is required per update (as in Fig. 2). When performing u updates, Eq. (7) becomes: This qubit overhead is included in Table 1.
Note that there are fundamental differences in the way updates are performed in our design and in the classical Hopfield associative memory. In the classical case, each update results in the updated x i being rewritten to −1 or +1 depending on the value of the update rule with respect to the desired threshold, typically described by Eq.
(2). However, in our quantum case, we utilize a rotation around the Bloch sphere where P(|1�) = sin 2 (φ i ) and therefore the updated qubit states are rarely a true |0� or |1� . Cascading many updates on all qubits in the system in this fashion without stopping execution of the quantum circuit intermediately to rewrite the qubit states to pure |0� or |1� based on a majority vote measurement value (as in Cao et al. 6 ) will eventually result in the state of each qubit converging to a superposition state depending on the average value of the probe elements rather than converging to a memory state as desired. Therefore, in order to maintain the quantum nature of the system within the capabilities of quantum hardware, we perform either individually selected updates on specific qubits or random updates up to a set hyperparameter of u total updates which can be tuned for maximum accuracy. After all of the updates, the system state can be measured with a desired number of "shots" to determine the probability distribution for each state. To determine the classical output of the system, we take a majority vote of many measurements of each of the individual qubits in the system to compose the final memory recall result.
Simulating the QHAM. Simulation results for two-attractor systems of sizes 4, 9 and 16 are shown in Fig. 4. The vectors representing the system states are reshaped to squares where the index of the memory elements are read left to right, top to bottom. In the size 9 and 16 cases, we update multiple selected qubits which are in "corrupted" superposition states of |0�+|1� √ 2 (equivalent to x i = 0 described previously), starting from lowest index corrupted qubit and following in order of index to demonstrate the performance of individual updates with our quantum neuron. Qubits which are updated first in this order tend to have a lower accuracy than qubits which are updated later in the update chain, since in the early updates there are more corrupted states used as controls for the update. This can be alleviated by updating the qubits multiple times, as in Fig. 5. Note that Figs. 4 and 5 show the P(|1�) of each qubit. From this, a majority vote of each of the qubit measurements can be taken to compose a classical binary result. One potential application of this execution method is in restoring images with corrupted pixels. www.nature.com/scientificreports/ Testing the QHAM in IBMQ hardware. We also demonstrate the n = 4 system in the 15-qubit ibmq_16_melbourne hardware 40 shown in further detail in Fig. S1 of the Supplementary Information. The hardware results for the n = 4 system execution are shown in Fig. 6. The ideal n = 4 system with a single update should require 5 qubits for its execution according to Eq. (7). However, since each qubit in the device is not directly physically connected to all other qubits, intermediate qubits must be used in order to transfer information between control and target qubits. As a Hopfield network requires high connectivity, the overall qubit connectivity of the system is crucial for performance in order to avoid these intermediate connections and additional qubits which contribute to increased noise in the system. Further analysis of hardware limitations and noise can be found in the Supplementary Information, including Table S1 and Table S2.
Determining effective memory capacity. To benchmark the QHAM we study its effective memory capacity 41,42 which quantifies the number of memories m which can be successfully stored and recalled in an  which is within ρn of ε 1 , or x = [−1, −1, 1, −1, −1] which is within ρn of ε 2 . As the Hopfield network performs updates on random elements of the probe, the state of the probe converges to the stored memory which is the closest in Hamming distance to the original probe. In a rigorous analysis by McEliece et al. 41 , it is derived that with 0 ≤ ρ < 1 2 , the maximum m patterns which can be successfully recalled in a classical associative memory grows as: We map these m memories and the probe to the quantum domain following Eq. (3), prepare the input state described by the equivalent quantum representation of the probe s = |s 1 s 2 . . . s n � and create the Hebbian weight matrix using the attractors following Eq. (1). Random updates are performed up to the hyperparameter u (representing the number of updates to perform) and the output of all n states are measured. After all of the updates, the system state can be measured with a desired number of "shots" to determine the probability distribution for each state. To determine the classical output of the system, we take a majority vote of many measurements of each of the individual qubits in the system to compose the final memory recall result.
Simulation of QHAM effective memory capacity. To analyze effective memory capacity, we perform Monte Carlo simulation with many random memories and probes to determine the accuracy of the system in reproducing the desired memory state. The capacity results for n = {4, 5, . . . , 10} , m = {1, 2, . . . , 10} and ρ = 0.2 are shown in Fig. 7. Figure 7a shows these results as a function of α = m n using a term we call "majority vote accuracy, " which is measured as the percentage of accurate memory strings obtained after taking a majority vote of many measurements of each of the individual qubits in the system. For example, if an experiment is run with 8192 "shots" as we use for our simulations, we take a majority vote for each qubit such that if a majority of the 8192 shots return |s 0 � = |0� , then result of qubit |s 0 � is assigned to |0� . For a target memory of |s� = |0110� , the majority vote accuracy is measured as the percentage of tests in which |0110� is returned after the majority vote result of each individual qubit is taken.
In Fig. 7b, we analyze an accuracy metric which we call "density accuracy" which describes the average rate of each of the individual qubits being measured in the correct state. This measurement quantifies the average accuracy of each individual qubit in the system and is used to model how the results propagate in the quantum domain, as it is a close reflection of the superposition states of each of the individual qubits. For example, if |s 0 � returns the desired value |0� in 90% of shots, and |s 1 � returns the desired value |1� in 100% of shots, then the density accuracy of the two qubit system is 95%. The results in Fig. 7a,b have been tuned to the value of the hyperparameter u which yields the maximum majority vote accuracy. An example of this hyperparameter tuning is shown in Fig. 7c. Since we cannot check for convergence in the quantum domain after each individual update because this would require mid-circuit measurement, we tune u with Monte Carlo simulation.
In these QHAM implementations, we notice trends mirroring the classical memory capacity calculations, even with the neuron activation function not being perfectly binary (as shown in Fig. 3). With ρ = 0.2 and n ∈ [4, 5, . . . , 10] , the probes which are allowed to be introduced contain no flipped bits when n = 4 or n = 5 , and a single flipped bit for 6 ≤ n ≤ 10 . Based on these results, we clearly see two separate trends in Fig. 7 wherein a greater number of flipped bits in the probe leads to lower classification accuracy. Since the ρ we define is an In the density accuracy measurements in Fig. 7b, which reflect the accuracy of the system in the quantum domain, we observe well over 90 % accuracy for all n when m = 1 . We also demonstrate tuning of the u parameter in Fig. 7c based on the majority vote accuracy measurements. Figure 7c shows the results of tuning the QHAM of length n = 10 when storing m = 2 and m = 4 memories. In these examples, the majority vote accuracy increases with each update as incorrect bits are corrected up to an optimal number of updates u. After this optimal u, the accuracy tends to decrease as the inaccuracy inherent in the neuron activation function (shown in Fig. 3) propagates through the circuit and leads to the incorrect changing of correct bits in the memory string. With a larger number m of stored memories, spurious minima are more likely to exist in the optimization landscape of the associative memory system, lowering the optimal u and the overall accuracy of the system. Overall, the accuracy improves with increasing updates up until the optimal u, beyond which the probability of incorrectly flipping an incorrect bit outweighs the probability of correctly flipping an incorrect bit. In this example, the optimal u is shown to be 16 for m = 2 and 12 for m = 4 . All of the data shown in Figs. 7a and 7b are tuned using this metric.
Simulation of QHAM effective memory capacity considering noise. In addition to simulating the effective memory capacity of the QHAM system in the noiseless scenario, we perform measurements of the QHAM capacity under the effects of simulated hardware noise from the ibmq_16_melbourne noise model as shown in Fig. 8. The sources of this noise due to quantum errors are further described in the Supplementary Information. With n = {4, 5, . . . , 10} , m = {1, 2, . . . , 10} and ρ = 0.2 as in the noiseless simulations, we see the m = 1 case for n = 4 and n = 5 demonstrate perfect recall when the output is extracted to the classical domain in the majority vote accuracy test in Fig. 8a, and degradation of the recall for larger n. In these measurements, we observe that memories with larger size n show lower effective capacity for the same ρ eff . This is explained by the larger number of updates performed in these cases and the need to take majority votes from n probabilistic qubit outputs wherein inaccuracies caused by noise can compound for large n. Without this inaccuracy from the majority vote extraction to the classical domain, the density accuracy metric shown in Fig. 8b tends to show a more condensed trend regardless of n. However, compared to the same tests without any noise modeling as shown in Fig. 7, the noise model results show significant degradation in their density accuracy measurements, for example the m = 1 , n = 4 case showing approximately 95% accuracy as opposed to perfect accuracy in the noiseless test. We also demonstrate tuning of the u parameter in Fig. 8c based on the majority vote measurements. Tuning u shows less of a defined optimization point when noise effects are included compared to the noiseless case, as increasing the number of updates leads to more compounding error due to noise. Increasing the number of updates increases the gate complexity of the quantum circuit, thereby increasing the amount of noise injected by each gate operation, thus increasing the error inherent in the neuron (see Fig. 3). Therefore, the optimal u tends to be lower in the noisy associative memory tests than in the equivalent noiseless associative memory, as the noise introduced by further gate complexity eventually outweighs the benefit of performing an update.
QHAM effective memory capacity in hardware. For limited cases, we are able to implement the QHAM in the ibmq_16_melbourne hardware. The same test structure as used in simulation is performed for n = {3, 4, 5} , m = {2, 3, 4} , ρ = 0.2 and 1024 shots, as shown in Fig. 9. We note that the number of trials performed for these measurements is much lower than the number of trials performed in simulation due to hardware availability. Clearly, the hardware implementation of the associative memory degrades the ability of the system to store memories, even more than the test with simulated noise from the noise model of the same hardware device. This is due to the significantly increased noise from lack of hardware connectivity and the increased number of qubits required for hardware execution of the QHAM circuit. While the noise model takes quantum error effects into account, it does not take into account these limitations. The noise model construction is explained There is some recall in the single pattern case for n = 3 , but an accuracy metric of around 60 % in the majority vote case is quite low for the production of meaningful results. In this case, quantum error correcting codes would become highly useful.

Discussion
We have demonstrated a Quantum Hopfield Associative Memory system which can be executed in real quantum hardware via IBMQ. The number of qubits scales linearly with the length of the memory in simulation and in hardware where reset operations are available. If reset operations are not possible, the system also scales linearly in the number of updates. The accuracy of this system depends strongly on quantum errors and noise, but we demonstrate high resilience to these errors when extracting the quantum superposition states to the classical domain via a majority vote of many circuit shots. Noise modeling in simulation via IBMQ aids in understanding the effects of different types of noise on quantum circuit performance, while testing in hardware shows limitations due to a low number of qubits and limited connectivity. We benchmark the QHAM by measuring its effective memory capacity which is shown to mimic the effective memory capacity of classical Hopfield associative memory systems. The output of the QHAM can also remain in the quantum domain via n entangled superposition states with high accuracy, which could then be used for further quantum computation. The implementation of quantum associative memory models such as ours are significant for the advancement of machine learning in the domain of quantum computing. In the NISQ era of quantum computing, this successful QHAM implementation in hardware is a significant demonstration of what can be done in quantum hardware even in devices with a limited number of qubits and high noise. With applications in image recognition, optimization, data restoration from corrupt storage and more, our QHAM has high potential for further development in various application spaces. Further study pathways include noise-aware training, quantum algorithm developments for producing true Hopfield threshold dynamics in the quantum domain, and quantum hardware developments for increased connectivity. There have been promising developments in quantum associative memory models which theorize polynomial or exponential improvements in memory capacity 24,25,27 , which is a major motivation to continue this work to determine a route for true quantum advantage in this area. Our study demonstrates a step in this direction by being the first of its kind in which hardware implementation is explored.

Methods
All QHAM testing was performed using IBMQ. Most data was collected via the QASM Simulator using noise models produced by the hardware systems, and some hardware tests were performed for cases which were small enough to fit on the quantum hardware, specifically on ibmq_16_melbourne, the largest publicly available IBMQ hardware device at the time of this work with 15 qubits. The noise models are frequently updated and calibrated by IBM to maintain accuracy to the true systems, and new versions of hardware are frequently being released. In this study, the specific IBMQ hardware versions utilized were: ibmq_5_yorktown (ibmqx2) v2.2.6, ibmq_16_melbourne v2.3.8, ibmq_athens v1.3.10, ibmq_santiago v1.3.10, ibmq_lima v1.0.2, ibmq_quito v1.0.4, ibmq_belem 1.0.0, and ibmq_armonk v2.4.0.
All QASM Simulator and hardware tests run with IBMQ use a variable called "shots" which represents the number of repeated tests which will be performed in the QASM simulator in order to gain an output probability distribution which is close to describing the true superposition state of the qubits. For the tests shown in Figs. 4, 5 and 6 and Table S2, we use shots = 8192 , the maximum allowed by IBMQ at the time of these experiments. For the Monte Carlo tests shown in Figs. 7, 8 and S2, we use shots = 1024 to save on run time, then perform many of these same tests and take a separate majority vote of the results to produce the effective memory capacity measurements. For all n in simulation we perform 1000 tests for the Monte-Carlo simulation www.nature.com/scientificreports/ (for 1024 * 1000 = 1,024,000 total "shots"), and in hardware we perform only 30 tests due to long hardware queue times.

Data availability
The code used for IBMQ simulation, testing and data analysis and the data produced and analyzed in this study are available from the authors upon reasonable request.