from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit, transpile, qasm2, qasm3
from qiskit_aer import Aer
from qiskit.primitives import BackendSampler
from qiskit.providers.basic_provider import BasicProvider # instead of BasicAer
import Our_Qiskit_Functions as oq
import numpy as np
import math as m
import scipy as sci
import random
import matplotlib
import matplotlib.pyplot as plt
from itertools import permutations
S_simulator = Aer.backends(name='statevector_simulator')[0]

def Happiness( A ):
    happiness = 0
    for i in np.arange(len(A)):
        if( A[i] == 1):
            Mi = int(i)
        if( A[i] == 2):
            Be = int(i)
        if( A[i] == 3):
            Ma = int(i)
        if( A[i] == 4):
            Cu = int(i)
        if( A[i] == 5):
            Na = int(i)
        if( A[i] == 6):
            Cl = int(i)
        if( A[i] == 7):
            Wi = int(i)
    if( (abs(Mi - Be)<=3) and (abs(Mi - Ma)<=3) ): # Michelle
        happiness += 1
    if( (abs(Be - Mi)<=3) and (abs(Be - Ma)<=3) ): # Betty
        happiness += 1
    if( (abs(Ma - Mi)<=3) and (abs(Ma - Be)<=3) ): # Margaret
        happiness += 1
    if( abs(Cu - Na)>=3 ): # Cullen
        happiness += 1
    if( (abs(Na - Cu)>=3) and (abs(Na - Be)==1) ): # Nate
        happiness += 1
    if( (abs(Cl - Cu)>1) and (abs(Cl - Wi)>1) ): # Clint
        happiness += 1
    happiness += 1 # Will
    return happiness
#==================================================================================
perm = permutations([1, 2, 3, 4, 5, 6, 7])
All_Happy = []
all_perm = 0
for i in list(perm):
    all_perm = all_perm + 1
    if( Happiness(list(i)) == 7 ):
        All_Happy.append( list(i) )
print('Total Combinations Where Everyone Is Happy: ',len(All_Happy))

q = QuantumRegister(2, name = 'q')
a = QuantumRegister(1, name = 'a')
qc= QuantumCircuit(q,a, name = 'qc')
#===================================
qc.h( q[0] )
qc.h( q[1] )
qc.barrier()
print('__ Initial State __')
oq.Wavefunction(qc, systems=[2,1])
#----------------------------------- Uc Operator
qc.x( q[0] )
qc.ccx( q[0], q[1], a[0] )
qc.cp( -m.pi/2, a[0], q[0] )
qc.ccx( q[0], q[1], a[0] )
qc.x( q[0] )
#-----------------------------------
print('\n__ After Applying The |01> Phase Term __')
oq.Wavefunction(qc, systems=[2,1], show_systems=[True,False])
print('\n__ Circuit Diagram __\n')
print(qc)

q = QuantumRegister(2, name = 'q')
a = QuantumRegister(1, name = 'a')
Uc_qc= QuantumCircuit(q,a, name = 'qc')
Uc_qc.h( q[0] )
Uc_qc.h( q[1] )
print('__ Initial State __')
oq.Wavefunction(Uc_qc, systems=[2,1])
#-------------------------------------- # |00> state
Uc_qc.x( q[0] )
Uc_qc.x( q[1] )
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.cp( m.pi/4, a[0], q[0] )
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.x( q[1] )
Uc_qc.x( q[0] )
#-------------------------------------- # |01> state
Uc_qc.x( q[0] )
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.cp( -m.pi/2, a[0], q[0] )
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.x( q[0] )
#-------------------------------------- # |10> state
Uc_qc.x( q[1] )
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.cp( -m.pi/4, a[0], q[0] )
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.x( q[1] )
#-------------------------------------- # |11> state
Uc_qc.ccx( q[0], q[1], a[0] )
Uc_qc.cp( m.pi/2, a[0], q[0] )
Uc_qc.ccx( q[0], q[1], a[0] )
print('\n__ After Applying U(C,gamma) __')
oq.Wavefunction(Uc_qc, systems=[2,1]);

