In [1]:
import numpy as np
import numpy as m
# Importing standard Qiskit libraries
from qiskit import QuantumCircuit, transpile, Aer, IBMQ
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from ibm_quantum_widgets import *
from qiskit.providers.aer import QasmSimulator
from qiskit import BasicAer


# Loading your IBM Quantum account(s)
provider = IBMQ.load_account()
<frozen importlib._bootstrap>:219: RuntimeWarning: scipy._lib.messagestream.MessageStream size changed, may indicate binary incompatibility. Expected 56 from C header, got 64 from PyObject

Library

In [2]:
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit, Aer, execute
from qiskit.extensions.simulator import snapshot
from qiskit.tools.visualization import circuit_drawer
import numpy as np
import math as m
import scipy as sci
import random
import time
import matplotlib
import matplotlib.pyplot as plt
S_simulator = Aer.backends(name='statevector_simulator')[0]
M_simulator = Aer.backends(name='qasm_simulator')[0]

#===============================================
#----------- Math Operations -----------
#===============================================
def Binary(N, total, LSB):
    '''
    Input: N (integer) total (integer) LSB (string)
    Returns the base-2 binary equivilant of N according to left or right least significant bit notation
    '''
    qubits = int(m.log(total,2))
    b_num = np.zeros(qubits)
    for i in np.arange(qubits):
        if( N/((2)**(qubits-i-1)) >= 1 ):
            if(LSB=='R'):
                b_num[i] = 1
            if(LSB=='L'):
                b_num[int(qubits-(i+1))] = 1
            N = N - 2**(qubits-i-1)
    B = []
    for j in np.arange(len(b_num)):
        B.append(int(b_num[j]))
    return B

def QFT(qc, q, qubits, **kwargs):
    '''
    Input: qc (QuantumCircuit) q (QuantumRegister) qubits (integer)
    Keyword Arguments: swap (Bool) - Adds SWAP gates after all of the phase gates have been applied
    Assigns all the gate operations for a Quantum Fourier Transformation
    '''
    R_phis = [0]
    for i in np.arange(2,int(qubits+1)):
        R_phis.append( 2/(2**(i)) * m.pi )
    for j in np.arange(int(qubits)):
        qc.h( q[int(j)] )
        for k in np.arange(int(qubits-(j+1))):
            qc.cu1( R_phis[k+1], q[int(j+k+1)], q[int(j)] )
    if 'swap' in kwargs:
        if(kwargs['swap'] == True):
            for s in np.arange(m.floor(qubits/2.0)):
                qc.swap( q[int(s)],q[int(qubits-1-s)] )
#==================================================
#----------- Displaying Results -----------
#==================================================


def Wavefunction(obj, **kwargs):
    '''
    Prints a tidier version of the array statevector corresponding to the wavefuntion of a QuantumCircuit object
    Keyword Arguments: precision (integer) - the decimal precision for amplitudes
    column (Bool) - prints each state in a vertical column
    systems (array of integers) - seperates the qubits into different states
    show_systems (array of Bools) - indictates which qubit systems to print
    '''
    if(type(obj) == QuantumCircuit ):
        statevec = execute( obj, S_simulator, shots=1 ).result().get_statevector()
    if(type(obj) == np.ndarray):
        statevec = obj
    sys = False
    NL = False
    dec = 5
    if 'precision' in kwargs:
       dec = int( kwargs['precision'] )
    if 'column' in kwargs:
       NL = kwargs['column']
    if 'systems' in kwargs:
        systems = kwargs['systems']
        sys = True
        last_sys = int(len(systems)-1)
        show_systems = []
        for s_chk in np.arange(len(systems)):
            if( type(systems[s_chk])!=int ):
                raise Exception('systems must be an array of all integers')
        if 'show_systems' in kwargs:
            show_systems = kwargs['show_systems']
            if( len(systems)!=len(show_systems) ):
                raise Exception('systems and show_systems need to be arrays of equal length')
            for ls in np.arange(len(show_systems)):
                if((show_systems[ls]!=True)and(show_systems[ls]!=False)):
                    raise Exception('show_systems must be an array of Truth Values')
                if(show_systems[ls]==True):
                    last_sys = int(ls)
        else:
            for ss in np.arange(len(systems)):
                show_systems.append(True)
                
    wavefunction = ''
    qubits = int(m.log(len(statevec),2))
    for i, comp in  enumerate(statevec): #i in np.arange( int(len(statevec)) ):
        value = round(comp.real, dec) + round(comp.imag, dec) * 1j
        if( (value.real != 0) or (value.imag != 0) ):
            state = list( Binary(int(i), int(2**qubits) ,'L') )
            state_str = ''
            if( sys == True ):
                k = 0
                for s in np.arange(len(systems)):
                    if(show_systems[s]==True):
                        if(int(s)!=last_sys):
                            state.insert( int(k+systems[s]),'>|' )
                            k = int(k+systems[s]+1)
                        else:
                            k = int(k+systems[s])
                    else:
                        for s2 in np.arange(systems[s]):
                            del state[int(k)]
            for j in np.arange(len(state)):
                if(type(state[j])!=str):
                    state_str = state_str+str(int(state[j]))
                else:
                    state_str = state_str+state[j]
            if( (value.real != 0) and (value.imag != 0) ):
                if( value.imag > 0):
                     wavefunction = wavefunction + str(value.real) + '+' + str(value.imag) + 'j |' + state_str + '>  '
                else:
                     wavefunction = wavefunction +str(value.real)+''+str(value.imag)+'j |'+state_str+'>  '
            if( (value.real!=0) and (value.imag==0) ):
                wavefunction = wavefunction + str(value.real) + ' |' + state_str + '>  '
            if( (value.real==0) and (value.imag!=0) ):
                wavefunction = wavefunction +str(value.imag)+'j |'+state_str+'> '
            if(NL):
                wavefunction = wavefunction + '\n'
    print(wavefunction)


