200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 【源码】量子计算机模拟器

【源码】量子计算机模拟器

时间:2021-03-29 12:23:34

相关推荐

【源码】量子计算机模拟器

本代码实现了一个通用量子计算机的模拟器。模拟器允许用户在量子计算机实际部署之前模拟和调试量子算法。

The introduced code implements a simulator of a universal quantum computer. The simulator allows user to simulate and debug quantum algorithms before actual deployment on a quantum computer.

该模拟器基于通用量子计算机的David Deutsch数学模型,因此矩阵乘法和张量积(Kronecker)只是用于模拟的高级数学运算。模拟的结果是量子计算机状态的概率分布。

The simulator is based on David Deutsch mathematical model of a universal quantum computer, so matrix multiplication and tensor (Kronecker) products are only advanced mathematical operations used in simulation. The result of simulation is a probability distribution of a quantum computer states.

量子计算机中的量子算法实际上是一个字符串矩阵。矩阵的行表示算法的q位和列步进。矩阵的每个单元都包含一个量子门。

A quantum algorithm fed into the quantum computer is actually a string matrix. Rows of the matrix represents q-bits and columns steps of the algorithm. Each cell of the matrix contains a quantum gate.

模拟器实现了这些标准的单q位量子门:I, X, Y, Z, H, S, T, RX, RY, RZ, U1, U2, U3。S和T的逆,表示为DS和DT,也可用。门RX、RY、RZ、U1、U2和U3需要输入参数(请参阅函数getOperator以掌握门的实现)。模拟器允许使用上述任何门的一个q位控制版本。例如,控制X,实际上是CNOT门。Toffoli门(或CCNOT)也得到了实现(表示为TF)。

The simulator implements these standard single q-bit quantum gates: I, X, Y, Z, H, S, T, RX, RY, RZ, U1, U2, U3. Inverse of S and T, denoted DS and DT, are available too. Gates RX, RY, RZ, U1, U2 and U3 need parameters (see function getOperator to grasp implementation of the gates). The simulator allows to use one q-bit controlled version of any above discussed gate. For example, controlled X, which is actually CNOT gate. Toffoli gate (or CCNOT) is implemented as well (denoted TF).

模拟器的主要功能是量子计算机。这个函数有三个参数:量子算法、被测q位列表和初始状态。第一个参数包含量子算法本身的矩阵,第二个参数是包含测量的q位索引的行向量(索引从1开始),初始状态包含在算法运行开始时量子计算机状态的列向量。

A main function of the simulator is quantumComputer. This function has three parameters: a quantum algorithm, a list of measured q-bits and initial state. The first parameter contains matrix with quantum algorithm itself, second parameter is a row vector containing indexes of measured q-bits (index start with 1) and initial state contains column vector with the quantum computer state at the beginning of the algorithm run.

函数initializeRegisters和initializeRegistersInt用作初始状态的生成器。第一个函数将单个q位的列表(每个q位的状态q = a|0> + b|1>)转换为它们的张量积,从而准备量子计算机的初始状态。第二个函数将整数转换为量子计算机的初始状态。

Functions initializeRegisters and initializeRegistersInt serve as generator of an initial state. The first function transforms list of single q-bits, each in state q = a|0> + b|1>, to their tensor product and as a result prepares initial state of the quantum computer. Second function transforms integer to the quantum computer initial state.

函数getOperator实现上述所有的单q位门。用户可以在这个函数中添加自己的单q位量子门。

Function getOperator implements all above described single q-bit gates. User can add its own single q-bit quantum gate to this function.

函数getControlledOperator和toffoliAlgorithmPreprocess是辅助函数,用户可以忽略它们,因为它们只在函数quantumComputer内部调用。以上讨论的函数有助于理解如何使用它们。键入命令例如“help quantumComputer”获取帮助信息。

Functions getControlledOperator and toffoliAlgorithmPreprocess are auxiliary functions and user can ignore them as they are called only inside the function quantumComputer.

All above discussed function have help to understand how to use them. Type for example “help quantumComputer”.

To better understand how to write quantum algorithm for the simulator, files with extension *.mat contain these algorithms:

a) bellState.mat – Preparation of Bell state (|00> + |11>)/sqrt(2). After loading the *.mat file, type this statement: “quantumComputer(qAlgorithm)”.

b) bitSwap.mat – Swap of two q-bits content.

c) Toffoli.mat – Implementation of Toffoli gate with CNOT and single q-bit gates.

d) grover_4bit_1iter.mat – First iteration of the Grover algorithm searching for solution of logical equation abc*not(d) = 1, whete a,b,c and d are logical variables and * denotes AND operation. After loading the *.mat file, type this statement:

“quantumComputer(qAlgorithm, [1 2 4 5])”.

e) Files grover_4bit_2iter.mat and grover_4bit_3iter.mat contain two and three (i.e. optimal number) iterations of the Grover algorithm, respectively to demonstrate how increasing number of iteration increase probability of solution of abc*not(d) = 1. After loading the *.mat file, type this statement: “quantumComputer(qAlgorithm, [1 2 4 5])”.

f) statePrep.mat – Preparation of 3-qbit register with below shown distribution of states. The algorithm is based on article “Transformation of quantum states using uniformly controlled rotations” by Mottonen, Vartiainen, Bergholm and Salomaa. After loading the *.mat file, type this statement: “quantumComputer(qAlgorithm)”.

a. p(|000>) = 3 %

b. p(|001>) = 5 %

c. p(|010>) = 7 %

d. p(|011>) = 10 %

e. p(|100>) = 13 %

f. p(|101>) = 15 %

g. p(|110>) = 17 %

h. p(|111>) = 30 %

更多精彩文章请关注公众号:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。