Skip to main content

Thank you for visiting You are using a browser version with limited support for CSS. To obtain the best experience, we recommend you use a more up to date browser (or turn off compatibility mode in Internet Explorer). In the meantime, to ensure continued support, we are displaying the site without styles and JavaScript.

Integer factorization using stochastic magnetic tunnel junctions


Conventional computers operate deterministically using strings of zeros and ones called bits to represent information in binary code. Despite the evolution of conventional computers into sophisticated machines, there are many classes of problems that they cannot efficiently address, including inference, invertible logic, sampling and optimization, leading to considerable interest in alternative computing schemes. Quantum computing, which uses qubits to represent a superposition of 0 and 1, is expected to perform these tasks efficiently1,2,3. However, decoherence and the current requirement for cryogenic operation4, as well as the limited many-body interactions that can be implemented, pose considerable challenges. Probabilistic computing1,5,6,7 is another unconventional computation scheme that shares similar concepts with quantum computing but is not limited by the above challenges. The key role is played by a probabilistic bit (a p-bit)—a robust, classical entity fluctuating in time between 0 and 1, which interacts with other p-bits in the same system using principles inspired by neural networks8. Here we present a proof-of-concept experiment for probabilistic computing using spintronics technology, and demonstrate integer factorization, an illustrative example of the optimization class of problems addressed by adiabatic9 and gated2 quantum computing. Nanoscale magnetic tunnel junctions showing stochastic behaviour are developed by modifying market-ready magnetoresistive random-access memory technology10,11 and are used to implement three-terminal p-bits that operate at room temperature. The p-bits are electrically connected to form a functional asynchronous network, to which a modified adiabatic quantum computing algorithm that implements three- and four-body interactions is applied. Factorization of integers up to 945 is demonstrated with this rudimentary asynchronous probabilistic computer using eight correlated p-bits, and the results show good agreement with theoretical predictions, thus providing a potentially scalable hardware approach to the difficult problems of optimization and sampling.

Access options

Rent or Buy article

Get time limited or full article access on ReadCube.


All prices are NET prices.

Fig. 1: Characteristics of stochastic magnetic tunnel junctions.
Fig. 2: Experimental demonstration of a p-bit.
Fig. 3: Experimental demonstration of integer factorization.

Data availability