def Wavefunction_orig_modified(obj, **kwargs):
    '''
     Prints a tidier version of the array statevector corresponding to the wavefuntion of a QuantumCircuit object
     Keyword Arguments: precision (integer) - the decimal precision for amplitudes
    column (Bool) - prints each state in a vertical column
    systems (array of integers) - seperates the qubits into different states
    show_systems (array of Bools) - indictates which qubit systems to print
    '''
    if(type(obj) == QuantumCircuit ):
        statevec = execute( obj, S_simulator, shots=1 ).result().get_statevector()
    if(type(obj) == np.ndarray):
        statevec = obj
    sys = False
    NL = False
    dec = 5
    if 'precision' in kwargs:
       dec = int( kwargs['precision'] )
    if 'column' in kwargs:
       NL = kwargs['column']
    if 'systems' in kwargs:
        systems = kwargs['systems']
        sys = True
        last_sys = int(len(systems)-1)
        show_systems = []
        for s_chk in np.arange(len(systems)):
            if( type(systems[s_chk])!=int ):
                raise Exception('systems must be an array of all integers')
        if 'show_systems' in kwargs:
            show_systems = kwargs['show_systems']
            if( len(systems)!=len(show_systems) ):
                raise Exception('systems and show_systems need to be arrays of equal length')
            for ls in np.arange(len(show_systems)):
                if((show_systems[ls]!=True)and(show_systems[ls]!=False)):
                    raise Exception('show_systems must be an array of Truth Values')
                if(show_systems[ls]==True):
                    last_sys = int(ls)
        else:
            for ss in np.arange(len(systems)):
                show_systems.append(True)
    wavefunction = ''
    qubits = int(m.log(len(statevec),2))
    for i, comp in  enumerate(statevec): #i in np.arange( int(len(statevec)) ):
        value = round(comp.real, dec) + round(comp.imag, dec) * 1j
        if( (value.real != 0) or (value.imag != 0) ):
            state = list(Binary(int(i), int(2**qubits) ,'L') )

            state_str = ''
            if( sys == True ):
                k = 0
                for s in np.arange(len(systems)):
                    if(show_systems[s]==True):
                        if(int(s)!=last_sys):
                            state.insert( int(k+systems[s]),'>|' )
                            k = int(k+systems[s]+1)
                        else:
                            k = int(k+systems[s])
                    else:
                        for s2 in np.arange(systems[s]):
                            del state[int(k)]
            for j in np.arange(len(state)):
                if(type(state[j])!=str):
                    state_str = state_str+str(int(state[j]))
                else:
                    state_str = state_str+state[j]
                if( (value.real != 0) and (value.imag != 0) ):
                    if( value.imag > 0):
                        wavefunction = wavefunction + str(value.real) + '+' + str(value.imag) + 'j |' + state_str + '> '
                    else:
                        wavefunction = wavefunction +str(value.real)+''+str(value.imag)+'j |'+state_str+'> '
                if( (value.real!=0) and (value.imag==0) ):
                    wavefunction = wavefunction + str(value.real) + ' |' + state_str + '>'
                if( (value.real==0) and (value.imag!=0) ):
                    wavefunction = wavefunction +str(value.imag)+'j |'+state_str+'> '
                if(NL):
                    wavefunction = wavefunction + '\n'
    print(wavefunction)
    
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit, Aer, execute
import numpy as np
import math as m
import scipy as sci

