# Task Three: Quantum Gates and Circuits


```python
from qiskit import *
from qiskit.visualization import plot_bloch_multivector
```

## Pauli Matrices

\begin{align}
I = \begin{pmatrix} 1&0 \\ 0&1 \end{pmatrix}, \quad
X = \begin{pmatrix} 0&1 \\ 1&0 \end{pmatrix}, \quad
Y = \begin{pmatrix} 0&i \\ -i&0 \end{pmatrix}, \quad
Z = \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$$



```python
# 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
```


```python
# Let's see the result
backend = Aer.get_backend('statevector_simulator')
out = execute(qc, backend).result().get_statevector() 
print(out) 
```

    [0.+0.j 1.+0.j]


## 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| $$



```python
# Do Y-gate on qubit 0
qc.y(0)
# Do Z-gate on qubit 0
qc.z(0)

qc.draw('mpl')
```

## 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 $$


```python
#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')
```

## Identity Gate


$$
I = \begin{bmatrix} 1 & 0 \\ 0 & 1\end{bmatrix}
$$



$$ I = XX $$


```python
qc.i(0)

qc.draw('mpl')
```

 **Other Gates: S-gate , T-gate, U-gate**

# That's all for Task 3
## Thank You!

Where can you find me?

LinkedIn : https://www.linkedin.com/in/arya--shah/

Twitter : https://twitter.com/aryashah2k

Github : https://github.com/aryashah2k

If you Like My Work, Follow me/ Connect with me on these platforms.
Show some Love ❤️ Sponsor me on Github!


```python

```

f21e707097ed88f3b52fd3bce07b1d3b12d40d34
ipynb
Jupyter Notebook
Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 3/Task 3 - Quantum Gates and Circuits.ipynb
bobsub218/exercise-qubit
32e1b851f65b98dcdf90ceaca1bd52ac6553e63a
MIT
2020-11-13T07:11:20.000Z
2022-03-06T02:27:45.000Z
Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 3/Task 3 - Quantum Gates and Circuits.ipynb
bobsub218/Exercise-qubit
32e1b851f65b98dcdf90ceaca1bd52ac6553e63a
MIT
2020-12-25T17:25:14.000Z
2021-04-26T07:56:06.000Z
Guided Project - Programming a Quantum Computer with Qiskit - IBM SDK/Task 3/Task 3 - Quantum Gates and Circuits.ipynb
trial1user/Quantum-Computing-Collection-Of-Resources
6953854769adef05e705fa315017c459e5e581ce
MIT
2020-11-13T08:55:28.000Z
2022-03-14T21:16:07.000Z
Qwen/Qwen-72B
1. YES
2. YES