import numpy as np
import cmath
# Importing standard Qiskit libraries
from qiskit.quantum_info import Statevector, random_statevector
from qiskit import QuantumCircuit, transpile, Aer, IBMQ, assemble, execute
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *

from qiskit.extensions import Initialize
# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()

#import sys
#sys.path.insert(0, '/home/jovyan/exercises_levels/Gates_and_Circuits/Single Qubit Gates/Level_1_Single_Qubit_Gates')
#from Check_level_1_gates import *
#import warnings
#warnings.filterwarnings('ignore')

qc = QuantumCircuit(1)

qc.x(0)

state = Statevector.from_instruction(qc)
plot_bloch_multivector(state)



qc = QuantumCircuit(1)

qc.h(0)

state = Statevector.from_instruction(qc)
plot_bloch_multivector(state)


qc = QuantumCircuit(1)

qc.x(0)
qc.h(0)

# or
#qc.h(0)
#qc.z(0)

# or
#qc.u(np.pi/2,np.pi,0,0)

state = Statevector.from_instruction(qc)
plot_bloch_multivector(state)

qc=QuantumCircuit(1,1)
qc.u3(np.pi/4,np.pi/4,np.pi/4,0)

qc.measure(0,0)

backend = Aer.get_backend('qasm_simulator') # we choose the simulator as our backend
Counts = execute(qc, backend, shots = 1024,  seed_simulator=312).result().get_counts() # we run the simulation and get the counts
plot_histogram(Counts) # let us plot a histogram to see the possible outcomes and corresponding probabilities

psi = random_statevector(2, seed=11)
init_gate = Initialize(psi)
init_gate.label = "Random_State"



## Measure the state in the x,y,z basis and make a guess for the state_vector psi

#Measure in all three different bases
qc=QuantumCircuit(1,1)
qc.initialize(psi,0)
qc.measure(0,0)
z = execute(qc, backend, shots = 1024,  seed_simulator=312).result().get_counts() # we run the simulation and get the counts

qc=QuantumCircuit(1,1)
qc.initialize(psi,0)
qc.h(0)
qc.s(0)
qc.measure(0,0)
y = execute(qc, backend, shots = 1024,  seed_simulator=312).result().get_counts() # we run the simulation and get the counts

qc=QuantumCircuit(1,1)
qc.initialize(psi,0)
qc.h(0)
qc.measure(0,0)
x = execute(qc, backend, shots = 1024,  seed_simulator=312).result().get_counts() # we run the simulation and get the counts

print(x,y,z)
#Put your answer here
#Try to remove any global phase in your answer
#phi=
#theta=



#bonus_validation([phi, theta])






angles : [phi,theta]