S_simulator = Aer.backends(name='statevector_simulator')[0]
M_simulator = Aer.backends(name='qasm_simulator')[0] 

#Displaying Results 
def Wavefunction_new( obj , *args, **kwargs):
#Displays the waveftmction of the quantum system 
    if(type(obj) == QuantumCircuit ):
        statevec = execute( obj, S_simulator, shots=1 ).result().get_statevector()
    if(type(obj) == np.ndarray):
        statevec = obj
    sys = False
    NL = False
    dec = 5
    if 'precision' in kwargs:
        dec = int( kwargs['precision'] )
    if 'column' in kwargs:
        NL = kwargs['column']
    if 'systems' in kwargs:
        systems = kwargs['systems']
        sys = True
        last_sys = int(len(systems)-1)
        show_systems = []
        for s_chk in np.arange(len(systems)):
            if( type(systems[s_chk]) != int ):
                raise Exception('systems must be an array of all integers')
        if 'show_systems' in kwargs:
            show_systems = kwargs['show_systems']
            if( len(systems)!= len(show_systems) ):
                raise Exception('systems and show_systems need to be arrays of equal length')
            for ls in np.arange(len(show_systems)):
                if((show_systems[ls] != True) and (show_systems[ls] != False)):
                    raise Exception('show_systems must be an array of Truth Values')
                if(show_systems[ls] == True):
                    last_sys = int(ls) 
        else:
            for ss in np.arange(len(systems)):
                show_systems.append(True)
    wavefunction = ''
    qubits = int(m.log(len(statevec),2))
    for i, comp in  enumerate(statevec): #i in np.arange( int(len(statevec)) ):
        value = round(comp.real, dec) + round(comp.imag, dec) * 1j 
#    for i in np.arange( int(len(statevec))):
        #print(wavefunction)
#        value = round(statevec[i].real, dec) + round(statevec[i].imag, dec) * 1j
        if( (value.real != 0) or (value.imag != 0)):
            state = list(Binary(int(i),int(2**qubits)))
            state.reverse()
            state_str = ''
            #print(state)
            if( sys == True ): #Systems and SharSystems 
                k = 0 
                for s in np.arange(len(systems)):
                    if(show_systems[s] == True):
                        if(int(s) != last_sys):
                            state.insert(int(k + systems[s]), '>|' )
                            k = int(k + systems[s] + 1)
                        else:
                            k = int(k + systems[s]) 
                    else:
                        for s2 in np.arange(systems[s]):
                            del state[int(k)]
            for j in np.arange(len(state)):
                if(type(state[j])!= str):
                    state_str = state_str + str(int(state[j])) 
                else:
                    state_str = state_str + state[j]
            #print(state_str)
            #print(value)
            if( (value.real != 0) and (value.imag != 0) ):
                if( value.imag > 0):
                    wavefunction = wavefunction + str(value.real) + '+' + str(value.imag) + 'j |' + state_str + '>   '
                else:
                    wavefunction = wavefunction + str(value.real) + '' + str(value.imag) + 'j |' + state_str +  '>   '
            if( (value.real !=0 ) and (value.imag ==0) ):
                wavefunction = wavefunction  + str(value.real) + '  |' + state_str + '>   '
            if( (value.real == 0) and (value.imag != 0) ):
                wavefunction = wavefunction + str(value.imag)  + 'j |' + state_str + '>   '
            if(NL):
                wavefunction = wavefunction + '\n'
        #print(NL)
    
    print(wavefunction)
    #return wavefunction
    
def QFT(qc, q, qubits, **kwargs):
    '''
    Input: qc (QuantumCircuit) q (QuantumRegister) qubits (integer)
    Keyword Arguments: swap (Bool) - Adds SWAP gates after all of the phase gates have been applied
    Assigns all the gate operations for a Quantum Fourier Transformation
    '''
    R_phis = [0]
    for i in np.arange(2,int(qubits+1)):
        R_phis.append( 2/(2**(i)) * m.pi )
    for j in np.arange(int(qubits)):
        qc.h( q[int(j)] )
        for k in np.arange(int(qubits-(j+1))):
            qc.cu1( R_phis[k+1], q[int(j+k+1)], q[int(j)] )
    if 'swap' in kwargs:
        if(kwargs['swap'] == True):
            for s in np.arange(m.floor(qubits/2.0)):
                qc.swap( q[int(s)],q[int(qubits-1-s)] )

