Skip to content

Sourcery refactored main branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Aug 11, 2023

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from qqmath August 11, 2023 19:40
Comment thread Pyfiles/circuits.py
Comment on lines -11 to +36

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

if repeat!=0:
qc.barrier(qr)

for l in range(L):

for _ in range(L):
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit1 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -47 to +76

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
qc.cx(qr[3],qr[2])
qc.cx(qr[2],qr[1])
qc.cx(qr[1],qr[0])
if repeat!=0:


if repeat!=0:
qc.barrier(qr)
for l in range(L):

for _ in range(L):
qc.cx(qr[1],qr[0])
qc.cx(qr[2],qr[1])
qc.cx(qr[3],qr[2])

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit2 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -91 to +124

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
qc.crz(theta[count],qr[3],qr[2])
count=count+1
count=count+1
qc.crz(theta[count],qr[2],qr[1])
count=count+1
count=count+1
qc.crz(theta[count],qr[1],qr[0])
count=count+1

if repeat!=0:
if repeat!=0:
qc.barrier(qr)


for l in range(L):



for _ in range(L):
qc.crz(theta[count],qr[1],qr[0])
count=count+1
count=count+1
qc.crz(theta[count],qr[2],qr[1])
count=count+1
count=count+1
qc.crz(theta[count],qr[3],qr[2])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit3 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -140 to +172

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

count=0
for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
qc.crx(theta[count],qr[3],qr[2])
count=count+1
count=count+1
qc.crx(theta[count],qr[2],qr[1])
count=count+1
count=count+1
qc.crx(theta[count],qr[1],qr[0])
count=count+1

if repeat!=0:
if repeat!=0:
qc.barrier(qr)


for l in range(L):



for _ in range(L):
qc.crx(theta[count],qr[1],qr[0])
count=count+1
count=count+1
qc.crx(theta[count],qr[2],qr[1])
count=count+1
count=count+1
qc.crx(theta[count],qr[3],qr[2])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit4 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -191 to +241

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1


for j in range(4):
for i in range(4):
if i!=j:
qc.crz(theta[count],qr[3-j],qr[3-i])
count=count+1



for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1


for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
if repeat!=0:

if repeat!=0:
qc.barrier(qr)


for l in range(L):



for _ in range(L):
for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1


for j in range(4):
for i in range(4):
if i!=j:
qc.crz(theta[count],qr[j],qr[i])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit5 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -993 to +982

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):
for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit16 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -1044 to +1031

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):
for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit17 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -1099 to +1084

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit18 refactored with the following changes:

Comment thread Pyfiles/circuits.py
Comment on lines -1157 to +1139

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],qr[i])
count=count+1

for i in range(4):
qc.rz(theta[count],qr[i])
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit19 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -9 to +33

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1
for i in range(4):
qc.rz(theta[count],i)
count=count+1

if repeat!=0:

for l in range(L):

for _ in range(L):
for i in range(4):
qc.rz(theta[count],i)
count=count+1

for i in range(4):
qc.rx(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit1 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -44 to +73

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
qc.cx(3,2)
qc.cx(2,1)
qc.cx(1,0)


if repeat!=0:

for l in range(L):


if repeat!=0:

for _ in range(L):
qc.cx(1,0)
qc.cx(2,1)
qc.cx(3,2)

for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit2 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -88 to +121

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
qc.crz(theta[count],3,2)
count=count+1
count=count+1
qc.crz(theta[count],2,1)
count=count+1
count=count+1
qc.crz(theta[count],1,0)
count=count+1

if repeat!=0:


if repeat!=0:

for l in range(L):


for _ in range(L):
qc.crz(theta[count],1,0)
count=count+1
count=count+1
qc.crz(theta[count],2,1)
count=count+1
count=count+1
qc.crz(theta[count],3,2)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit3 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -137 to +169

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

count=0
for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
qc.crx(theta[count],3,2)
count=count+1
count=count+1
qc.crx(theta[count],2,1)
count=count+1
count=count+1
qc.crx(theta[count],1,0)
count=count+1

if repeat!=0:


if repeat!=0:

for l in range(L):


for _ in range(L):
qc.crx(theta[count],1,0)
count=count+1
count=count+1
qc.crx(theta[count],2,1)
count=count+1
count=count+1
qc.crx(theta[count],3,2)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit4 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -188 to +238

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],i)
count=count+1


for j in range(4):
for i in range(4):
if i!=j:
qc.crz(theta[count],3-j,3-i)
count=count+1



for i in range(4):
qc.rx(theta[count],i)
count=count+1


for i in range(4):
qc.rz(theta[count],i)
count=count+1

if repeat!=0:



for l in range(L):

if repeat!=0:



for _ in range(L):
for i in range(4):
qc.rz(theta[count],i)
count=count+1

