from qiskit import *
from math import pi
import numpy as np
from qiskit.quantum_info import Statevector
from qiskit_textbook.tools import array_to_latex
from qiskit.visualization import plot_bloch_multivector, plot_histogram, plot_state_city,plot_state_qsphere

%matplotlib inline

qc1 = QuantumCircuit(2)
qc1.draw('mpl')

backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit
final_state = execute(qc1,backend).result().get_statevector()
job = execute(qc1,backend).result() # Do the simulation, returning the state vector
print(final_state)
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc1))

qc1 = QuantumCircuit(2)
qc1.x(0)
qc1.draw('mpl')

backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit
final_state = execute(qc1,backend).result().get_statevector()
job = execute(qc1,backend).result() # Do the simulation, returning the state vector
print(final_state)
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc1))

qc1 = QuantumCircuit(2)
qc1.x(1)
qc1.draw('mpl')

backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit
final_state = execute(qc1,backend).result().get_statevector()
job = execute(qc1,backend).result() # Do the simulation, returning the state vector
print(final_state)
array_to_latex(final_state, pretext="\\text{Statevector = }")
plot_state_qsphere(job.get_statevector(qc1))

qc1 = QuantumCircuit(2)
qc1.x(0)
qc1.x(1)
qc1.draw('mpl')

backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit
final_state = execute(qc1,backend).result().get_statevector()
job = execute(qc1,backend).result() # Do the simulation, returning the state vector
print(final_state)
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc1))

sv = Statevector.from_label('00')
# Bell State |Ψ+>
qcb = QuantumCircuit(2)
qcb.h(0)
qcb.cx(0, 1)
qcb.draw('mpl')

new_sv = sv.evolve(qcb)
print(new_sv)
plot_state_qsphere(new_sv.data)

qc = QuantumCircuit(2)
# Apply H-gate to the first:
qc.h(0)
# Apply a CNOT:
qc.cx(0,1)
qc.draw('mpl')

backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()
job = execute(qc,backend).result() # Do the simulation, returning the state vector
print(np.round(final_state,10))
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc))

sv = Statevector.from_label('01')
# Bell State |Ψ+>
qcx = QuantumCircuit(2)
qcx.h(0)
qcx.cx(0, 1)
qcx.draw('mpl')

new_sv = sv.evolve(qcx)
print(new_sv)
plot_state_qsphere(new_sv.data)

qc = QuantumCircuit(2)
# Apply H-gate to the first:
qc.x(0)
qc.h(0)
# Apply a CNOT:
qc.cx(0,1)
qc.draw('mpl')

backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()
job = execute(qc,backend).result() # Do the simulation, returning the state vector
print(np.round(final_state,10))
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc))

sv = Statevector.from_label('10')
# Bell State |Ψ+>
qcx = QuantumCircuit(2)
qcx.h(0)
qcx.cx(0, 1)
qcx.draw('mpl')

new_sv = sv.evolve(qcx)
print(new_sv)
plot_state_qsphere(new_sv.data)

qc = QuantumCircuit(2)
# Apply H-gate to the first:
qc.x(1)
qc.h(0)
# Apply a CNOT:
qc.cx(0,1)
qc.draw('mpl')

backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()
job = execute(qc,backend).result() # Do the simulation, returning the state vector
print(np.round(final_state,10))
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc))

sv = Statevector.from_label('11')
# Bell State |Ψ+>
qcx = QuantumCircuit(2)
qcx.h(0)
qcx.cx(0, 1)
qcx.draw('mpl')

new_sv = sv.evolve(qcx)
print(new_sv)
plot_state_qsphere(new_sv.data)

qc = QuantumCircuit(2)
# Apply H-gate to the first:
qc.x(0)
qc.x(1)
qc.h(0)
# Apply a CNOT:
qc.cx(0,1)
qc.draw('mpl')

backend = Aer.get_backend('statevector_simulator')
final_state = execute(qc,backend).result().get_statevector()
job = execute(qc,backend).result() # Do the simulation, returning the state vector
print(np.round(final_state,10))
array_to_latex(final_state, pretext="\\text{Statevector} = ")
plot_state_qsphere(job.get_statevector(qc))