from qiskit import *
from math import pi,sqrt
from qiskit.visualization import plot_bloch_multivector,plot_histogram

backend_s = Aer.get_backend('statevector_simulator')
backend_q = Aer.get_backend('qasm_simulator')

qc = QuantumCircuit(2)
qc.h(0)
qc.z(0)
qc.h(0)
qc.x(1)

display(qc.draw('mpl'))

# we use the statevector_simulator to obtain the statevector
job = execute(qc,backend_s)
job_result = job.result()
state_vec = job_result.get_statevector()
plot_bloch_multivector(state_vec)

qc = QuantumCircuit(2)
qc.x(0)
qc.z(0)
qc.y(1)

display(qc.draw('mpl'))

job = execute(qc,backend_s)
job_result = job.result()
state_vec = job_result.get_statevector()
plot_bloch_multivector(state_vec)

qc = QuantumCircuit(1,1)
# initialize qubit in state |+>
qc.initialize([1/sqrt(2),1/sqrt(2)],0)
qc.barrier()
qc.h(0)
qc.measure(0,0)

display(qc.draw('mpl'))

job = execute(qc, backend_q)
job_result = job.result()
res_counts = job_result.get_counts()
plot_histogram(res_counts)

# initialize in |+> state:

qc = QuantumCircuit(1,1)
qc.h(0)
qc.measure(0,0)

display(qc.draw('mpl'))

job = execute(qc, backend_q,shots=4000)
job_result = job.result()
res_counts = job_result.get_counts()
plot_histogram(res_counts)

qc = QuantumCircuit(1,1)
qc.x(0)
qc.h(0)
qc.measure(0,0)

display(qc.draw('mpl'))

job = execute(qc, backend_q,shots=4000)
job_result = job.result()
res_counts = job_result.get_counts()
plot_histogram(res_counts)

qc = QuantumCircuit(2)
qc.initialize([1/sqrt(2),1.j/sqrt(2)],0)
qc.initialize([1/sqrt(2),-1.j/sqrt(2)],1)
qc.sdg([0,1])
qc.h([0,1])
qc.measure_all()
qc.barrier()
qc.h([0,1])
qc.s([0,1])
qc.draw('mpl')

job = execute(qc,backend_q).result()
counts = job.get_counts()
plot_histogram(counts)

job = execute(qc,backend_s).result()
state_vec = job.get_statevector()
plot_bloch_multivector(state_vec)

import qiskit
qiskit.__qiskit_version__