q = QuantumRegister(3,name='q')
c = ClassicalRegister(3,name='c')
qc = QuantumCircuit(q,c,name='qc')
#=================================
qc.h( q[0] )
qc.h( q[1] )
qc.h( q[2] )
qc.p( m.pi/10, q[0] )
qc.p( m.pi/15, q[1] )
qc.p( m.pi/20, q[2] )
qc.rx( m.pi/5, q[0] )
qc.ry( m.pi/6, q[1])
qc.rz( m.pi/7, q[2])
#----------------------
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
qc.measure(q,c)
M = oq.Measurement( qc, shots=10000, return_M=True, print_M=False)
#-----------------------------------------------------------------
Energies = [ ['000',2],['100',-4],['010',-2],['110',4],['001',4],['101',-2],['011',-4],['111',2]]
EV1 = 0
EV2 = 0
for i in range( len(Energies) ):
    EV1 = EV1 + M[ Energies[i][0] ] * Energies[i][1]/10000
    EV2 = EV2 + np.real(SV[i]*np.conj(SV[i])) * Energies[i][1]
print('Energy Expectation Value From Measurements: ',round(EV1,4))
print('\nEnergy Expectation Value From Wavefunction: ',round(EV2,4))

q = QuantumRegister(2,name='q')
qc = QuantumCircuit(q,name='qc')
#===============================
qc.h( q[0] )
qc.h( q[1] )
qc.barrier()
print('___ Initial State ___')
oq.Wavefunction( qc )
#-------------------------------
qc.cx( q[0], q[1] )
qc.p( -m.pi/2, q[1] )
qc.cx( q[0], q[1] )
#-------------------------------
print('\n___ After e^{ZZ} ___')
oq.Wavefunction( qc )
print( qc )

gamma = 0.8
beta = 1.6
B = [-2.5,3.25,2.25]
#====================================
q = QuantumRegister(3,name='q')
c = ClassicalRegister(3,name='c')
qc = QuantumCircuit(q,c,name='qc')
#------------------------------------
for i in np.arange(3):
    qc.h( q[int(i)] )
#---------------------- # Z1Z2
qc.cx( q[0], q[1] )
qc.p( 2*gamma, q[1] )
qc.cx( q[0], q[1] )
#---------------------- # Z1Z3
qc.cx( q[0], q[2] )
qc.p( 2*gamma, q[2] )
qc.cx( q[0], q[2] )
#---------------------- # Z2Z3
qc.cx( q[1], q[2] )
qc.p( 2*gamma, q[2] )
qc.cx( q[1], q[2] )
#---------------------- # Z_gamma gates
for j in np.arange(3):
    qc.p( gamma*B[j], q )
#---------------------- # X_beta gates
for k in np.arange(3):
    qc.rx( beta, q )
#------------------------------------
qc.measure( q,c )
oq.Measurement( qc, shots = 1 )

trials = 10000
M = oq.Measurement(qc, shots = trials, return_M=True)

K = list(M.keys())
Cz = { '000':-5.0, '001':1.5, '010':5.5, '011':8.0, '100':-6.0, '101':-3.5, '110':0.5, '111':-1.0 }
#----------------------------
F = 0
for k in np.arange( len(K) ):
    F = F + (M[K[k]]*Cz[K[k]])/trials
print('\u03B3 = ',gamma,' \u03B2 = ',beta,' Expectation Value: ',round(F,3))

size = 100
Vert = [ [0,-2.5] , [1,3.25] , [2,1.25] ]
Edge = [ [0,1],[0,2],[1,2] ]
#-------------------------------------------------------
Energies,States = oq.Ising_Energy( Vert,Edge )
EV_grid = np.zeros(shape=(size,size))
EV_min = 10000
#========================================================
for b in np.arange(size):
    beta = round(2*m.pi*(b/size),4)
    for g in np.arange(size):
        gamma = round(2*m.pi*(g/size),4)
        q = QuantumRegister(len(Vert))
        qc= QuantumCircuit(q)
        for hh in np.arange(len(Vert)):
            qc.h( q[int(hh)] )
        oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma )
        EV = oq.E_Expectation_Value( qc, Energies )
        EV_grid[b,g] = EV
        if( EV < EV_min ):
            Params = [beta,gamma]
            EV_min = EV