def QFT_dgr(qc, q, qubits, **kwargs):
    '''
    Input: qc (QuantumCircuit) q (QuantumRegister) qubits (integer)
    Keyword Arguments: swap (Bool) - Adds SWAP gates after all of the phase gates have been applied
    Assigns all the gate operations for a Quantum Fourier Transformation
    '''
    if 'swap' in kwargs:
        if(kwargs['swap'] == True):
            for s in np.arange(m.floor(qubits/2.0)):
                qc.swap( q[int(s)],q[int(qubits-1-s)] )
    R_phis = [0]
    for i in np.arange(2,int(qubits+1)):
        R_phis.append( -2/(2**(i)) * m.pi )
    for j in np.arange(int(qubits)):
        for k in np.arange(int(j)):
            qc.cu1(R_phis[int(j-k)], q[int(qubits-(k+1))], q[int(qubits-(j+1))] )
        qc.h( q[int(qubits-(j+1))] )
        
def DFT(x, **kwargs):
    '''
    Input: x (array)
    Keyword Arguments: inverse (Bool) - if True, performs a Inverse Discrete Fourier Transformation instead
    Computes a classical Discrete Fourier Transformation on the array of values x, returning a new array of transformed val
    '''
    p = -1.0
    if 'inverse' in kwargs:
        P = kwargs['inverse']
        if(P == True):
            p = 1.0
    L = len(x)
    X = []
    for i in np.arange(L):
        value = 0
        for j in np.arange(L):
            value = value + x[j]*np.exp(p*2*m.pi*1.0j * ( int(i*j)/(L*1.0) ) )
        X.append(value)
    for k in np.arange(len(X)):
        re = round(X[k].real,5)
        im = round(X[k].imag,5)
        if( (abs(im) == 0) and (abs(re) != 0) ):
            X[k] = re
        elif( (abs(re) == 0) and (abs(im) != 0) ):
            X[k] = im*1.0j
        elif( (abs(re) == 0) and (abs(im) == 0) ):
            X[k] = 0
        else:
            X[k] = re + im*1.0j
    return X


#=================================================
#----------- Custom Operations -----------
#=================================================
def X_Transformation(qc, qreg, state):
    '''
    Input: qc (QuantumCircuit) qreg (QuantumRegister) state (array)
    Applies the neccessary X gates to transform 'state' to the state of all 1's
    '''
    for j in np.arange(len(state)):
        if( int(state[j])==0 ):
            qc.x( qreg[int(j)] )
            
#==========================================================
#----------- Lesson 6.1 - Quantum Adder ------------
#==========================================================
def Quantum_Adder(qc, Qa, Qb, A, B):
    '''
    Input: qc (QuantumCircuit) Qa (QuantumRegister) Qb (QuantumRegister) A (array) B (array)
    Appends all of the gate operations for a QFT based addition of two states A and B
    '''
    Q = len(B)
    for n in np.arange(Q):
        if( A[n] == 1 ):
            qc.x( Qa[int(n+1)] )
        if( B[n] == 1 ):
            qc.x( Qb[int(n)] )
    QFT(qc,Qa,Q+1)
    p = 1
    for j in np.arange( Q ):
        qc.cu1( m.pi/(2**p), Qb[int(j)], Qa[0] )
        p = p + 1
    for i in np.arange(1,Q+1):
        p = 0
        for jj in np.arange( i-1, Q ):
            qc.cu1( m.pi/(2**p), Qb[int(jj)], Qa[int(i)] )
            p = p + 1
    QFT_dgr(qc,Qa,Q+1)

Unitary operator

image.png image.png

In [4]:
alpha = 2*m.pi/3
U = np.array([ [ np.cos(alpha) , np.sin(alpha) ],
[ -np.sin(alpha) , np.cos(alpha) ] ])
#---------------------------------------------------
e = 0.5*(-1+m.sqrt(3)*1.0j)
v = 1.0/m.sqrt(2)*np.array( [-1.0j,1] )
#---------------------------------------------------
print('____ Unitary Matrix ____\n',U)
print( '\n U |u> = ',np.dot(U,v))
print( 'e^{2\u03C0i\u03C6} |u> = ',e * v)
____ Unitary Matrix ____
 [[-0.5        0.8660254]
 [-0.8660254 -0.5      ]]

 U |u> =  [ 0.61237244+0.35355339j -0.35355339+0.61237244j]
