HW 7 (Practice) - Quantum Algorithms 2

1: QFT

Question

Consider the sequence of steps shown in Section 4 of the qiskit page on the Quantum
Fourier Transform: https://github.com/qiskit-community/qiskit-textbook/blob/main/content/ch-algorithms/quantum-fourier-transform.ipynb
a. Follow these steps explicitly for a 2-qubit system.
b. A two-qubit system can encode the numbers 0 to 3. For each of these find its Fourier
transform.
c. Is your result from the previous part consistent with the Bloch sphere animation at the
end of section 4 of the QFT qiskit textbook page? Explain. Since we only have three
qubits, which of the four spheres correspond to our three spheres (e.g. qubit 0 to 2 or
qubit 1 to 3, etc.).

For a 2-qubit system we can do the steps explicitly:

QFT2|x1x2⟩=122∑y=022−1ω4xy|y⟩=12∑y=03exp⁡(2πixy4)|y⟩=12(e2πix4⋅0|00⟩+e2πix4⋅1|01⟩+e2πix4⋅2|10⟩+e2πix4⋅3|11⟩)=12(exp⁡(2πix⋅[021+022])|00⟩+exp⁡(2πix⋅[021+122]|01⟩)+exp⁡(2πix⋅[121+022]|10⟩)+exp⁡(2πix⋅[121+122]|11⟩))=12(exp⁡(2πix021)exp⁡(2πix022)|00⟩)+12(exp⁡(2πix021)exp⁡(2πix122)|01⟩)+12(exp⁡(2πix121)exp⁡(2πix022)|10⟩)+12(exp⁡(2πix121)exp⁡(2πix122)|11⟩)=12exp⁡(2πix021)|0⟩⊗(exp⁡(2πix022)|0⟩+exp⁡(2πix122)|1⟩)+12exp⁡(2πix121)|1⟩⊗(exp⁡(2πix022)|0⟩+exp⁡(2πix122)|1⟩)=12(|0⟩+exp⁡(2πix121)|1⟩)⊗(|0⟩+exp⁡(2πix122)|1⟩)

Encoding Numbers

Using our equation above, we can get our QFT2 for all the numbers:

Ket to Encode |x⟩ QFT2|x⟩
|00⟩ QFT2|x⟩=12(|0⟩+|1⟩)⊗(|0⟩+|1⟩)=12(|00⟩+|01⟩+|10⟩+|11⟩)
|01⟩ QFT2|x⟩=12(|0⟩−|1⟩)⊗(|0⟩+i|1⟩)=12(|00⟩+i|01⟩−|10⟩−i|11⟩)
|10⟩ QFT2|x⟩=12(|0⟩+|1⟩)⊗(|0⟩−|1⟩)=12(|00⟩−|01⟩+|10⟩−|11⟩)
|11⟩ QFT2|x⟩=12(|0⟩−|1⟩)⊗(|0⟩−i|1⟩)=12(|00⟩−i|01⟩−|10⟩+i|11⟩)
Notice that we can construct the unitary matrix in this case:
UQFT=12[11111i−1−i1−11−11−i−1i]⇔UIQFT=UQFT†=12[11111−i−1i1−11−11i−1−i]

Intuition

Consider the following image:

fourierbasis-counting.gif

In this case since we have only two qubits, then qubit 3 in the gif above corresponds to the qubit 1 (the most significant qubit) in our 2-qubit system. Qubit 1 in our 2-qubit system corresponds to qubit 2 in the animation above.

This is because, if you look at the table prior, when the most significant qubit is changing between |x⟩ states, it flips negative sign, which is exemplified in the animation. Similarly, the least significant bit changes the phase by π2 radians, just like we see in the Qubit 2 animation above.

2: QPE

Question

Consider the sequence of steps shown in Section 1.2 of the qiskit page on the Quantum
Phase Estimation: https://github.com/qiskit-community/qiskit-textbook/blob/main/content/ch-algorithms/quantum-phase-estimation.ipynb
a. Follow these steps explicitly for a system with two counting qubits and one ancilla qubit.
b. Build this circuit in IBMQ. According to the resulting probability distribution, what is
θ?
Pasted image 20240612091134.png
Explain.

A 2-qubit System

Consider running QPE for 2-qubits in our system (and still one ancilla qubit). Namely we want to find eigenvalues for the transformation U that's arbitrary. Then:

|ψ0⟩=|0⟩⊗2|ψ⟩

Where it's presumed that |ψ⟩ is an eigenvector of unitary U. Applying the Hadamard Layer:

|ψ1⟩=H⊗2|0⟩⊗2|ψ⟩=12(|0⟩+|1⟩)⊗(|0⟩+|1⟩)⊗|ψ⟩=12(|00⟩+|01⟩+|10⟩+|11⟩)|ψ⟩

