<jupyter_start><jupyter_text>prepared by <NAME> (QLatvia) and <NAME> (QTurkey)                 This cell contains some macros. If there is a problem with displaying mathematical formulas, please run this cell to load these macros. $ \newcommand{\bra}[1]{\langle 1|} $$ \newcommand{\ket}[1]{|1\rangle} $$ \newcommand{\braket}[2]{\langle 1|2\rangle} $$ \newcommand{\dot}[2]{ 1 \cdot 2} $$ \newcommand{\biginner}[2]{\left\langle 1,2\right\rangle} $$ \newcommand{\mymatrix}[2]{\left( \begin{array}{1} 2\end{array} \right)} $$ \newcommand{\myvector}[1]{\mymatrix{c}{1}} $$ \newcommand{\myrvector}[1]{\mymatrix{r}{1}} $$ \newcommand{\mypar}[1]{\left( 1 \right)} $$ \newcommand{\mybigpar}[1]{ \Big( 1 \Big)} $$ \newcommand{\sqrttwo}{\frac{1}{\sqrt{2}}} $$ \newcommand{\dsqrttwo}{\dfrac{1}{\sqrt{2}}} $$ \newcommand{\onehalf}{\frac{1}{2}} $$ \newcommand{\donehalf}{\dfrac{1}{2}} $$ \newcommand{\hadamard}{ \mymatrix{rr}{ \sqrttwo & \sqrttwo \\ \sqrttwo & -\sqrttwo }} $$ \newcommand{\vzero}{\myvector{1\\0}} $$ \newcommand{\vone}{\myvector{0\\1}} $$ \newcommand{\stateplus}{\myvector{ \sqrttwo \\  \sqrttwo } } $$ \newcommand{\stateminus}{ \myrvector{ \sqrttwo \\ -\sqrttwo } } $$ \newcommand{\myarray}[2]{ \begin{array}{1}2\end{array}} $$ \newcommand{\X}{ \mymatrix{cc}{0 & 1 \\ 1 & 0}  } $$ \newcommand{\Z}{ \mymatrix{rr}{1 & 0 \\ 0 & -1}  } $$ \newcommand{\Htwo}{ \mymatrix{rrrr}{ \frac{1}{2} & \frac{1}{2} & \frac{1}{2} & \frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & \frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} \\ \frac{1}{2} & -\frac{1}{2} & -\frac{1}{2} & \frac{1}{2} } } $$ \newcommand{\CNOT}{ \mymatrix{cccc}{1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0} } $$ \newcommand{\norm}[1]{ \left\lVert 1 \right\rVert } $$ \newcommand{\pstate}[1]{ \lceil \mspace{-1mu} 1 \mspace{-1.5mu} \rfloor } $ Phase Kickback In this notebook, we will look at an interesting phenomenon in quantum systems. Before going into the details, we should make some definitions. $ v $ is an **eigenvector** for matrix $ A  $ with **eigenvalue** $ \lambda $ if $Av = {\lambda}v$. We will talk about eigenvalues of quantum operator in more detail in the upcoming notebooks. Now consider the quantum state $\ket{-}=\frac{1}{\sqrt{2}}\ket{0}-\frac{1}{\sqrt{2}}\ket{1}$. Let's check the effect of applying NOT operator to the quantum state $\ket{-}$. \begin{align*}\ket{-} \xrightarrow{NOT} &=  \frac{1}{\sqrt{2}} \ket{1} - \frac{1}{\sqrt{2}} \ket{0}= \text{-} \left(\frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}\right)= \text{-}\ket{-}\end{align*} So we see that $NOT\ket{-} = \text{-}\ket{-}$. $\ket{-}$ is an eigenstate of the $NOT$ operator with eigenvalue -1.  Task 1What is the other eigenstate of the $NOT$ operator? What is the corresponding eigenvalue? click for our solution ----- Now we will observe another interesting quantum effect here. Suppose that the second qubit is in state $\ket{-}$. When the first qubit is in state $\ket{0}$, then $CNOT$ does not have any effect.$\ket{0}\ket{-} \xrightarrow{CNOT} \ket{0}\ket{-}$ When the first qubit is in state $\ket{1}$, then we have the following state.$\ket{1}\ket{-} \xrightarrow{CNOT} \text{-}\ket{1}\ket{-}$     Now suppose that first qubit is in state $\alpha \ket{0} + \beta \ket{1}$ and the second qubit is in state $\ket{-}$, that is we have the following quantum state $\alpha \ket{0}\ket{-} + \beta \ket{1}\ket{-}$.$\alpha \ket{0}\ket{-} + \beta \ket{1}\ket{-} \xrightarrow{CNOT} \alpha \ket{0}\ket{-} ~-~ \beta \ket{1}\ket{-} = (\alpha \ket{0} - \beta \ket{1})\ket{-}$ The state of the first qubit after the $CNOT$ is $\alpha \ket{0} - \beta \ket{1}$The amplitude of $ \ket{1} $ of the first qubit changes sign after the $CNOT$ operator.    This is called phase kickback._The eigenvalue is kicked back to the control register._   Task 2Create a quantum circuit with a qreg register of two qubits.Set the state of qreg[0] to $ \ket{1} $.Set the state of qreg[1] to $ \ket{0} $.Apply Hadamard to both qubits.Apply $CNOT$ operator, where the controller qubit is qreg[1] and the target qubit is qreg[0].Apply Hadamard to both qubits.Measure the outcomes.We start in quantum state $ \ket{01} $ (Keep in mind the Qiskit order). What is the outcome?<jupyter_code># import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer


