# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from qiskit_aer import AerSimulator

# qiskit-ibmq-provider has been deprecated.
# Please see the Migration Guides in https://ibm.biz/provider_migration_guide for more detail.
from qiskit_ibm_runtime import QiskitRuntimeService, Sampler, Estimator, Session, Options

# Loading your IBM Quantum account(s)
service = QiskitRuntimeService(channel="ibm_quantum")

# Invoke a primitive inside a session. For more details see https://qiskit.org/documentation/partners/qiskit_ibm_runtime/tutorials.html
# with Session(backend=service.backend("ibmq_qasm_simulator")):
#     result = Sampler().run(circuits).result()

from qiskit import * #importing libraries we need
from qiskit.tools.visualization import  plot_bloch_multivector
from qiskit.visualization import plot_histogram
%matplotlib inline
import math

Aer.backends() #seeing all the availibe simulators

def run_on_simulators(circuit): #defining a function to run on two simulators
    statevector = execute(circuit, backend=Aer.get_backend('statevector_simulator'))
    result = statevector.result()
    vec = result.get_statevector()
    
    QubitsNumber = circuit.num_qubits
    circuit.measure([i for i in range(QubitsNumber)], [i for i in range(QubitsNumber)])
    
    Qass = execute(circuit, backend=Aer.get_backend('qasm_simulator'), shots=1024).result()
    count = Qass.get_counts()
    
    return vec, count

circuit = QuantumCircuit(2,2)
statevec, counts = run_on_simulators(circuit)



plot_bloch_multivector(statevec)


plot_histogram([counts])


circuit = QuantumCircuit(2,2)
circuit.h(0)
circuit.cx(0,1)
statevec, counts = run_on_simulators(circuit)
plot_bloch_multivector(statevec)

plot_histogram([counts])


circuit = QuantumCircuit(2,2)
circuit.rx(math.pi/4, 0)
circuit.rx(math.pi / 2, 1)
statevec, counts = run_on_simulators(circuit)
plot_bloch_multivector(statevec)

plot_histogram([counts])


circuit = QuantumCircuit(2,2)
circuit.ry(math.pi/4, 0)
circuit.ry(math.pi / 2, 1)
statevec, counts = run_on_simulators(circuit)
plot_bloch_multivector(statevec)

plot_histogram([counts])


circuit.h(0)
statevec, counts = run_on_simulators(circuit)
plot_bloch_multivector(statevec)


plot_histogram([counts])


circuit.h(0)
circuit.h(1)
statevec, counts = run_on_simulators(circuit)
plot_bloch_multivector(statevec)

plot_histogram([counts])


statevec, counts = run_on_simulators(circuit)
plot_bloch_multivector(statevec)

plot_histogram([counts])