e^{2πiφ} |u> =  [ 0.61237244+0.35355339j -0.35355339+0.61237244j]

image.png

A. Y. Kitaev, "Quantum measurements and the Abelian Stabilizer Problem", arXiv:9511026 (1995)

image.png

image.png

image.png

image.png

image.png image.png

QFT^\dagger

image.png image.png

image.png

image.png

image.pngdownload.png

In [5]:
q = QuantumRegister(3,name='q' )
qc= QuantumCircuit(q,name='qc')
#-------------------------------
qc.x( q[1] )
qc.x( q[2] )
print('____ Initial State ____')
Wavefunction(qc)
qc.swap( q[0], q[2] )
QFT_dgr( qc,q,3 )
print('\n____ After QFT\u2020 ____')
Wavefunction(qc)
#======================================
print('\n ____ QFT\u2020 Expression ____')
for k in np.arange( 8 ):
    phase = 1.0/(m.sqrt(8)) * np.exp( -1.0j*m.pi*( (3*k)/4 ) )
    print( 'state: ',Binary(int(k),8,'R'),' phase: ',round(phase.real,4)+round(phase.imag,4)*1.0j )
____ Initial State ____
1.0 |011>  

____ After QFT† ____
0.35355 |000>  -0.35355 |100>  0.35355j |010> -0.35355j |110> -0.25-0.25j |001>  0.25+0.25j |101>  0.25-0.25j |011>  -0.25+0.25j |111>  

 ____ QFT† Expression ____
state:  [0, 0, 0]  phase:  (0.3536+0j)
state:  [0, 0, 1]  phase:  (-0.25-0.25j)
state:  [0, 1, 0]  phase:  0.3536j
state:  [0, 1, 1]  phase:  (0.25-0.25j)
state:  [1, 0, 0]  phase:  (-0.3536+0j)
state:  [1, 0, 1]  phase:  (0.25+0.25j)
state:  [1, 1, 0]  phase:  -0.3536j
state:  [1, 1, 1]  phase:  (-0.25+0.25j)
/tmp/ipykernel_59/1482679176.py:99: DeprecationWarning: The return type of saved statevectors has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.Statevector` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using  `np.asarray(object)`.
  qubits = int(m.log(len(statevec),2))
/tmp/ipykernel_59/1482679176.py:100: DeprecationWarning: The return type of saved statevectors has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.Statevector` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using  `np.asarray(object)`.
  for i, comp in  enumerate(statevec): #i in np.arange( int(len(statevec)) ):
/tmp/ipykernel_59/1482679176.py:335: DeprecationWarning: The QuantumCircuit.cu1 method is deprecated as of 0.16.0. It will be removed no earlier than 3 months after the release date. You should use the QuantumCircuit.cp method instead, which acts identically.
  qc.cu1(R_phis[int(j-k)], q[int(qubits-(k+1))], q[int(qubits-(j+1))] )

image.png

Example: 𝑗 = 6 𝑛 = 3

image.png

image.png

image.png

image.png image.png

image.png

Measurement on this system is promised to reveal the phase with high probability !!!

In [6]:
n = 3
q1 = QuantumRegister(n,name='q1')
q2 = QuantumRegister(1,name='q2')
qc = QuantumCircuit(q1,q2,name='qc')
theta = 0.52
phi = 2*m.pi*theta
#---------------------------------------------------
for i in np.arange(n):
    qc.h(q1[int(i)])
qc.x( q2[0] )
for j in np.arange(n):
    for k in np.arange(2**j):
        qc.cu1( phi, q1[int(n-1-j)], q2[0] )
        
print('\n___ After Control-U Operations ___')
Wavefunction( qc, systems=[n,1] )
#---------------------------------------------------

Phases = [np.exp(4.0j*phi),np.exp(2.0j*phi),np.exp(1.0j*phi)]
print(' ')
for i in np.arange(8):
    state = Binary(int(i),8,'R')
    phase = m.sqrt(1/8)
    for j in np.arange(3):
        if(state[j]==1):
            phase = phase*Phases[j]
    print('State: ',state,' Phase: ',round(phase.real,5)+round(phase.imag,5)*1.0j)