#
# your code is here
#

# execute the circuit 100 times in the local simulator
job = execute(mycircuit1,Aer.get_backend('qasm_simulator'),shots=100)
counts = job.result().get_counts(mycircuit1)

# print the reverse of the outcome
for outcome in counts:
    print("We start in quantum state 01, and",outcome,"is observed",counts[outcome],"times")<jupyter_output><empty_output><jupyter_text>click for our solution  Analysis We start in state $\ket{01}$.The quantum state of the first qubit before $CNOT$:$$    \ket{0} \xrightarrow{H} \frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1}.$$The quantum state of the second qubit before $CNOT$:$$    \ket{1} \xrightarrow{H} \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}.$$ The quantum state of the composite system:$$   \mypar{ \frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1} }    \otimes   \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }$$ $CNOT$ affects when the first qubit has the value 1.Let's rewrite the composite state as below to explicitly represent the effect of CNOT.$$     \frac{1}{\sqrt{2}} \ket{0} \otimes \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }     +     \frac{1}{\sqrt{2}} \ket{1} \otimes \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }$$ $CNOT$ flips the state of the second qubit.After $CNOT$, we have:$$     \frac{1}{\sqrt{2}} \ket{0} \otimes \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }     +     \frac{1}{\sqrt{2}} \ket{1} \otimes \mypar{ \frac{1}{\sqrt{2}} \ket{1} - \frac{1}{\sqrt{2}} \ket{0}  }$$Remark that $\ket{0}$ and $ \ket{1} $ are swapped in the second qubit.Thus the last equation can be equivalently written as follows:$$     \frac{1}{\sqrt{2}} \ket{0} \otimes \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }     -     \frac{1}{\sqrt{2}} \ket{1} \otimes \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }$$It is easy to see from the last expression, that the quantum states of the qubits are separable (no correlation):$$   \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1} }    \otimes   \mypar{ \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1}  }$$Note that the sign of $ \ket{1} $ in the first qubit is flipped. If we apply Hadamard to each qubit, both qubits evolve to state $ \ket{1} $.Hence, the final state is $ \ket{11} $.  Task 3 Create a circuit with 7 qubits.Set the states of the qubits 1-6 to $ \ket{0} $.Set the state of the qubit 0 to $ \ket{1} $.Apply Hadamard operators to all qubits.Apply $CNOT$ operator (1,0) Apply $CNOT$ operator (4,0)Apply $CNOT$ operator (5,0)Apply Hadamard operators to all qubits.Measure all qubits. For each $CNOT$ operator, do we have a phase-kickback effect?<jupyter_code># import all necessary objects and methods for quantum circuits
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit, execute, Aer

#
# your code is here
#

# execute the circuit 100 times in the local simulator

job = execute(mycircuit2,Aer.get_backend('qasm_simulator'),shots=100)
counts = job.result().get_counts(mycircuit2)

# print the outcome
for outcome in counts:
    for i in range(len(outcome)):
        print("the final value of the qubit nr.",(n-i-1),"is",outcome[i])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20319397559075564, 'fraction_numerical': 0.03674370293430278, 'mean_word_length': 3.922044728434505, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '430636', 'license': 'Apache-2.0', 'n_tokens_mistral': 2803, 'n_tokens_neox': 2631, 'n_words': 830, 'path': 'nickel/A02_Phase_Kickback.ipynb', 'repo_name': 'asif-saad/qNickel', 'size': '7720'}