pip install qiskit

!pip install pylatexenc

pip install qiskit-aer

pip install qiskit-ibm-runtime

pip install qiskit-ibm-provider

import numpy as np
from numpy import pi
# importing Qiskit
from qiskit import QuantumCircuit, transpile, Aer, IBMQ, assemble
from qiskit.visualization import plot_histogram, plot_bloch_multivector
from math import pi, sqrt
sim = Aer.get_backend('aer_simulator')

# Let's do an X-gate on a |0> qubit
qc = QuantumCircuit(1)
qc.x(0)
qc.draw('mpl')

# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an Y-gate on a |0> qubit
qc = QuantumCircuit(1)
#qc.x(0)
qc.y(0)
qc.draw('mpl')

# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an Y-gate on a |1> qubit
qc = QuantumCircuit(1)
#In qiskit, the qubit is initialised at |0>
qc.x(0) #prepares the |1> qubit
qc.y(0) #Then y-gate is applied on y
qc.draw('mpl')

# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an Y-gate on a |1> qubit
qc = QuantumCircuit(1)
#In qiskit, the qubit is initialised at |0>
qc.z(0) #z rotation on the |0> qubit, leaves it unchanged as seen below
qc.draw('mpl')

# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an Y-gate on a |1> qubit
qc = QuantumCircuit(1)
#In qiskit, the qubit is initialised at |0>
qc.x(0)
qc.z(0) #z rotation on the |1> qubit?
qc.draw('mpl')

# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an H-gate on a |0> qubit
qc = QuantumCircuit(1)
#In qiskit, the qubit is initialised at |0>
qc.h(0)
qc.draw('mpl')

# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an H-gate on a |0> qubit followed by Z
qc = QuantumCircuit(1)
#In qiskit, the qubit is initialised at |0>, let's convert it to the |1> state
qc.h(0)
qc.z(0)


# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

# Let's do an H-gate on a |0> qubit followed by X
qc = QuantumCircuit(1)
#In qiskit, the qubit is initialised at |0>, let's convert it to the |1> state
qc.h(0)
qc.x(0) #Does this make any difference?
qc.z(0) #This flips


# Let's see the result
qc.save_statevector()
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector()
plot_bloch_multivector(state)

import numpy as np
from numpy import pi
# importing Qiskit
from qiskit import QuantumCircuit, transpile, Aer, IBMQ
from qiskit.tools.monitor import job_monitor
from qiskit.visualization import plot_histogram, plot_bloch_multivector

qc = QuantumCircuit(3)
qc.h(2)
qc.cp(pi/2, 1, 2) # CROT from qubit 1 to qubit 2
qc.cp(pi/4, 0, 2) # CROT from qubit 2 to qubit 0
qc.h(1)
qc.cp(pi/2, 0, 1) # CROT from qubit 0 to qubit 1
qc.h(0)
qc.swap(0,2)
qc.draw('mpl')

def qft_rotations(circuit, n):
    """Performs qft on the first n qubits in circuit (without swaps)"""
    if n == 0:
        return circuit
    n -= 1
    circuit.h(n)
    for qubit in range(n):
        circuit.cp(pi/2**(n-qubit), qubit, n)
    # At the end of our function, we call the same function again on
    # the next qubits (we reduced n by one earlier in the function)
    qft_rotations(circuit, n)

# Let's see how it looks:
qc = QuantumCircuit(4)
qft_rotations(qc,4)
qc.draw('mpl')

def swap_registers(circuit, n):
    for qubit in range(n//2):
        circuit.swap(qubit, n-qubit-1)
    return circuit

def qft(circuit, n):
    """QFT on the first n qubits in circuit"""
    qft_rotations(circuit, n)
    swap_registers(circuit, n)
    return circuit

# Let's see how it looks:
qc = QuantumCircuit(4)
qft(qc,4)
qc.draw('mpl')

bin(5)

# Create the circuit
qc = QuantumCircuit(3)

# Encode the state 5
qc.x(0)
qc.x(2)
qc.draw('mpl')

#Checking qubit states in the bloch vector representation using the Aer simulator

sim = Aer.get_backend("aer_simulator")
qc_init = qc.copy()
qc_init.save_statevector()
statevector = sim.run(qc_init).result().get_statevector()
plot_bloch_multivector(statevector)

qft(qc,3)
qc.draw('mpl')

qc.save_statevector()
statevector = sim.run(qc).result().get_statevector()
plot_bloch_multivector(statevector)

bin(4)

# Create the circuit
qc = QuantumCircuit(3)

# Encode the state 4
qc.x(2)
qc.draw('mpl')

sim = Aer.get_backend("aer_simulator")
qc_init = qc.copy()
qc_init.save_statevector()
statevector = sim.run(qc_init).result().get_statevector()
plot_bloch_multivector(statevector)

qft(qc,3)
qc.draw('mpl')

qc.save_statevector()
statevector = sim.run(qc).result().get_statevector()
plot_bloch_multivector(statevector)