print('Optimal Energy Expectation Value: ',EV_min,' \u03B3 = ',Params[1],' \u03B2 = ',Params[0],'\n')
#========================================================
fig, ax = plt.subplots()
show_text = False
show_ticks = False
oq.Heatmap(EV_grid, show_text, show_ticks, ax, "plasma", "Energy Expectation Value")
fig.tight_layout()
plt.show()

beta = Params[0] # Params is required from the previous cell of code
gamma = Params[1]
Vert = [ [0,-2.5] , [1,3.25] , [2,1.25] ]
Edge = [ [0,1],[0,2],[1,2] ]
Energies,States = oq.Ising_Energy( Vert,Edge )
#=======================================================
q = QuantumRegister(len(Vert))
qc= QuantumCircuit(q)
for hh in np.arange(len(Vert)):
    qc.h( q[int(hh)] )
oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma )
#========================================================
print('Optimal Energy Expectation Value: ',EV_min,' \u03B3 = ',Params[1],' \u03B2 = ',Params[0],'\n')
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
oq.Top_States(States,Energies,SV,8)

T = 8
Z = [m.sqrt(0.5),0,0,m.sqrt(0.5)]
Closest_IP = 0
#====================================
for i1 in np.arange(T+1):
    t1 = i1*m.pi/T
    for i2 in np.arange(T+1):
        t2 = i2*m.pi/T
        for i3 in np.arange(T+1):
            t3 = i3*m.pi/T
            for i4 in np.arange(T+1):
                t4 = i4*m.pi/T
#---------------------
                q = QuantumRegister(2)
                qc= QuantumCircuit(q)
                qc.rx( t1, q[0] )
                qc.rx( t2, q[1] )
                qc.ry( t3, q[0] )
                qc.ry( t4, q[1] )
                SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
                IP = (SV[0]*Z[0]) + (SV[1]*Z[1]) + (SV[2]*Z[2]) + (SV[3]*Z[3])
                if( IP > Closest_IP ):
                    Closest_IP = IP

print( 'Largest Inner Product Overlap with the |00> + |11> state: ',round(np.real(Closest_IP),4 ))

T = 8
Z = [m.sqrt(0.5),0,0,m.sqrt(0.5)]
Closest_IP = 0
#====================================
for i1 in np.arange(T+1):
    t1 = i1*m.pi/T
    for i2 in np.arange(T+1):
        t2 = i2*m.pi/T
        for i3 in np.arange(T+1):
            t3 = i3*m.pi/T
            for i4 in np.arange(T+1):
                t4 = i4*m.pi/T
#---------------------
                q = QuantumRegister(2)
                qc= QuantumCircuit(q)
                qc.rx( t1, q[0] )
                qc.rx( t2, q[1] )
                qc.ry( t3, q[0] )
                qc.ry( t4, q[1] )
                qc.cx( q[0], q[1] )
                SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
                IP = (SV[0]*Z[0]) + (SV[1]*Z[1]) + (SV[2]*Z[2]) + (SV[3]*Z[3])
                if( IP > Closest_IP ):
                    Closest_IP = IP

print( 'Largest Inner Product Overlap with |\u03A8>: ',round(np.real(Closest_IP),4 ))

size = 100
Vert = [ [0,-2.5] , [1,3.25] , [2,1.25] ]
Edge = [ [0,1],[0,2],[1,2] ]
#-------------------------------------------------------
Energies,States = oq.Ising_Energy( Vert,Edge )
EV_grid = np.zeros(shape=(size,size))
EV_min = 10000
#========================================================
for b in np.arange(size):
    beta = round(2*m.pi*(b/size),4)
    for g in np.arange(size):
        gamma = round(2*m.pi*(g/size),4)
        q = QuantumRegister(len(Vert))
        qc= QuantumCircuit(q)
        for hh in np.arange(len(Vert)):
            qc.h( q[int(hh)] )
        oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma, Mixing=2, p = 2)
        EV = oq.E_Expectation_Value( qc, Energies )
        EV_grid[b,g] = EV
        if( EV < EV_min ):
            Params = [beta,gamma]
            EV_min = EV