___ After Control-U Operations ___
0.35355 |000>|1>  0.30982+0.17033j |100>|1>  0.34245+0.08793j |010>|1>  0.25773+0.24202j |110>|1>  -0.35077-0.04431j |001>|1>  -0.28603-0.20781j |101>|1>  -0.32873-0.13015j |011>|1>  -0.22536-0.27242j |111>|1>  
 
State:  [0, 0, 0]  Phase:  (0.35355+0j)
State:  [0, 0, 1]  Phase:  (-0.35077-0.04431j)
State:  [0, 1, 0]  Phase:  (0.34245+0.08793j)
State:  [0, 1, 1]  Phase:  (-0.32873-0.13015j)
State:  [1, 0, 0]  Phase:  (0.30982+0.17033j)
State:  [1, 0, 1]  Phase:  (-0.28603-0.20781j)
State:  [1, 1, 0]  Phase:  (0.25773+0.24202j)
State:  [1, 1, 1]  Phase:  (-0.22536-0.27242j)
/tmp/ipykernel_59/1985345189.py:13: DeprecationWarning: The QuantumCircuit.cu1 method is deprecated as of 0.16.0. It will be removed no earlier than 3 months after the release date. You should use the QuantumCircuit.cp method instead, which acts identically.
  qc.cu1( phi, q1[int(n-1-j)], q2[0] )
/tmp/ipykernel_59/1482679176.py:99: DeprecationWarning: The return type of saved statevectors has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.Statevector` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using  `np.asarray(object)`.
  qubits = int(m.log(len(statevec),2))
/tmp/ipykernel_59/1482679176.py:100: DeprecationWarning: The return type of saved statevectors has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.Statevector` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using  `np.asarray(object)`.
  for i, comp in  enumerate(statevec): #i in np.arange( int(len(statevec)) ):
In [7]:
n = 3
q1 = QuantumRegister(n,name='q1')
q2 = QuantumRegister(1,name='q2')
c = ClassicalRegister(n,name='c')
qc = QuantumCircuit(q1,q2,c,name='qc')
theta = 0.52
#---------------------------------------------------
for i in np.arange(n):
    qc.h(q1[int(i)])
qc.x( q2[0] )

phi = 2*m.pi*theta
for j in np.arange(n):
    for k in np.arange(2**j):
        qc.cu1( phi, q1[int(n-1-j)], q2[0] )
        
print('\n___ After QFT_dgr ___')
QFT_dgr( qc,q1,n,swap=True )
Wavefunction( qc, systems=[n,1] )
#---------------------------------------------------
qc.measure(q1,c)
results = execute(qc, BasicAer.get_backend('qasm_simulator'), shots=10000).result()
plot_histogram(results.get_counts())
/tmp/ipykernel_59/853297913.py:15: DeprecationWarning: The QuantumCircuit.cu1 method is deprecated as of 0.16.0. It will be removed no earlier than 3 months after the release date. You should use the QuantumCircuit.cp method instead, which acts identically.
  qc.cu1( phi, q1[int(n-1-j)], q2[0] )
/tmp/ipykernel_59/1482679176.py:335: DeprecationWarning: The QuantumCircuit.cu1 method is deprecated as of 0.16.0. It will be removed no earlier than 3 months after the release date. You should use the QuantumCircuit.cp method instead, which acts identically.
  qc.cu1(R_phis[int(j-k)], q[int(qubits-(k+1))], q[int(qubits-(j+1))] )
/tmp/ipykernel_59/1482679176.py:99: DeprecationWarning: The return type of saved statevectors has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.Statevector` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using  `np.asarray(object)`.
  qubits = int(m.log(len(statevec),2))
/tmp/ipykernel_59/1482679176.py:100: DeprecationWarning: The return type of saved statevectors has been changed from a `numpy.ndarray` to a `qiskit.quantum_info.Statevector` as of qiskit-aer 0.10. Accessing numpy array attributes is deprecated and will result in an error in a future release. To continue using saved result objects as arrays you can explicitly cast them using  `np.asarray(object)`.
  for i, comp in  enumerate(statevec): #i in np.arange( int(len(statevec)) ):
___ After QFT_dgr ___
0.02569-0.0546j |000>|1>  0.86777+0.40834j |100>|1>  0.07553-0.02719j |010>|1>  -0.03085-0.08568j |110>|1>  0.04708-0.04284j |001>|1>  -0.12512-0.1375j |101>|1>  0.13673+0.00645j |011>|1>  0.00316-0.06698j |111>|1>  
Out[7]:

image.pngdownload.png