from qiskit.providers.ibmq.managed import IBMQJobManager
from qiskit import IBMQ
IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q-education')

from qiskit import QuantumCircuit, execute, transpile, Aer
from qiskit.extensions import UnitaryGate, Initialize
from qiskit.quantum_info import Statevector
from qiskit.compiler import assemble 
from qiskit.tools.visualization import plot_bloch_vector
from qiskit.tools.visualization import plot_histogram, plot_bloch_multivector
import numpy as np
from time import sleep
import sys
sys.path.append("..")
from scipy.stats import unitary_group
import matplotlib.pyplot as plt
%matplotlib inline

from Modules.changed_SPEA import bundled_SPEA_alternate 

q = QuantumCircuit(2)
q.cp(2*np.pi*(1/4), 0, 1)
q.draw('mpl')

spe = bundled_SPEA_alternate(q, resolution=30, error=3, max_iters=10)

jakarta = provider.get_backend('ibmq_jakarta')
bogota = provider.get_backend('ibmq_bogota')

thetas = []
for k in range(5):
    result = spe.get_eigen_pair(
        backend=jakarta, progress=True, randomize=True)
    print("Result is :", result)
    thetas.append(result['theta'])

thetas

plt.title("Plot for returned Eigenvalues", fontsize=16)
plt.xlabel("Experiment number")
plt.ylabel("Eigenvalues")
plt.plot([0, 6], [0, 0], color='black')
plt.plot([0, 6], [1, 1], color='black')
plt.plot([0, 6], [0.25, 0.25], color='black')
plt.plot(list(range(5)), thetas, label='Estimates',
         color='cyan', linewidth=2, marker='s')
plt.legend()
plt.grid()