print('Optimal Energy Expectation Value: ',EV_min,' \u03B3 = ',Params[1],' \u03B2 = ',Params[0],'\n')
#========================================================
fig, ax = plt.subplots()
show_text = False
show_ticks = False
oq.Heatmap(EV_grid, show_text, show_ticks, ax, "plasma", "Energy Expectation Value")
fig.tight_layout()
plt.show()
#========================================================
beta = Params[0]
gamma = Params[1]
q = QuantumRegister(len(Vert))
qc= QuantumCircuit(q)
for hh in np.arange(len(Vert)):
    qc.h( q[int(hh)] )
oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma, Mixing=2,p=2 )
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
oq.Top_States(States,Energies,SV,8)

size = 100
#-------------------------------------------------------
Vert = [ [0,-2.5] , [1,3.25] , [2,1.25] ]
Edge = [ [0,1,2],[1,2,1.5],[2,0,-3] ]
#-------------------------------------------------------
Energies,States = oq.Ising_Energy( Vert,Edge,Transverse=True )
EV_grid = np.zeros(shape=(size,size))
EV_min = 10000
#========================================================
for b in np.arange(size):
    beta = round(2*m.pi*(b/size),4)
    for g in np.arange(size):
        gamma = round(2*m.pi*(g/size),4)
        q = QuantumRegister(len(Vert))
        qc= QuantumCircuit(q)
        for hh in np.arange(len(Vert)):
            qc.h( q[int(hh)] )
        oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma , Transverse=True, Mixing=2, p = 2 )
        EV = oq.E_Expectation_Value( qc, Energies )
        EV_grid[b,g] = EV
        if( EV < EV_min ):
            Params = [beta,gamma]
            EV_min = EV
print('Optimal Energy Expectation Value: ',EV_min,' \u03B3 = ',Params[1],' \u03B2 = ',Params[0],'\n')
#========================================================
fig, ax = plt.subplots()
show_text = False
show_ticks = False
oq.Heatmap(EV_grid, show_text, show_ticks, ax, "plasma", "Energy Expectation Value")
fig.tight_layout()
plt.show()
#========================================================
beta = Params[0]
gamma = Params[1]
q = QuantumRegister(len(Vert))
qc= QuantumCircuit(q)
for hh in np.arange(len(Vert)):
    qc.h( q[int(hh)] )
oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma, Transverse=True, Mixing=2,p=2 )
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
oq.Top_States(States,Energies,SV,8)

def Ising_Gradient_Descent(qc, q, Circ, V, E, beta, gamma, epsilon, En, step, **kwargs):
    '''
    Input: qc (QuantumCircuit) q (QuantumRegister) Circ (Ising_Circuit function) V (array) E
    beta (float) gamma (float) epsilon (float) En (array) step (float)
    Keyword Arguments: Transverse (Bool) - Changes to the Transve
    Mixing (integer) - Denotes which mixing circuit to use for U(B,beta)
    Calculates and returns the next values for beta and gamma using gradient descent
    '''
    Trans = False
    if 'Transverse' in kwargs:
        if( kwargs['Transverse'] == True ):
            Trans = True
    Mixer = 1
    if 'Mixing' in kwargs:
        Mixer = int(kwargs['Mixing'])
    params = [ [beta+epsilon,gamma],[beta-epsilon,gamma],[beta,gamma+epsilon],[beta,gamma-epsilon] ]
    ev = []
    for i in np.arange( 4 ):
        q = QuantumRegister(len(V))
        qc= QuantumCircuit(q)
        for hh in np.arange(len(V)):
            qc.h( q[int(hh)] )
        Circ( qc, q, V, E, params[i][0], params[i][1], Transverse=Trans, Mixing=Mixer )
        ev.append( E_Expectation_Value( qc, En ) )
    beta_next = beta - ( ev[0] - ev[1] )/( 2.0*epsilon ) * step
    gamma_next = gamma - ( ev[2] - ev[3] )/( 2.0*epsilon ) * step
    return beta_next, gamma_next

