qiskit-community-tutorials icon indicating copy to clipboard operation
qiskit-community-tutorials copied to clipboard

Incorrect output for QFT

Open nighttrain7 opened this issue 6 years ago • 1 comments

This code was taken from here I changed some import statements because they were outdated and now the qft is returning 111 instead of 001 for inputs of all 0's. The output for qft3.quasm reads: OPENQASM 2.0; include "qelib1.inc"; qreg q0[3]; creg c0[3]; h q0[0]; u1(3.14159265358979) q0[0]; h q0[1]; u1(1.57079632679490) q0[1]; h q0[2]; u1(0.785398163397448) q0[2]; h q0[0]; cu1(1.57079632679490) q0[1],q0[0]; h q0[1]; cu1(0.785398163397448) q0[2],q0[0]; cu1(1.57079632679490) q0[2],q0[1]; h q0[2]; measure q0[0] -> c0[0]; measure q0[1] -> c0[1]; measure q0[2] -> c0[2]; As oppose to the original: OPENQASM 2.0; include "qelib1.inc"; qreg q0[3]; creg c0[3]; h q0[0]; u1(-3.14159265358979) q0[0]; h q0[1]; u1(-1.57079632679490) q0[1]; h q0[2]; u1(-0.785398163397448) q0[2]; h q0[0]; cu1(1.57079632679490) q0[1],q0[0]; h q0[1]; cu1(0.785398163397448) q0[2],q0[0]; cu1(1.57079632679490) q0[2],q0[1]; h q0[2]; measure q0[0] -> c0[0]; measure q0[1] -> c0[1]; measure q0[2] -> c0[2]; I believe the problem is here but I cant seem to solve it, if anyone could help that would be great, thanks!

`import math

# importing Qiskit
from qiskit import Aer, IBMQ
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute
from qiskit.providers.ibmq import least_busy

# useful additional packages 
from qiskit.tools.jupyter import *
from qiskit.tools.visualization import plot_histogram
provider = IBMQ.load_account()`


  # """n-qubit input state for QFT that produces output 1."""
`def input_state(circ, q, n):
    for j in range(n):
        circ.h(q[j])
        circ.u1(math.pi/float(2**(j)), q[j]).inverse()

def qft(circ, q, n):
  # """n-qubit QFT on q in circ."""
    for j in range(n):
        for k in range(j):
            circ.cu1(math.pi/float(2**(j-k)), q[j], q[k])
        circ.h(q[j])`
`q = QuantumRegister(3)
c = ClassicalRegister(3)
qft3 = QuantumCircuit(q, c)

input_state(qft3, q, 3)
qft(qft3, q, 3)
for i in range(3):
    qft3.measure(q[i], c[i])
print(qft3.qasm())`
`# run on local simulator
backend = Aer.get_backend("qasm_simulator")

simulate = execute(qft3, backend=backend, shots=1024).result()
simulate.get_counts()`
`%%qiskit_job_status

# Use the IBM Quantum Experience
backend = least_busy(IBMQ.backends(simulator=False))
shots = 1024

job_exp = execute(qft3, backend=backend, shots=shots)`
`results = job_exp.result()
plot_histogram(results.get_counts())`

nighttrain7 avatar Aug 19 '19 15:08 nighttrain7

this has moved to the Qiskit-community-tutorial

jaygambetta avatar Aug 20 '19 02:08 jaygambetta