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

Surface code implementation #5

Merged
merged 7 commits into from
Jun 5, 2023

Conversation

JiQing000
Copy link
Contributor

Solutions for issue#1 Implementation of surface codes. Please let me know whether there is any mistake or adjustment required.

Solutions for issue#1 Implementation of surface codes. Please let me know whether there is any mistake or adjustment required.
@abdullahkhalids abdullahkhalids changed the title Add files via upload Surface code implementation May 29, 2023
@abdullahkhalids
Copy link
Owner

abdullahkhalids commented May 31, 2023

This is good starting work. Let me suggest some improvements.

In the current form, the code is not at all taking advantage of stac's abilities for constructing such circuits. Right now, most of the code is just figuring out the indices in a convoluted manner. The whole point of geometric addressing is to avoid doing this, and going mad.

Let us look at Fig 1. of the paper.

image

By drawing the two axes I have labelled each qubit by $(x, y)$. Now, from the diagram it is quite clear that for measurement qubit at $(x,y)$, the $CX$ gates will go between it and the qubits $(x+1,y), (x-1,y), (x,y+1), (x,y-1)$. So how do we do this in stac?

The key is when you create the physical qubits. Right now, you have

surface_code_circ.physical_register.elements = \
    [stac.PhysicalQubit(i, i, []) for i in range(surface_code_circ.num_qubits)]

In stac.PhysicalQubit(i, i, []) the second argument is the coordinate of the physical qubit. So, we want to turn this into $(x_i,y_j)$.

surface_code_circ.physical_register.elements = \
    [stac.PhysicalQubit(row*i + j, (i, j), []) for i in range(row) for j in range(col)]
# double check the first argument.

Next, in the following lines inside the for loop, you are assigning the physical qubits created above to the virtual qubits of the circuit.

surface_code_circ.register[(0,0,i)].constituent_register = surface_code_circ.physical_register.elements[i]
surface_code_circ.layout_map[(0,0,i)] = i

You want to rewrite the two loops, so you are alternatively assigning each physical qubit to either the data register or the syndrome register, as per the diagram.

Once you have done the above, the rest is trivial. Iterate through all the syndrome measurement qubits, look at its coordinates and do the $(x\pm 1, y\pm 1)$ business with the gates.

  • To iterate through the virtual qubits in the syndrome register, just do for qubit in circ.register[(0,1)].qubits()
  • To figure out the coordinates of physical qubit associated with the above virtual qubit, you can do qubit.constituent_register.coordinates
  • With these physical coordinates in hand, add/subtract 1 etc and call geo_append.

This should do the job. I hope the above is clear. If not, please ask.

@abdullahkhalids
Copy link
Owner

abdullahkhalids commented May 31, 2023

Lets also try to write relatively clean code from the start.

  • Move the import statements outside the function call.
  • Actually do a return surface_code_circ at the end of the circuit instead of drawing it. You can move the draw commands outside the function into the script.
  • Add a documentation string to the function.

Thank you for your work.

@JiQing000
Copy link
Contributor Author

Thank you for the clarification! It is very kind of you to let me know all the improvements. I will work on them right away.

@abdullahkhalids abdullahkhalids linked an issue May 31, 2023 that may be closed by this pull request
Hi, I have completed my solution with the requested improvements. Please let me know whether it suits your needs now. Thank you!
@JiQing000
Copy link
Contributor Author

@abdullahkhalids Hi, I have uploaded the revised solution into the files changed. Please let me know whether there is any other improvements and mistake. Thank you!

Hi, I have rewrote the part of creating the circuit. Thank you!
@JiQing000
Copy link
Contributor Author

@abdullahkhalids Hi. The revised 2nd version of the solution is ready for review. Pls let me know whether any other change is required. Thank you!

@abdullahkhalids
Copy link
Owner

I finally found the time to take a look at it. The logic seems sound as far as I have checked.

To finish this PR, kindly make the following minor changes:

  • Kindly delete all files, except the final version, and rename it to surfacecode.py.
  • There is a typo in the first line of the documentation: "syndromeasurement". Fix that.
  • At the absolute top of the file, add a comment "Contributors: YOURFULLNAME " (or any other way of identifying/contacting you).
  • Finally, only if you agree, below that add another comment line "Licensed under GPLV3".

You don't have to do the last thing. But if you do, when I write the Surface Code chapter of the book, I will be able to use this code, and identify you as a contributor to the book.

@JiQing000
Copy link
Contributor Author

Great! Thank you. I will make the changes accordingly, and I would be glad to let you use my code for your amazing book.

@JiQing000
Copy link
Contributor Author

@abdullahkhalids Thank you for the help and guidance. I have made changes according to your requests.

@abdullahkhalids abdullahkhalids merged commit 6a45d1f into abdullahkhalids:main Jun 5, 2023
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.

Implementation of surface codes
2 participants