from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit_aer import AerSimulator
from qiskit import *
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.draw('mpl')

qc.initialize([1,0])  # Define initial_state as |0>
qc.draw('mpl')

initial_state = [0,1]   # this is the |1> state
qc.initialize(initial_state,0) # apply the initialisation on the qubit
qc.draw('mpl')

from qiskit.primitives import Sampler
sampler = Sampler()  # tell qiskit how to simulate the circuit

backend = AerSimulator()  # tell qiskit to use the AerSimulator
backend.available_devices()

backend.available_methods()


qc.draw('mpl')

from qiskit.quantum_info import Statevector


# get the statevcector
state = Statevector.from_instruction(qc)
print(state)

# lets plot the histogram
qc.measure_all()

# run the simulation
result = sampler.run(qc).result()
counts = result.quasi_dists[0]
plot_histogram(counts)

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

qc = QuantumCircuit(1)

qc.initialize(initial_state,0) # apply the initialisation on the qubit
qc.draw('mpl')

# get the statevcector
state = Statevector.from_instruction(qc)
print(state)

qc.measure_all()

# run the simulation
result = sampler.run(qc).result()
counts = result.quasi_dists[0]
plot_histogram(counts)


vector = [1,1]

qc.initialize(vector,0)

qc = QuantumCircuit(1)   # making a new quantum circuit
initial_state = [0.+1.j/sqrt(2),1/sqrt(2)+0.j]
qc.initialize(initial_state,0)
qc.draw('mpl')

qc = QuantumCircuit(1)
initial_state = [0.+1.j/sqrt(2),1/sqrt(2)+0.j]
qc.initialize(initial_state, 0)

# get the statevcector
state = Statevector.from_instruction(qc)
print(state)

qc.draw('mpl')

from qiskit.visualization import plot_bloch_vector

plot_bloch_vector([pi/2,0,1])

# let's plot |0>
plot_bloch_vector([0,0,1])

# let's plot |0>
plot_bloch_vector([1,0,0])