Applying the unitary operations:

|ψ2⟩=Uq12|ψ1⟩=12(|00⟩+|01⟩+U2|10⟩+U2|11⟩)|ψ⟩|ψ3⟩=Uq01|ψ2⟩=12(|00⟩+U|01⟩+U2|10⟩+U3|11⟩)|ψ⟩

All the U's only apply to the rightmost state by the way. So then:

|ψ3⟩=12(|00⟩|ψ⟩+|01⟩U|ψ⟩+|10⟩U2|ψ⟩+|11⟩U3|11⟩)

For each U|ψ⟩ we are given that U|ψ⟩=e2πiθ|ψ⟩ where 0≤θ≤1 then:

|ψ3⟩=12(|00⟩+e2πiθ|01⟩+e2πi2θ|10⟩+e2πi3θ|11⟩)|ψ⟩

Recall from earlier in our table that θ can only be one of |00⟩,...,|11⟩ in resolution, so use the table for each gate going backwards. Namely we know:

UQFT†=12[11111−i−1i1−11−11i−1−i]

Giving:

|ψ4⟩=14((|00⟩+|01⟩+|10⟩+|11⟩)+e2πiθ(|00⟩−i|01⟩−|10⟩+i|11⟩)+e2πi2θ(|00⟩−|01⟩+|10⟩−|11⟩)+e2πi3θ(|00⟩+i|01⟩−|10⟩−i|11⟩))|ψ⟩|ψ4⟩=14∑k=03exp⁡(2πikθ)|00⟩+14∑k=03exp⁡(2πikθ)exp⁡(2πi3πk2)|01⟩+14∑k=03exp⁡(2πikθ)exp⁡(2πiπk)|10⟩+14∑k=03exp⁡(2πikθ)exp⁡(2πik2)|11⟩=14∑x=03∑k=03exp⁡(−2πk4(x−2nθ))|x⟩⊗|ψ⟩

Thus we get a peak at ket x=2nθ as then the exponent becomes a 1.

An Example System

Using the example system above, we get the following probability distribution:

]>0000000100100011Computational basis states020406080100Probability (% of 1024 shots

Notice the spike in probability at x=1 in this case. That implies that 2nθ=1 so since n=2 then θ≈14 in this case.

3: Shor - period finding

Question

We want to carry out Shor's algorithm to factor 15.
a. Only one of the following options for a meet the criteria for a for use in Shor’s algorithm.
Which one is it? Circle the correct one. For all others, what is the reason they don’t
work?
i. a=5
ii. a=12
iii. a=13
b. Using a = (the correct result from part a.), follow the cycle (until you get back to |1>)
shown in the first paragraph of section 2 on this page (and in class).
https://github.com/qiskit-community/qiskit-textbook/blob/main/content/ch-algorithms/shor.ipynb
c. Based on your result from the previous part, what is the period of axmodN?

Which a to use?

a=5 will not meet the criteria. This is because a itself is a factor for N, so since we check if amodN≡0 before we run Shor's, we'll never need to run it in this case.

a=12 would not meet the criteria either. This is because a also just contains a factor for N. Namely, gcd(a,N)=gcd(12,15)=3 so then clearly 3 would be a factor for N and we wouldn't have to run Shor's Algorithm whatsoever.

a=13 doesn't have the issues we've talked about above since gcd(13,15)=1, so it's a valid candidate to use in the algorithm.

Using a=13

Using this, we can execute Shor's Algorithm by hand. We'll use:

U|y⟩≡|13ymod15⟩U1|1⟩=|13mod15⟩U2|1⟩≡|4mod15⟩U3|1⟩≡|7mod15⟩U4|1⟩≡|1mod15⟩

What does this show?

This shows that since the power U4 returns our ket back to ≡|1mod15⟩ then the power is our r period, so r=4.

4: Shor - factoring

Question

Shor – factoring. Running a period finding algorithm, you found that with a choice of a=13, the period of axmodN is r=4.
a. Follow step 3 from lecture slide 33 to find two candidates for prime factors of N.
b. If N=15, were any of our factors correct? If not, use step 4 from lecture slide 33 to find two new candidates for prime factors of 15. Now are any of your factors correct?

Finding p,q Candidates

Given that r=4 and a=13 then since r is even then we can use the candidates:

(ar2−1)=(1342−1)=168(ar2+1)=2+168=170

Clearly neither of these are prime (they are both even), so we need to find the gcd of N and ar2−1 with N and ar2+1 and N:

gcd(N,168)=3gcd(N,170)=5

These are the factors that we need for N, so then p=3 and q=5 such that N=p⋅q.