epsilon = 0.001
step_size = 0.001
delta = 0.0001
#-------------------------------------------------------
Vert = [ [0,-2.5] , [1,3.25] , [2,1.25] ]
Edge = [ [0,1,2],[1,2,1.5],[2,0,-3] ]
#-------------------------------------------------------
Energies,States = oq.Ising_Energy( Vert,Edge, Transverse=True )
EV = 100
EV_old = 1000
EV_min = 1000
#========================================================
beta = 0.5
gamma = 4.5
s = 0
while( (abs( EV - EV_old ) > delta)):
    q = QuantumRegister(len(Vert))
    qc= QuantumCircuit(q)
    for hh in np.arange(len(Vert)):
        qc.h( q[int(hh)] )
    if( s != 0 ):
        beta,gamma = oq.Ising_Gradient_Descent(qc,q,oq.Ising_Circuit,Vert,Edge,beta,gamma,epsilon,Energies,step_size,Transverse=True,Mixing=1)
    oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma, Transverse=True, Mixing=2 )
    EV_old = EV
    EV = oq.E_Expectation_Value( qc, Energies )
    if( EV < EV_min ):
        Params = [beta,gamma]
        EV_min = EV
    s = int(s+1)
    if (s % 10 == 0):
        print('F(\u03B3,\u03B2): ',EV,' \u03B3 = ',round(gamma,6),' \u03B2 = ',round(beta,6),)

Energies

States

epsilon = 0.0001
step_size = 0.001
delta = 0.0001
#-------------------------------------------------------
Vert = [ [0,-2.5] , [1,3.25] , [2,1.25] ]
Edge = [ [0,1,2],[1,2,1.5],[2,0,-3] ]
#-------------------------------------------------------
Energies,States = oq.Ising_Energy( Vert,Edge, Transverse=True )
EV = 100
EV_old = 1000
EV_min = 1000
#========================================================
mixing = 2
pp = 1
beta = 2*m.pi*random.random()
gamma = 2*m.pi*random.random()
s = 0
while( (abs( EV - EV_old ) > delta) and ( EV < EV_old ) ):
    q = QuantumRegister(len(Vert))
    qc= QuantumCircuit(q)
    for hh in np.arange(len(Vert)):
        qc.h( q[int(hh)] )
    if( s != 0 ):
        beta,gamma = oq.Ising_Gradient_Descent(qc,q,oq.Ising_Circuit,Vert,Edge,beta,gamma,epsilon,Energies,step_size,Transverse=True,Mixing=mixing,p=pp)
    oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma, Transverse=True, Mixing=2 )
    EV_old = EV
    EV = oq.E_Expectation_Value( qc, Energies )
    if( EV < EV_min ):
        Params = [beta,gamma]
        EV_min = EV
    s = int(s+1)
    print('F(\u03B3,\u03B2): ',EV,' \u03B3 = ',round(gamma,6),' \u03B2 = ',round(beta,6),)
#========================================================
print('\n-----------------------------------------------------------\n')
q = QuantumRegister(len(Vert))
qc= QuantumCircuit(q)
for hh in np.arange(len(Vert)):
    qc.h( q[int(hh)] )
oq.Ising_Circuit( qc, q, Vert, Edge, beta, gamma, Transverse=True, Mixing=mixing,p=pp)
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
oq.Top_States(States,Energies,SV,8)

p = 2
epsilon = 0.001
step_size = 0.01
delta = 0.001
#-------------------------------------------------------
Vert = [ 0,1,2,3,4,5 ]
Edge = [ [0,1],[0,2],[0,5],[1,2],[1,3],[2,3],[2,4],[3,5] ]
#-------------------------------------------------------
Energies,States = oq.MaxCut_Energy( Vert,Edge )
EV = -100
EV_old = -1000
EV_max = -1
#========================================================
beta = []
gamma = []
for pp in np.arange(p):
    beta.append(2*m.pi*random.random())
    gamma.append(2*m.pi*random.random())