for i in range(4):
qc.rx(theta[count],i)
count=count+1


for j in range(4):
for i in range(4):
if i!=j:
qc.crz(theta[count],j,i)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit5 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -259 to +306

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat


count=0
for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rz(theta[count],i)
count=count+1


for j in range(4):
for i in range(4):
if i!=j:
qc.crx(theta[count],3-j,3-i)
count=count+1



for i in range(4):
qc.rx(theta[count],i)
count=count+1


for i in range(4):
qc.rz(theta[count],i)
count=count+1

if repeat!=0:



for l in range(L):

if repeat!=0:



for _ in range(L):
for i in range(4):
qc.rz(theta[count],i)
count=count+1

for i in range(4):
qc.rx(theta[count],i)
count=count+1


for j in range(4):
for i in range(4):
if i!=j:
qc.crx(theta[count],j,i)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1
count=count+1
for i in range(4):
qc.rx(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit6 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -1041 to +1028

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):
for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit17 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -1096 to +1081

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit18 refactored with the following changes:

Comment thread Pyfiles/circuits_n1.py
Comment on lines -1154 to +1136

# repeat will conjugate the first part and add next the the circuit for expressibility
# 0:No, 1: Repeat

count=0

for l in range(L):

for _ in range(L):
for i in range(4):
qc.rx(theta[count],i)
count=count+1

for i in range(4):
qc.rz(theta[count],i)
count=count+1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function circuit19 refactored with the following changes:

Comment thread Pyfiles/experiments.py
r'''A helper function which makes the classfier circuits.
Given an ID, it returns the PQC.'''
param_y=[(Parameter('θ'+str(i))) for i in range(40)]
param_y = [Parameter(f'θ{str(i)}') for i in range(40)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_classifer_circuit refactored with the following changes:

Comment thread Pyfiles/experiments.py
data = list(zip(dataCoords, 2*dataLabels-1))

return data
return list(zip(dataCoords, 2*dataLabels-1))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function load_data refactored with the following changes:

This removes the following comments ( why? ):

# for shuffling.
# Also, notice we change the data labels from {0, 1} to {-1, +1}
# Make a data structure which is easier to work with

Comment thread Pyfiles/experiments.py
Comment on lines -149 to +144
np.random.seed(0)
np.random.seed(0)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function train_model refactored with the following changes:

Comment thread Pyfiles/optimizer.py
Comment on lines -19 to +23
gradient = (loss(currentParams + gradientCoefficient*randomPerturbation) - loss(currentParams - gradientCoefficient*randomPerturbation))\
/(gradientCoefficient*randomPerturbation)

return gradient

return (
loss(currentParams + gradientCoefficient * randomPerturbation)
- loss(currentParams - gradientCoefficient * randomPerturbation)
) / (gradientCoefficient * randomPerturbation)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SPSA_gradient refactored with the following changes:

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -54 to +56
val=k.most_common(1)[0][0]
val=k.most_common(1)[0][0]
list1=['00','11'];
if val in list1:
ypredit=-1
else:
ypredit=1
return ypredit
return -1 if val in list1 else 1
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convertv refactored with the following changes:

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -100 to +96
predict=convertv(count)
return predict
return convertv(count)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Qrun refactored with the following changes:

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -115 to +110
def loss2qubit(datainput,datalabel,currentParams):
def loss2qubit(datainput,datalabel,currentParams):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function loss2qubit refactored with the following changes:

This removes the following comments ( why? ):

# how many qubit?
#number of shots on simulation

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -134 to +126
def quick_predict(datainput,currentParams):
def quick_predict(datainput,currentParams):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function quick_predict refactored with the following changes:

This removes the following comments ( why? ):

# how many qubit?
#number of shots on simulation

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -169 to +160
val=k.most_common(1)[0][0]
val=k.most_common(1)[0][0]
list1=['0000','0001','0010','0011','1100','1101','1110','1111'];
if val in list1:
ypredit=-1
else:
ypredit=1
return ypredit
return -1 if val in list1 else 1
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert_qubitF refactored with the following changes:

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -192 to +177
predict=convert_qubitF(count)
return predict
return convert_qubitF(count)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Qrun_qubitF refactored with the following changes:

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -197 to +181
def loss_qubitF(datainput,datalabel,currentParams,circuit):
def loss_qubitF(datainput,datalabel,currentParams,circuit):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function loss_qubitF refactored with the following changes:

This removes the following comments ( why? ):

# how many qubit?
#number of shots on simulation

Comment thread Pyfiles/quantumcircuit.py
Comment on lines -216 to +197
def predict_qubitF(datainput,currentParams,circuit):
def predict_qubitF(datainput,currentParams,circuit):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function predict_qubitF refactored with the following changes:

This removes the following comments ( why? ):

# how many qubit?
#number of shots on simulation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants