!pip install qiskit

import numpy as np
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit import execute

q = QuantumRegister(1) 

c = ClassicalRegister(1)

qc = QuantumCircuit(q,c)

qc.x(q[0])
qc.barrier(q)
qc.measure(q,c)

qc.draw()

from qiskit import BasicAer

backend = BasicAer.get_backend('qasm_simulator')

job = execute(qc, backend, shots=1024)
res = job.result()
res.get_counts()

q = QuantumRegister(1)
c = ClassicalRegister(1)
qc = QuantumCircuit(q,c)

qc.h(q[0])
qc.barrier(q)
qc.measure(q,c)

qc.draw()

job=execute(qc,backend,shots=1024)
res=job.result()

res.get_counts()

from qiskit.tools.visualization import plot_histogram
plot_histogram(res.get_counts())

q = QuantumRegister(1) 
qc = QuantumCircuit(q)

qc.x(q[0])
qc.h(q[0])


qc.draw()

backend = BasicAer.get_backend('statevector_simulator')

job = execute(qc,backend)
res = job.result()

vector = res.get_statevector(qc,decimals=3)
print(vector)

from sympy import Matrix , pprint

pprint(Matrix(vector))

from qiskit.tools.visualization import plot_bloch_vector


qc1 = QuantumCircuit(q)


qc1.iden(q[0])

job = execute(qc1,backend)
res =job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

px = np.array([[0,1],[1,0]])
py = np.array([[0,-1j],[1j,0]])
pz = np.array([[1,0],[0,-1]])


x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec=[x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)


qc1.x(q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.h(q[0])


job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.h(q[0])
qc1.y(q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))



vec = [x,y,z]

plot_bloch_vector(vec)

qc1=QuantumCircuit(q)

qc1.h(q[0])
qc1.z(q[0])

job=execute(qc1,backend)
res=job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p=np.outer(vector,vector.conj())

x=float(np.trace(np.dot(px,p)))
y=float(np.trace(np.dot(py,p)))
z=float(np.trace(np.dot(pz,p)))

vec=[x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.h(q[0])
qc1.t(q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.h(q[0])
qc1.tdg(q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.h(q[0])
qc1.s(q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.h(q[0])
qc1.sdg(q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

qc1 = QuantumCircuit(q)

qc1.u3(np.pi/7,5*np.pi/14,np.pi/8,q[0])

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

pprint(Matrix(vector))

p = np.outer(vector,vector.conj())

x = float(np.trace(np.dot(px,p)))
y = float(np.trace(np.dot(py,p)))
z = float(np.trace(np.dot(pz,p)))

vec = [x,y,z]

plot_bloch_vector(vec)

q = QuantumRegister(2)

qc1 = QuantumCircuit(q)

qc1.h(q[0])
qc1.cx(q[0],q[1])
qc1.draw()

job = execute(qc1,backend)
res = job.result()

vector = res.get_statevector(qc1,decimals=3)
print(vector)

pprint(Matrix(vector))

q = QuantumRegister(2)
c = ClassicalRegister(2)
qc1 = QuantumCircuit(q,c)

qc1.h(q[0])
qc1.cx(q[0],q[1])
qc1.barrier(q)
qc1.measure(q,c)

from qiskit import BasicAer
backend = BasicAer.get_backend('qasm_simulator')

job = execute(qc1,backend,shots=1000)
res = job.result()

counts = res.get_counts()

print(counts)

plot_histogram(counts)

q = QuantumRegister(2)

qc = QuantumCircuit(q)

qc.ch(q[0],q[1])
qc.draw()

q = QuantumRegister(2)

qc = QuantumCircuit(q)

qc.cy(q[0],q[1])
qc.draw()

q = QuantumRegister(2)

qc = QuantumCircuit(q)

qc.cz(q[0],q[1])
qc.draw()

q = QuantumRegister(2)

qc = QuantumCircuit(q)

qc.cu3(np.pi/3,np.pi/4,np.pi,q[0],q[1])
qc.draw()

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

qc.h(q[0])
qc.cx(q[0],q[1])
qc.cx(q[0],q[2])
qc.barrier(q)
qc.measure(q,c)
qc.draw()




backend = BasicAer.get_backend('qasm_simulator')


job = execute(qc,backend,shots=1000)

res = job.result()

res.get_counts()

plot_histogram(res.get_counts())

backend=BasicAer.get_backend('statevector_simulator')

job=execute(qc,backend)

res=job.result()


v=res.get_statevector(qc,decimals=3)

pprint(Matrix(v))