s = 0
while( abs( EV - EV_old ) > delta ):
    q = QuantumRegister(len(Vert))
    qc= QuantumCircuit(q)
    for hh in np.arange(len(Vert)):
        qc.h( q[int(hh)] )
    if( s != 0 ):
        beta,gamma = oq.p_Gradient_Ascent(qc,q,oq.MaxCut_Circuit,Vert,Edge,p,beta,gamma,epsilon,Energies,step_size)
    for i in np.arange(p):
        oq.MaxCut_Circuit( qc, q, Vert, Edge, beta[i], gamma[i] )
#-------------------------------
    EV_old = EV
    EV = oq.E_Expectation_Value( qc, Energies )
    if( EV_old > EV ):
        EV_old = EV
    if( EV > EV_max ):
        Params = [beta,gamma]
        EV_max = EV
    s = int(s+1)
#-------------------------------
    if( (m.floor( s/10 ) == s/10) or (s == 1) ):
        params_string = ''
        for ps in np.arange(p):
            params_string = params_string + ' \u03B3'+str(int(ps+1))+' = '+str(round(gamma[ps],6))+'   \u03B2'+str(int(ps+1))+' = '+str(round(beta[ps],6)) + ' '
        params_string = params_string+' steps: '+str(s)
        print('F(\u03B3,\u03B2): ',EV,' |',params_string)
print('\n _____ Terminated Gradient Ascent _____ \n')
params_string = ''
for ps in np.arange(p):
    params_string = params_string + ' \u03B3'+str(int(ps+1))+' = '+str(round(gamma[ps],6))+' \u03B2'+str(int(ps+1))+' = '+str(round(beta[ps],6)) + ' '
params_string = params_string+' steps: '+str(s)
print('F(\u03B3,\u03B2): ',EV,' |',params_string,'\n')
#=========================================================
beta = Params[0]
gamma = Params[1]
p = len( Params[0] )
#------------------------------
q = QuantumRegister(len(Vert))
qc= QuantumCircuit(q)
for hh in np.arange(len(Vert)):
    qc.h( q[int(hh)] )
for i in np.arange(p):
    oq.MaxCut_Circuit( qc, q, Vert, Edge, beta[i], gamma[i] )
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
oq.Top_States(States,Energies,SV,12)


size = 100
#-------------------------------------------------------
Vert = [ 0,1,2,3,4,5 ]
Edge = [ [0,1],[0,2],[0,5],[1,2],[1,3],[2,3],[2,4],[3,5] ]
#-------------------------------------------------------
Energies,States = oq.MaxCut_Energy( Vert,Edge )
EV_grid = np.zeros(shape=(size,size))
EV_max = -1
#========================================================
for b in np.arange(size):
    beta = round(2*m.pi*(b/size),4)
    for g in np.arange(size):
        gamma = round(2*m.pi*(g/size),4)
        q = QuantumRegister(len(Vert))
        qc= QuantumCircuit(q)
        for hh in np.arange(len(Vert)):
            qc.h( q[int(hh)] )
        oq.MaxCut_Circuit( qc, q, Vert, Edge, beta, gamma )
        EV = oq.E_Expectation_Value( qc, Energies )
        EV_grid[b,g] = EV
        if( EV > EV_max ):
            Params = [beta,gamma]
            EV_max = EV
print('Energy Expectation Value: ',EV_max,' \u03B3 = ',Params[1],' \u03B2 = ',Params[0],'\n')
#--------------------------------------
fig, ax = plt.subplots()
show_text = False
show_ticks = False
oq.Heatmap(EV_grid, show_text, show_ticks, ax, "plasma", "Energy Expectation Value")
fig.tight_layout()
plt.show()
#======================================
beta = Params[0]
gamma = Params[1]
#--------------------------------------
q = QuantumRegister(len(Vert))
qc= QuantumCircuit(q)
for hh in np.arange(len(Vert)):
    qc.h( q[int(hh)] )
oq.MaxCut_Circuit( qc, q, Vert, Edge, beta, gamma )
SV = oq.execute( qc, S_simulator, shots=1 ).result().get_statevector()
oq.Top_States(States,Energies,SV,12)