The datasets generated and analysed during this study are available from the corresponding authors on reasonable request.


  1. 1.

    Feynman, R. P. Simulating physics with computers. Int. J. Theor. Phys. 21, 467–488 (1982).

    MathSciNet  Article  Google Scholar 

  2. 2.

    Shor, P. Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer. SIAM J. Comput. 26, 1484–1509 (1997).

    MathSciNet  Article  Google Scholar 

  3. 3.

    Vandersypen, L. M. K. et al. Experimental realization of Shor’s quantum factoring algorithm using nuclear magnetic resonance. Nature 414, 883–887 (2001).

    CAS  ADS  Article  Google Scholar 

  4. 4.

    Preskill, J. Quantum computing in the NISQ era and beyond. Quantum 2, 79 (2018).

    Article  Google Scholar 

  5. 5.

    Kirkpatrick, S., Gelatt, C. D. & Vecchi, M. P. Optimization by simulated annealing. Science 220, 671–680 (1983).

    CAS  ADS  MathSciNet  Article  Google Scholar 

  6. 6.

    Geman, S. & Geman, D. Stochastic relaxation, Gibbs distributions, and the Bayesian restoration of images. IEEE Trans. Pattern Anal. Mach. Intell. 6, 721–741 (1984).

    CAS  Article  Google Scholar 

  7. 7.

    Sutton. B., Camsari, K. Y., Behtash, B.-A. & Datta, S. Intrinsic optimization using stochastic nanomagnets. Sci. Rep. 7, 44370 (2017).

    ADS  Article  Google Scholar 

  8. 8.

    Camsari, K. Y., Faria, R., Sutton, B. M. & Datta, S. Stochastic p-bits for invertible logic. Phys. Rev. X 7, 031014 (2017).

    Google Scholar 

  9. 9.

    Albash, T. & Lidar, D. A. Adiabatic quantum computation. Rev. Mod. Phys. 90, 015002 (2018).

    ADS  MathSciNet  Article  Google Scholar 

  10. 10.

    Ikeda, S. et al. A perpendicular anisotropy CoFeB–MgO magnetic tunnel junction. Nat. Mater. 9, 721–724 (2010).

    CAS  ADS  Article  Google Scholar 

  11. 11.

    Kent, A. D. & Worledge, D. C. A new spin on magnetic memories. Nat. Nanotechnol. 10, 187–191 (2015).

    CAS  ADS  Article  Google Scholar 

  12. 12.

    Peng, X. et al. Quantum adiabatic algorithm for factorization and its experimental implementation. Phys. Rev. Lett. 101, 220405 (2008).

    ADS  Article  Google Scholar 

  13. 13.

    Biamonte, J. Nonperturbative k-body to two-body commuting conversion Hamiltonians and embedding problem instances into Ising spins. Phys. Rev. A 77, 052331 (2008).

    ADS  MathSciNet  Article  Google Scholar 

  14. 14.

    Jiang, S., Britt, K. A., Humble, T. S. & Kais, S. Quantum annealing for prime factorization. Sci. Rep. 8, 17667 (2018).

    ADS  Article  Google Scholar 

  15. 15.

    Ackley, D. H., Hinton, G. E. & Seinowski, T. J. A learning algorithm for Boltzmann machines. Cogn. Sci. 9, 147–169 (1985).

    Article  Google Scholar 

  16. 16.

    Camsari, K. Y., Salahuddin, S. & Datta, S. Implementing p-bits with embedded MTJ. IEEE Electron Device Lett. 38, 1767–1770 (2017).

    ADS  Article  Google Scholar 

  17. 17.

    Fukushima, A. et al. Spin dice: a scalable truly random number generator based on spintronics. Appl. Phys. Express 7, 083001 (2014).

    ADS  Article  Google Scholar 

  18. 18.

    Mizrahi, A. et al. Neural-like computing with populations of superparamagnetic basis functions. Nat. Commun. 9, 1533 (2018).

    ADS  Article  Google Scholar 

  19. 19.

    Julliere, M. Tunneling between ferromagnetic films. Phys. Lett. A 54, 225–226 (1975).

    ADS  Article  Google Scholar 

  20. 20.

    Brown, W. F. Thermal fluctuations of a single-domain particle. Phys. Rev. 130, 1677–1686 (1963).

    ADS  Article  Google Scholar 

  21. 21.

    Chaves-O’Flynn, G. D., Wolf, G., Sun, J. Z. & Kent, A. D. Thermal stability of magnetic states in circular thin-film nanomagnets with large perpendicular magnetic anisotropy. Phys. Rev. Appl. 4, 024010 (2015).

    ADS  Article  Google Scholar 

  22. 22.

    Slonczewski, J. C. Current-driven excitation of magnetic multilayers. J. Magn. Magn. Mater. 159, L1–L7 (1996).

    CAS  ADS  Article  Google Scholar 

  23. 23.

    Berger, L. Emission of spin waves by a magnetic multilayer traversed by a current. Phys. Rev. B 54, 9353–9358 (1996).

    CAS  ADS  Article  Google Scholar 

  24. 24.

    Brataas, A., Kent, A. D. & Ohno, H. Current-induced torques in magnetic materials. Nat. Mater. 11, 372–381 (2012).

    CAS  ADS  Article  Google Scholar 

  25. 25.

    Pervaiz, A. Z., Ghantasala, L. A., Camsari, K. Y. & Datta, S. Hardware emulation of stochastic p-bits for invertible logic. Sci. Rep. 7, 10994 (2017).

    ADS  Article  Google Scholar 

  26. 26.

    Camsari, K. Y., Chowdhury, S. & Datta, S. Scaled quantum circuits emulated with room temperature p-bits. Preprint at 2018).

  27. 27.

    Kleinjung, T. et al. in Advances in Cryptology – CRYPTO 2010 (ed. Rabin, T.) 333–350 (Springer, 2010).

  28. 28.

    Lee, Y. K. et al. Embedded STT-MRAM in 28-nm FDSOI logic process for industrial MCU/IoT application. In 2018 IEEE Symposium on VLSI Technology 181–182 (IEEE, 2018).

  29. 29.

    Roberts, G. O. & Sahu, S. K. Updating schemes, correlation structure, blocking and parametrization for the Gibbs sampler. J. R. Soc. Ser. B 59, 291–317 (1997).

    Article  Google Scholar 

  30. 30.

    Endo, M. et al. Electric field effects on thickness-dependent magnetic anisotropy of sputtered MgO/CoFeB/Ta structures. Appl. Phys. Lett. 96, 212503 (2010).

    ADS  Article  Google Scholar 

  31. 31.

    Enobio, E. C. I., Bersweiler, M., Sato, H., Fukami, S. & Ohno, H. Evaluation of energy barrier of CoFeB/MgO magnetic tunnel junctions with perpendicular easy axis using retention time measurement. Jpn. J. Appl. Phys. 57, 04FN08 (2018).

    Article  Google Scholar 

  32. 32.

    Lucas, A. Ising formulations of many NP problems. Front. Phys. 2, 5 (2014).

    Article  Google Scholar 

  33. 33.

    Xu, N. et al. Quantum factorization of 143 on a dipolar-coupling nuclear magnetic resonance system. Phys. Rev. Lett. 108, 130501 (2012).

    ADS  Article  Google Scholar 

  34. 34.

    Burges, C. J. C. Factoring As Optimization. Report No. MSR-TR-2002-83 (Microsoft Research Lab, 2002).

  35. 35.

    Henelius, P. & Girvin, S. A statistical mechanics approach to the factorization problem. Preprint at (2011).

  36. 36.

    Dridi, R. & Alghassi, H. Prime factorization using quantum annealing and computational algebraic geometry. Sci. Rep. 7, 43048 (2017); erratum 7, 44963 (2017).

    CAS  ADS  Article  Google Scholar 

  37. 37.

    Pervaiz, A. Z., Sutton, B. M., Ghantasala, L. A. & Camsari, K. Y. Weighted p-bits for FPGA implementation of probabilistic circuits. IEEE Trans. Neural Netw. Learn. Syst. 30, 1920–1926 (2018).

    Article  Google Scholar 

  38. 38.

    Zand, R., Camsari, K. Y., Datta, S. & Demara, R. F. Composable probabilistic inference networks using MRAM-based stochastic neurons. ACM J. Emerg. Technol. 15, 17 (2019).

    Google Scholar 

  39. 39.

    Mathew, S. K. et al. μRNG: a 300–950 mV, 323 Gbps/W all-digital full-entropy true random number generator in 14 nm FinFET CMOS. IEEE J. Solid-State Circuits 51, 1695–1704 (2016).

    ADS  Article  Google Scholar 

  40. 40.

    Zhao, W. & Yu, C. New generation of predictive technology model for sub-45 nm early design exploration. IEEE Trans. Electron Dev. 53, 2816–2823 (2006).

    CAS  ADS  Article  Google Scholar 

  41. 41.

    Datta, D. et al. Voltage asymmetry of spin-transfer torques. IEEE Trans. Nanotechnol. 11, 261–272 (2012).

    ADS  Article  Google Scholar 

  42. 42.

    Park, C. et al. Low RA magnetic junction arrays in conjunction with low switching current and high breakdown voltage for STT-MRAM at 10 nm and beyond. In 2018 IEEE Symposium on VLSI Technology 185–186 (IEEE, 2018).

