Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a shift to colswap in _perform_row_operations #3

Merged
merged 1 commit into from
Jun 16, 2024

Conversation

manuelgpda
Copy link
Contributor

When performing operations on the bimatrices of Code objects for finding the standard form one needed to take into account the shift given by start_row. This comes from the fact that first, one finds the rref of the left sub matrix A and then the rref of the right sub sub matrix E. After finding A, one needs to shift the row operations we are performing a number of start_row=self.rankx elements to the right so one does not mess with the identity that is on the left already and this was implemented in the code as it should. However, one should also shift the column operations in order to avoid messing with the aforementioned identity and this was not considered in the code.

I don't believe though that this sole change will fix #2 .

@abdullahkhalids
Copy link
Owner

Thank you. Does this fix encoding for the codes in the notebook linked in issue #2 ?

@manuelgpda
Copy link
Contributor Author

I think that this does not fix #2 but I have not checked in depth.

@abdullahkhalids
Copy link
Owner

I agree that this is likely a correct partial fix to the algorithm. But I would like some justification. Did you try it with any code, where the change improved things?

@manuelgpda
Copy link
Contributor Author

Yes, if you try:

def get_generator_matrix(stabilisers):
    generator_matrix_list = []
    for jj,stab in enumerate(stabilisers):
        row = [0]*2*len(stab)
        for ii,letter in enumerate(stab):
            if letter == 'X':
                row[ii] = 1
            if letter == 'Z':
                row[len(stab) + ii] = 1
            if letter == 'Y':
                row[ii] = 1
                row[len(stab) + ii] = 1
        generator_matrix_list.append(row)
    return np.array(generator_matrix_list)

generators = ['IYZXIIIXZYII', 'IXZYIIIYZXII']
gm = get_generator_matrix(generators)
cd_rep = stac.Code(gm)
st = cd_rep.construct_standard_form()
print('r:',cd_rep.rankx)
print('X submatrix:')
print(st[0])
print('Z submatrix:')
print(st[1])

The output will be:

r: 1
X submatrix:
[[0 0 1 1 0 0 0 1 0 1 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0]]
Z submatrix:
[[1 0 1 0 0 0 0 0 1 1 0 0]
 [0 0 1 1 0 0 0 1 0 1 0 0]]

And this makes no sense since r=1 implies that the X sub matrix has to have an identity sub matrix of size 1x1 and the very left. However, after implementing #3 , the output will be:

r: 1
X submatrix:
[[1 1 0 0 0 0 0 1 0 1 0 0]
 [0 0 0 0 0 0 0 0 0 0 0 0]]
Z submatrix:
[[1 0 1 0 0 0 0 0 1 1 0 0]
 [1 1 0 0 0 0 0 1 0 1 0 0]]

@abdullahkhalids
Copy link
Owner

Excellent. This looks correct. I will accept this in a couple of weeks, because I am in the middle of teaching a workshop that uses stac, and there will be some confusion.

Thanks for the contribution.

@abdullahkhalids abdullahkhalids merged commit 2428f7c into abdullahkhalids:main Jun 16, 2024
@abdullahkhalids
Copy link
Owner

Thanks.

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.

Encoding circuits are incorrect
2 participants