arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2506.08142quant-ph
收藏

如何从零开始编写量子电路模拟器:教程

How to Write a Simulator for Quantum Circuits from Scratch: A Tutorial

Michael J. McGuffin, Jean-Marc Robert, Kazuki Ikeda

AI总结:

本教程面向缺乏量子计算经验的程序员,讲解如何仅用约1000–2000行代码从零实现支持20余个量子比特的量子电路模拟器,并提供精简的 JavaScript 完整示例。

摘要:

本教程引导有能力的程序员从零开始构建一个量子电路模拟器,即使读者几乎没有量子计算的先前经验也可使用。量子电路的开源模拟器已经存在,但通过亲自编写模拟器可以获得更深入的理解。只需大约1000至2000行代码,就可以在个人计算机上、不使用任何特殊库的情况下,在多达20余个量子比特的电路上模拟 Hadamard、Pauli X、Y、Z、SWAP 以及其他量子逻辑门,并支持控制量子比特与反控制量子比特的任意组合。我们讲解模拟器的关键算法,特别是用于更新状态向量的逐量子比特乘法,以及用于求约化密度矩阵的偏迹。我们还讨论优化方法,以及如何计算量子比特相位、纯度和其他统计量。一个完整的 JavaScript 示例实现可在 https://github.com/MJMcGuffin/muqcs.js 获取;该实现还演示了如何计算 von Neumann 熵、concurrence(用于量化纠缠)和 magic,同时比其他流行软件包小得多,也更易于学习。

英文摘要:

This tutorial guides a competent programmer through the crafting of a quantum circuit simulator from scratch, even for readers with almost no prior experience in quantum computing. Open source simulators for quantum circuits already exist, but a deeper understanding is gained by writing ones own. With roughly 1000-2000 lines of code, one can simulate Hadamard, Pauli X, Y, Z, SWAP, and other quantum logic gates, with arbitrary combinations of control and anticontrol qubits, on circuits of up to 20+ qubits, with no special libraries, on a personal computer. We explain key algorithms for a simulator, in particular: qubit-wise multiplication for updating the state vector, and partial trace for finding a reduced density matrix. We also discuss optimizations, and how to compute qubit phase, purity, and other statistics. A complete example implementation in JavaScript is available at https://github.com/MJMcGuffin/muqcs.js , which also demonstrates how to compute von Neumann entropy, concurrence (to quantify entanglement), and magic, while remaining much smaller and easier to study than other popular software packages.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