from qiskit import QuantumCircuit, assemble, Aer
from qiskit.visualization import plot_histogram, plot_bloch_vector
from cmath import sqrt, pi, exp
sim = Aer.get_backend('aer_simulator')

qc = QuantumCircuit(1)  # Create a quantum circuit with one qubit
initial_state = [0,1]
qc.initialize(initial_state, 0)

sim = Aer.get_backend('aer_simulator') 
qc.save_statevector()         ## this converts output in to state vector
qobj = assemble(qc)           ## this assembles quantum circuit
job = sim.run(qobj)         ## this is for running the job
ket = job.result().get_statevector()
print(ket)

qc.measure_all()
qc.draw()

qobj = assemble(qc)
counts = sim.run(qobj).result().get_counts()
plot_histogram(counts)

qc1 = QuantumCircuit(1)  # Create a quantum circuit with one qubit
initial_state = [1/sqrt(2),1/sqrt(2)]   # Define initial_state as |1>
qc1.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
qc1.draw()  # Let's view our circuit

sim = Aer.get_backend('aer_simulator') 
qc1.save_statevector()         ## this converts output in to state vector
qobj = assemble(qc1)           ## this assembles quantum circuit
job = sim.run(qobj)         ## this is for running the job
ket = job.result().get_statevector()
print(ket)

qc1.measure_all()
qc1.draw()

qobj = assemble(qc1)
counts = sim.run(qobj).result().get_counts()
plot_histogram(counts)

state1 = [1/sqrt(3),sqrt(2/3)]


i=complex(0,1)
state2 = [exp(-i*pi)*1/sqrt(3),exp(-i*pi)*sqrt(2/3)] ## adding a global phase never changes the probabilities.

initial_state = state1  # Define state |q_0>
qc = QuantumCircuit(1) # Must redefine qc
qc.initialize(initial_state, 0) # Initialize the 0th qubit in the state `initial_state`
qc.save_statevector() # Save statevector
qobj = assemble(qc)
results = sim.run(qobj).result().get_counts()
plot_histogram(results)

initial_state = state2  # Define state |q_0>
qc = QuantumCircuit(1) # Must redefine qc
qc.initialize(initial_state, 0) # Initialize the 0th qubit in the state `initial_state`
qc.save_statevector() # Save statevector
qobj = assemble(qc)
state = sim.run(qobj).result().get_statevector() # Execute the circuit
print(state)           # Print the result
qobj = assemble(qc)
results = sim.run(qobj).result().get_counts()
plot_histogram(results)

from qiskit_textbook.widgets import plot_bloch_vector_spherical
coords = [pi/2,0,1] # [Theta, Phi, Radius]
plot_bloch_vector_spherical(coords) # Bloch Vector with spherical coordinates

from qiskit_textbook.widgets import plot_bloch_vector_spherical
coords = [2*pi,0,1] # [Theta, Phi, Radius]
plot_bloch_vector_spherical(coords) # Bloch Vector with spherical coordinates

from qiskit_textbook.widgets import plot_bloch_vector_spherical
coords = [pi,0,1] # [Theta, Phi, Radius]
plot_bloch_vector_spherical(coords) # Bloch Vector with spherical coordinates



from qiskit_textbook.widgets import plot_bloch_vector_spherical
coords = [pi/2,0,1] # [Theta, Phi, Radius]
plot_bloch_vector_spherical(coords) # Bloch Vector with spherical coordinates


from qiskit_textbook.widgets import plot_bloch_vector_spherical
coords = [pi/2,-pi/2,1] # [Theta, Phi, Radius]
plot_bloch_vector_spherical(coords) # Bloch Vector with spherical coordinates