Download references


We thank H. Sato, M. Bersweiler, T. Hirata, H. Iwanuma, K. Goto, C. Igarashi, I. Morita, R. Ono and M. Musya for technical support. We thank O. Hassan and S. Chowdhury for their help with the Methods sections comparing CMOS alternatives and quantum computing, respectively. A portion of this work was supported by ImPACT Program of CSTI, JSPS KAKENHI grant numbers 17H06093 and 19J12206, Cooperative Research Projects of RIEC, and ASCENT, one of six centres in JUMP, an SRC program sponsored by DARPA. W.A.B. acknowledges JST-OPERA.

Author information




S.F., K.Y.C., H.O. and S.D. planned the study. W.A.B. and S.F. prepared and characterized the MTJ devices. A.Z.P., K.Y.C. and S.D. developed the algorithm and experimental setup. A.Z.P. and K.Y.C. conducted factorization experiment and collected results. All authors contributed to the writing of the manuscript. All authors discussed the results.

Corresponding authors

Correspondence to Shunsuke Fukami or Kerem Y. Camsari.

Ethics declarations

Competing interests

The authors declare no competing interests.

Additional information

Publisher’s note Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Peer review information Nature thanks Kyung-Jin Lee, Dmitri Nikonov and the other, anonymous, reviewer(s) for their contribution to the peer review of this work.

