Final Project for Phys 642: An Introduction to Quantum Information and Quantum Computing Fall 2013...

Post on 20-Jan-2018

213 views 0 download

description

Shor’s Algorithm (as broken down by Nielsen & Chuang)

transcript

Final Projectfor

Phys 642: An Introduction to Quantum Information and Quantum Computing

Fall 2013

Implementing a Computer Simulation of Shor’s Quantum Factoring Algorithm

Mark FoersterDecember 9, 2013

Overview

• Implemented from scratch in C++, as a partly numeric and partly symbolic algebra system

• Followed Box 5.4 on page 235 of Nielsen & Chuang for guidance & verification steps: “Keep the train on the rails”

• Considerable further development and re-implementation needed to conform to original ambitions

Shor’s Algorithm(as broken down by Nielsen & Chuang)

• Two registers of qubits, one for modular exponentiation work, another for the exponent itself.

• Modular exponentiation work register is L qubits wide, exponent register is qubits wide. Epsilon is error probability, use more qubits for smaller epsilon.

• Set both register’s qubits to all |0>.• Perform Hadamard transformations on all qubits of the exponent

register.• Perform a controlled unitary transform of modular exponentiation

upon the work register:– Fixed values of x and N are set before usage– k comes from the exponent register and is the control– An entangled state of size is created by the transform

Shor’s Algorithm Continued(Nielsen & Chuang)

• The work register undergoes implicit measurement (section 4.4, page 187) by virtue of no further operations. The state collapses to in size around one of the values.

• The exponent register is subjected to a quantum inverse Fourier transform. The corresponding sized state is rearranged to the inverse transformation.

• The transformed exponent register is measured, supplying a candidate number for further processing (“order of x”) with which to find a pair of factors for N.

Implementation Pieces• A class for representing a complex number with

magnitude limited to a maximum of one– Magnitude squared stored as separate numerator and

denominator.– Phase angle stored as separate numerator and denominator,

represents a fraction of 2π.– The above are features for printed expression for easy

recognition. Better than reading cryptic floating point numbers all the time.

– Floating point numbers for radius, theta, real and imaginary also stored as numeric backup for “hairy” calculation results (adding numbers that have different phases).

Implementation Pieces

• A QuBit class that contains two of the complex numbers.

• An entangled state class (QuTangle) that may contain an unlimited quantity of the complex numbers.

• A Hadamard gate class.• A Rotation gate class.• A quantum Fourier transform class.• A driving program to use them all.

Matching the Simulation Steps to Box 5.4’s Narrative

• Box 5.4 on page 235 of Nielsen & Chuang applies the algorithm to finding the finding the prime factors for 15.

• The work register is L = 4 qubits wide.• Epsilon is set at , so the exponent register is t = 11 qubits wide.• Setting initial qubit states and creating Hadamard-gated qubits

for the exponent register was trivial.• Created entangled state of H-gated exponent register qubits ( =

2048 elements long).• The first major step was to create the state that results from

the controlled modular exponentiation transform. Box 5.4 uses x = 7, so the transform is .

Matching the Simulation Steps to Box 5.4’s Narrative

• This simulation lacked a quantum circuit to perform the controlled modular exponentiation, so a more traditional numeric calculation approach was required.

• Computing with k values from 0 to 2047 proved infeasible with both double and long double numeric types: insufficient precision to keep the lowest-end mantissa bits covering the range to .– double limit is .– long double limit is .

• Fortunately, cycles through only four values: 1, 7, 4, 13, so that could be “canned” for the construction of the entangled state of the exponent and work registers.

• The state construction was laborious, requiring tensor multiplying the Hadamard transformed exponent register state for each k value with each matching work register value, and adding the result to a running sum state. The multiplied and sum states were elements long.

• It was an implementation of expression (5.62) in box 5.4.

Matching the Simulation Steps to Box 5.4’s Narrative

• The printed-out sum result was:

sqrt(1/2048)|1> + sqrt(1/2048)|23> + sqrt(1/2048)|36> + sqrt(1/2048)|61> + …… + sqrt(1/2048)|32705> + sqrt(1/2048)|32727> + sqrt(1/2048)|32740> + sqrt(1/2048)|32765>

…which corresponds to the state result listed under (5.62). One must multiply the k basis numbers in the text by 16 and add the basis numbers to them to get the basis numbers in the output above.

Matching the Simulation Steps to Box 5.4’s Narrative

• The next step was to perform the implicit measurement of the work register, selecting one out of the four modular exponentiation states to survive. One may either generate a pseudo-random number for selection or make a fixed choice. The text’s suggestion of 4 was followed for the latter. Printed, it is:

sqrt(1/512)|2> + sqrt(1/512)|6> + sqrt(1/512)|10> + sqrt(1/512)|14> + sqrt(1/512)|18> + …… + sqrt(1/512)|2034> + sqrt(1/512)|2038> + sqrt(1/512)|2042> + sqrt(1/512)|2046>

…this matches perfectly to the example quoted in the box for choosing 4.

Matching the Simulation Steps to Box 5.4’s Narrative

• The next step, of submitting the state to inverse Fourier transform, presented a problem of deriving the 11 qubit states that comprised the implicitly measured state.

• The necessity was that the Fourier transform is presented in the text in terms of a quantum circuit operating on qubits, rather than on an entangled state.

• For immediately practical reasons, the vector of qubits was worked out on paper outside of the simulation and submitted to an inverse Fourier transform to get to the next result.

• The worked-out qubit vector submitted to inverse transform is .• Figure 5.1 on page 219 shows the Fourier transform circuit that

was reversed for the inverse transform.

Matching the Simulation Steps to Box 5.4’s Narrative

• The result from inverse Fourier transform was very satisfying:

sqrt(1/4)|0> - sqrt(1/4)|512> + sqrt(1/4)|1024> - sqrt(1/4)|1536>

• This is exactly what is graphed for the probability distribution in box 5.4.

• The text’s further suggestion of choosing 1536 is available, and so the rest of the narrative may be satisfied to obtain 3 and 5 as factors of 15.

Further Directions

• The simulation code developed so far requires another revision of data structure and procedures to handle the requirements of quantum factoring in a natural and automatic fashion. The preceding was accomplished only by making several arbitrary external manipulations (hacks) of the data.

• A genuine quantum circuit for modular exponentiation needs to be worked out and employed for this simulation.

• Source code on Newton in /home/mfoerste/p642.

References

• Quantum Computation and Quantum Information 10th Anniversary Edition, Michael A. Nielsen and Isaac L. Chuang, Cambridge University Press, ISBN 978-1-107-00217-3.