from qiskit import QuantumCircuit,Aer,execute,transpile,BasicAer
from qiskit.visualization import *
import numpy as np



qc = QuantumCircuit(1)
qc.initialize([1/np.sqrt(2), -1/np.sqrt(2)], 0)
qc.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(qc,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

print(sv)

plot_state_qsphere(sv,show_state_phases=True)

qc = QuantumCircuit(1)
qc.x(0)
qc.h(0)
qc.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(qc,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

qc = QuantumCircuit(2)
qc.initialize('01', qc.qubits)
qc.draw(output="mpl")

backend = BasicAer.get_backend('statevector_simulator')
job = backend.run(transpile(qc, backend))
qc_state = job.result().get_statevector(qc)
qc_state

array_to_latex(qc_state)

qc = QuantumCircuit(2)

qc.x(0)

qc.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(qc,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")

qc = QuantumCircuit(2)
qc.initialize([0, 1/np.sqrt(2), -1.j/np.sqrt(2), 0], qc.qubits)
qc.draw()

backend = BasicAer.get_backend('statevector_simulator')
job = backend.run(transpile(qc, backend))
qc_state = job.result().get_statevector(qc)
qc_state

array_to_latex(qc_state)

qc = QuantumCircuit(2)

qc.h(0)
qc.x(1)
qc.cx(0,1)
qc.sdg(1)


qc.draw(output="mpl")

backend=Aer.get_backend('statevector_simulator')
job=execute(qc,backend,shots=1024)
result=job.result()
sv=result.get_statevector()
sv.draw(output="latex")