<jupyter_start><jupyter_text>Task Three: Quantum Gates and Circuits<jupyter_code>from qiskit import *
from qiskit.visualization import plot_bloch_multivector<jupyter_output><empty_output><jupyter_text>Pauli Matrices \begin{align}I = \begin{pmatrix} 1&0 \\ 0&1 \end{pmatrix}, \quadX = \begin{pmatrix} 0&1 \\ 1&0 \end{pmatrix}, \quadY = \begin{pmatrix} 0&i \\ -i&0 \end{pmatrix}, \quadZ = \begin{pmatrix} 1&0 \\ 0&-1 \end{pmatrix} \quad\end{align}  X-gate The X-gate is represented by the Pauli-X matrix:$$ X = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix} = |0\rangle\langle1| + |1\rangle\langle0| $$Effect a gate has on a qubit: $$ X|0\rangle = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}\begin{bmatrix} 1 \\ 0 \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \end{bmatrix} = |1\rangle$$<jupyter_code># Let's do an X-gate on a |0> qubit
qc=QuantumCircuit(1)
qc.x(0)
qc.draw('mpl')#mpl stands for the matplotlib argument
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc, backend).result().get_statevector() 
print(out)<jupyter_output>[0.+0.j 1.+0.j]<jupyter_text>Z & Y-Gate $$ Y = \begin{bmatrix} 0 & -i \\ i & 0 \end{bmatrix} \quad\quad\quad\quad Z = \begin{bmatrix} 1 & 0 \\ 0 & -1 \end{bmatrix} $$$$ Y = -i|0\rangle\langle1| + i|1\rangle\langle0| \quad\quad Z = |0\rangle\langle0| - |1\rangle\langle1| $$<jupyter_code># Do Y-gate on qubit 0
qc.y(0)
# Do Z-gate on qubit 0
qc.z(0)

qc.draw('mpl')<jupyter_output><empty_output><jupyter_text>Hadamard Gate $$ H = \tfrac{1}{\sqrt{2}}\begin{bmatrix} 1 & 1 \\ 1 & -1 \end{bmatrix} $$We can see that this performs the transformations below:$$ H|0\rangle = |+\rangle $$$$ H|1\rangle = |-\rangle $$<jupyter_code>#create circuit with three qubit
qc =  QuantumCircuit(3)
# Apply H-gate to each qubit:
for qubit in range(3):
    qc.h(qubit)
# See the circuit:
qc.draw('mpl')<jupyter_output><empty_output><jupyter_text>Identity Gate $$I = \begin{bmatrix} 1 & 0 \\ 0 & 1\end{bmatrix}$$$$ I = XX $$<jupyter_code>qc.i(0)

qc.draw('mpl')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18829891838741397, 'fraction_numerical': 0.035398230088495575, 'mean_word_length': 4.470430107526882, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '458100', 'license': 'MIT', 'n_tokens_mistral': 889, 'n_tokens_neox': 796, 'n_words': 191, 'path': 'Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 3/Task 3 - Quantum Gates and Circuits.ipynb', 'repo_name': 'bobsub218/exercise-qubit', 'size': '2034'}