Extended data figures and tables

Extended Data Fig. 1 p-bit construction.

a, A diagram of the ideal response of a stochastic MTJ as used in this work and the parameters used to characterize the MTJ. b, The measured drain current IDS as a function of VIN of a 2N7000 NMOS transistor used in our p-bit demonstration.

Extended Data Fig. 2 Block diagram of an asynchronous p-circuit.

A microcontroller reads the outputs voltages VOUT of all p-bits and computes the synaptic weights, which are then converted to the analogue input voltages VIN for each p-bit, using a DAC that communicates with the microcontroller.

Extended Data Fig. 3 Experimentally observed time snapshots.

ac, Experimentally observed time snapshots of the four p-bits used to factorize 35 (a, b). These snapshots are combined to create x and y (c), which fluctuate between 7 × 5 and 5 × 7.

Extended Data Fig. 4 Calibrating the experimental system.

Calibrating a reference state using synaptic weights. a, The experimentally observed time-averaged output of six p-bits versus applied inputs (which are misaligned). b, The output is corrected using synaptic biases leading to the reference state shown. Each data point in a and b are taken as an average over a time window of 15 s with 2,000 or more sampling points.

Extended Data Fig. 5 Comparison between the MTJ- and CMOS-based energy per random bit and cell area.

a, An MTJ-based p-bit simulated with the stochastic LLG model (s-LLG, dotted box). b, A 32-bit LFSR. The look-up table (LUT) and the digital comparator of the CMOS p-bit are not included in the comparison. INV, inverter; DFF, D-type flip flop.

Extended Data Fig. 6 Computing with p-bits versus AQC.

a, A representation of how an array of six Ising spins in a qubit array can be replicated with an array of p-bits. b, A comparison of both approaches for factoring 161 = 23 × 7. For a system of six Ising spins, there are 64 states. At higher magnetic fields (ΓX = 0.5) both systems are ‘disordered’ and the correct peak is not pronounced. At lower magnetic field (ΓX = 0.1) the correct peaks emerge with a high probability. The states (yixi) have been converted to binary variables si from the bipolar variables mi by defining si = (mi + 1)/2 and the states [y2 y1 x4 x3 x2 x1] are expressed in decimal on the x axis.

Extended Data Fig. 7 Simulation versus experiment.

ad, We simulate the ideal experiment when all p-bits are perfectly aligned (a), using an idealized p-bit model which produces the results shown in c. Each data point is taken as an average over a time window of 15 s with 2,000 or more sampling points. The presence of device variations leads to a non-ideal system of misaligned p-bits (b), which is corrected using synaptic biases, allowing the experiment to approach the correct results (d). The time-averaged statistics in b are collected over a time window of 15 s with 2,000 or more sampling points.

Extended Data Fig. 8 Simulation of variations of τN.

The τ of six p-bits is varied from a minimum value of τΝ to a maximum value of 4τΝ. Variations between p-bits do not affect system operation providing that τinter = τN.

Extended Data Fig. 9 Simulations of variations of MTJ parameters.

ac, The variation of MTJ parameters results in the misalignment of the average responses of the p-bits (a), which results in a biased reference state (b). When such a system is used for factorizing 161 the observed results are incorrect (c). df, The shifts in the average responses are corrected using synaptic biases (d), which correct the reference state (e) and factorization results (f).

Extended Data Fig. 10 Invertible AND gate operation.

a, b, Time snapshot for the direct mode of operation when the inputs x2 and x1 have both been pinned to 1 (a); the statistics collected for 60 s (b). c, d, Time snapshot for the p-bits operating the AND gate in inverted mode when the output y1 is pinned to 0 (c); the statistics collected for 60 s (d). e, f, Time snapshot for the p-bits operating the AND gate in floating mode (e); the statistics collected for 60 s (f). All statistics shown are collected over a time window of 60 s with 2,000 or more sampling points.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Borders, W.A., Pervaiz, A.Z., Fukami, S. et al. Integer factorization using stochastic magnetic tunnel junctions. Nature 573, 390–393 (2019).

Download citation

Further reading


By submitting a comment you agree to abide by our Terms and Community Guidelines. If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.


Quick links

Nature Briefing

Sign up for the Nature Briefing newsletter — what matters in science, free to your inbox daily.

Get the most important science stories of the day, free in your inbox. Sign up for Nature Briefing