Qiskit / qiskit-tutorials

A collection of Jupyter notebooks showing how to use the Qiskit SDK
Apache License 2.0
2.32k stars 1.29k forks source link

Question regarding QFT #361

Closed yangjy0826 closed 5 years ago

yangjy0826 commented 5 years ago

Description

Hi, I am now using QISKit to realize quantum fourier transform. I run the code provided by you in this link.

The input state is set to 000 by default. Is there any methods to change the input, for example to 001?

Could you please answer my question? Thank you so much!

Your Environment

muneerqu commented 5 years ago

Hi @yangjy0826

To change the initial qubit from 0 to 1 you can apply the X gate. In the 4th cell of the notebook the statement q = QuantumRegister(3) creates a quantum register with 3 qubits all in state 0. To change one qubit from 0 to 1 you can apply X to that particular qubit (using the qubit index) right after you create the circuit. The 4th cell becomes:

q = QuantumRegister(3)
c = ClassicalRegister(3)
qft3 = QuantumCircuit(q, c)

qft3.x(q[0]) # changes the first qubit (with index 0 ) q[0] to 1

input_state(qft3, q, 3)
qft(qft3, q, 3)
for i in range(3):
    qft3.measure(q[i], c[i])
print(qft3.qasm())

Note: The original tutorial "creates a state from which a QFT will return 1"

yangjy0826 commented 5 years ago

Oh I understand! That's smart. Thank you so much! But I still have a question: when you designed this package, why didn't you consider to design a function to set the initial input value?

jaygambetta commented 5 years ago

because that is really user code to make the state to have the Fourier transform applied to. I think this should be left to the user but the user can use the initializer method to make the state they want.

I am going to close this as its not really a bug but if you want more methods for making initial inputs please open another issue and we can discuss how.

yangjy0826 commented 5 years ago

OK, thanks!