from qiskit import QuantumCircuit, execute, Aer
from qiskit.visualization import plot_histogram, plot_bloch_vector
from math import sqrt, pi

qc = QuantumCircuit(1) # Create a quantum circuit with one qubit

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

backend = Aer.get_backend('statevector_simulator') # Tell Qiskit how to simulate our circuit


qc = QuantumCircuit(1) # Create a quantum circuit with one qubit
initial_state = [0,1]   # Define initial_state as |1>
qc.initialize(initial_state, 0) # Apply initialisation operation to the 0th qubit
result = execute(qc,backend).result() # Do the simulation, returning the result

output_state = result.get_statevector()
print(output_state) # Display the output state vector

qc.measure_all()
qc.draw() 

result = execute(qc,backend).result()
counts = result.get_counts()
plot_histogram(counts)

initial_state = [1/sqrt(2), 1j/sqrt(2)]  # Define state |q_0> 

qc = QuantumCircuit(1) # Must redefine qc
qc.initialize(initial_state, 0) # Initialise the 0th qubit in the state `initial_state`
state = execute(qc,backend).result().get_statevector() # Execute the circuit
print(state)           # Print the result

results = execute(qc,backend).result().get_counts()
plot_histogram(results)

vector = [1,1]
qc.initialize(vector, 0)

qc = QuantumCircuit(1) # We are redefining qc
initial_state = [0.+1.j/sqrt(2),1/sqrt(2)+0.j]
qc.initialize(initial_state, 0)
qc.draw()

state = execute(qc, backend).result().get_statevector()
print("Qubit State = " + str(state))

qc.measure_all()
qc.draw()

state = execute(qc, backend).result().get_statevector()
print("State of Measured Qubit = " + str(state))

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

import qiskit
qiskit.__qiskit_version__

