Create plaquette from RPNG string#411
Conversation
|
Just note typo in the below: z means CZ.
…On Wed, Dec 4, 2024, 10:54 AM giangiac ***@***.***> wrote:
See issue #410 <#410> in the tqec repo.
This PR includes:
- a function to validate the RPNG string
- a function that generates the plaquette given the RPNG string
- a generic and documented interface, so that users will be able to
implement their own translation if they want
------------------------------
Example of a RPNG string and description of the format:
-z1- -z2- -z3- -z4-
rpng rpng rpng rpng
(r) data qubit reset basis or -
(p) data basis for the controlled operation (x means CNOT controlled on
the ancilla and targeting the data qubit, y means CZ)
(n) time step
(g) data qubit measure basis or h or -
Assumptions on the circuit:
- if not otherwise stated, a basis can be {x,y,z}
- the ancilla is always initialized in $\ket{+}$ and measured in the X
basis
- the ancilla is always the control qubit for the CNOT, CY, or CZ gates
------------------------------
You can view, comment on, or merge this pull request online at:
#411
Commit Summary
- 170d22d
<170d22d>
Add notebook to test plaquette generation from RPNG
- 3b33c64
<3b33c64>
Add QubitMap to tqec
- 63ea6dc
<63ea6dc>
Add first draft of create_plaquette_from_rpng_string()
File Changes
(3 files <https://github.com/tqec/tqec/pull/411/files>)
- *A* examples/notebooks/create_plaquette.ipynb
<https://github.com/tqec/tqec/pull/411/files#diff-2acebaf074af1c83762608733ac759463425a03ba5410f7cb5d4431074cab5d4>
(326)
- *M* src/tqec/__init__.py
<https://github.com/tqec/tqec/pull/411/files#diff-5fef3f4318fbce14dddc599168ce5ee45b835ef5a28fc64bfa2d08d364249500>
(1)
- *M* src/tqec/circuit/__init__.py
<https://github.com/tqec/tqec/pull/411/files#diff-3ba34f37721824ea2ebfe69fc3d82b9a9c30802791752aaaf67143f932ebffa6>
(1)
Patch Links:
- https://github.com/tqec/tqec/pull/411.patch
- https://github.com/tqec/tqec/pull/411.diff
—
Reply to this email directly, view it on GitHub
<#411>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAXTCL32HI4FAR6KTI2VD2D5FWJAVCNFSM6AAAAABTA2UEX6VHI2DSMVQWIX3LMV43ASLTON2WKOZSG4YTQNJVGU4TQMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
|
@nelimee I am not sure why the CI/CD is failing. Also, I am thinking if it is worth merging with the canonical form of the circuits expressed as RPNG strings, leaving the general interface for custom compilation for another PR. |
|
Hi Gian,
You need to install and run the pre-commit hooks locally. And the deploy failure is because you did not create the branch under the tqec repository but use your fork instead, it will cause permission issue.
In my opinion, they should be in separate PR. |
|
A few preliminary notes on the current state of the implementation:
|
Would you suggest creating a new branch in the official tqec repo, merge my fork there, and then create a PR internal to tqec? |
Thanks for the early feedback, Adrien. I can wrap the rpng strings into a dataclass to facilitate querying the values of interest. I'll include the validation inside that class, but would not mind keeping its "complex" implementation for the moment (there is no urgency here and no risk of computational slowdowns). |
See for example #412. I think we need a simple and robust representation of a RPNG string, and a RPNGPlaquette, as we might have to use them in several places.
The problem is mostly about code reuse. I think it is better to have most of the validation code in one place, and #412 would need a little bit more flexibility, so I think we shoule have reusable structures if we can. |
Thanks for the concrete example! |
|
The only structures I believe will need to be implemented as scalable
circuits are state cultivation and Y basis measurement and initialization.
These are all terminal structures, with I believe a standard surface code
layer that could be specified using plaquettes to end or begin the
structures that could be used to connect in the usual way.
Best,
Austin.
…On Mon, Dec 9, 2024, 11:54 PM Yiming Zhang ***@***.***> wrote:
I would vote against the 5-character notation. In my mind if you need to go
to a circuit that cannot be expressed with the four character notation, you
probably wouldn't express that circuit using plaquettes in the first place.
For circuits that cannot be represented in a canonical plaquette form, we
return to the issue of whether we should allow specifying a scalable
circuit directly, as an alternative to the template + plaquette method.
This might be necessary if we adhere strictly to the canonical plaquette
definition. However, this approach seems to have a couple of challenges:
- The replacement rules currently only apply to plaquettes. We would
need a new approach to implement pipes.
- The detector computation based on subtemplates won't work with this
approach and would need to be modified.
- The current compilation pipeline heavily relies on the template and
plaquettes, it will need to be changed.
—
Reply to this email directly, view it on GitHub
<#411 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAXTBGBZPZ7DI7Q7AFYRL2E2M25AVCNFSM6AAAAABTA2UEX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZQG4YTAMJSGE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
+1 for careful separation, but I'd be even the happier if we stuck with
just the four character representation exclusively and focused on good
conversion tools for other gate sets.
…On Tue, Dec 10, 2024, 11:00 PM Adrien Suau ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/tqec/plaquette/rpng_description.py
<#411 (comment)>:
> + ----
+ Extended RPNG format:
+
+ The extra field (a) is used together with (p) to determine the 2Q gate involving the
+ ancilla and data qubits. For example:
+ - a=z, p=x --> CNOT controlled by the ancilla and targeting the data
+ - a=z, p=z --> CZ controlled by the ancilla and targeting the data
+ - a=y, p=z --> CY controlled by the data and targeting the ancilla
+ By default a=z.
The extra field:
- is 4 more characters to type each time a user wants a Plaquette,
- makes the code more complex.
We can keep it, but if we do I would advocate for it to be completely
separate from the "normal" RPNG notation. Basically, have RPNG only
represent a 4-character string, and have another class (ERPNG? RPNGA?
RAPNG?) represent the 5-character notation. The 4-character version will
be used extensively in the code, and so it should be easy to read, the
simplest possible, and as robust as possible, which is in my opinion
incompatible with having both the 4- and 5-character approaches in the same
implementation.
—
Reply to this email directly, view it on GitHub
<#411 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAXTETWYTG6LQOF56XXG32E7PJDAVCNFSM6AAAAABTA2UEX6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOJUGQ3TQNZWG4>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
|
@giangiac the goal is to merge that PR as soon as possible to unlock other issues. I'll make a real full review, and we will be able to merge once the review will be addressed. |
nelimee
left a comment
There was a problem hiding this comment.
I think the main point that needs to be changed is the extraction of the Extended RPNG representation outside of the RPNG code. There are also formatting issue, you will have to run pre-commit.
| Note that the ancilla qubit is the last among the PlaquetteQubits and thus | ||
| has index 4, while the data qubits have indices 0-3. |
There was a problem hiding this comment.
I think that currently the standard was to have the ancilla as the first qubit (index 0). Is there any reason to change that?
There was a problem hiding this comment.
Also note that plaquettes on the boundary only have 3 qubits (counting the ancilla). Having a hole in qubit indexing should not be an issue, but I would advocate for not having a hole at all.
There was a problem hiding this comment.
That's a good point.
I just noticed that if I iterate through the SquarePlaquetteQubits the iterator first goes through the data qubits and then the ancilla qubit.
I do not know the consequences of changing that behavior, so I simply adopted that convention.
In the future one may have multiple ancillas to measure a stabilizer (e.g. when connectivity is constrained) so we may have other type of issees then).
There was a problem hiding this comment.
From memory, the iteration order is very much just a detail and is not used anywhere. A good hint that the previous sentence is likely true is that the iteration order is not documented anywhere.
PS: just checked, all_qubits is only used to reduce a circuit to the plaquette's qubits by calling ScheduledCircuit.filter_by_qubits, so the specific ordering does not matter.
There was a problem hiding this comment.
Shall I change the order then (first ancilla, then data)?
There was a problem hiding this comment.
Ok, I just updated the PlaquetteQubits class changing the order of the fields (first syndrome_qubits, then data_qubits) and the __iter__ method.
There was a problem hiding this comment.
@nelimee This actually broke several CI/CD tests.
Shall we update those tests or change the way we iterate though the qubits in the RPNGDescription.get_plaquette() method?
@afowler I think it would be nice to have consistency across the codebase:
When listing the qubits in a plaquette, shall we start from the data qubits or from the ancillas?
My preference would be for data first.
There was a problem hiding this comment.
Shall we update those tests or change the way we iterate though the qubits in the
RPNGDescription.get_plaquette()method?
For the moment, I would take the solution that minimise the amount of code changes for this PR. If that solution is not the prefered one (ancilla qubit first or last, I have a soft preference for ancilla qubit first) then we can open a different PR to change that.
So for the moment, stick to the convention that does not break tests and minimise code changes.
There was a problem hiding this comment.
Ok, I reverted the commit.
First data and then ancilla qubits.
Co-authored-by: Adrien Suau <[email protected]>
Co-authored-by: Adrien Suau <[email protected]>
I am catching up with the comments and it seems that the consensus (at least among the active users @afowler @inmzhang @nelimee ) is to focus exclusively on the 4-character notation. Question on N: Is it ok to assume a single digit value or shall we provide the flexibility to have a larger integer? Question on the measurement time: We need to know that at the time when we generate the plaquette. |
|
I'm ok with restricting n to be a single digit 1-9. A single rnpg string
doesn't tell you the measurement time, this is a property of an entire
layer of such strings.
…On Wed, Dec 11, 2024 at 10:02 AM giangiac ***@***.***> wrote:
I would vote against the 5-character notation. In my mind if you need to
go to a circuit that cannot be expressed with the four character notation,
you probably wouldn't express that circuit using plaquettes in the first
place. H can be on both reset and measurement as a typical expansion of
cnot into CZ can easily require H on both ends of the circuit. I think
reset time should always be zero, and the measurement time should be the
latest time of a gate in an entire circuit layer plus one. Best, Austin.
I am catching up with the comments and it seems that the consensus (at
least among the active users @afowler <https://github.com/afowler>
@inmzhang <https://github.com/inmzhang> @nelimee
<https://github.com/nelimee> ) is to focus exclusively on the 4-character
notation.
I will move the 5-character one to separate classes (not to lose its
implementation in case of future reevaluation).
Question on N: Is it ok to assume a single digit value or shall we provide
the flexibility to have a larger integer?
This may happen when gates take more than a "time step", if we describe
time in terms of a certain clock.
Question on the measurement time: We need to know that at the time when we
generate the plaquette.
Are we going to populate the templates with Plaquette or RPNGDescription
objects?
—
Reply to this email directly, view it on GitHub
<#411 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAXTBXW43RRHDDO2JO3ZL2FB427AVCNFSM6AAAAABTA2UEX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKMZWG4YTSNRSGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Let's have the simple case correct first. If we need 10+ values for
Templates will return RPNG strings. These strings will be translated to |
|
+1 for not breaking tests through changing qubit order in this PR.
…On Thu, Dec 12, 2024, 12:52 AM Adrien Suau ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In src/tqec/plaquette/rpng_description.py
<#411 (comment)>:
> + Note that the ancilla qubit is the last among the PlaquetteQubits and thus
+ has index 4, while the data qubits have indices 0-3.
Shall we update those tests or change the way we iterate though the qubits
in the RPNGDescription.get_plaquette() method?
For the moment, I would take the solution that minimise the amount of code
changes for this PR. If that solution is not the prefered one (ancilla
qubit first or last, I have a soft preference for ancilla qubit first) then
we can open a different PR to change that.
So for the moment, stick to the convention that does not break tests and
minimise code changes.
—
Reply to this email directly, view it on GitHub
<#411 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKAXTBU42CQHVPDB7WJT332FFFDHAVCNFSM6AAAAABTA2UEX6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDIOJYGQYTGNJXHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
Here is a proposal for the @staticmethod
def _parse_or_raise(
typ: type[RPNGCharType], char: str, pos: Literal["R", "P", "N", "G"]
) -> RPNGCharType:
try:
return typ(char)
except ValueError as err:
raise ValueError(
f"Unacceptable character for the {pos} field: '{char}'."
) from err
@classmethod
def from_string(cls, rpng_string: str) -> RPNG:
"""Initialize the RPNG object from a 4-character string
Note that any character different from a BasisEnum / ExtendedBasisEnum
value would result in the corresponding field being None.
"""
if len(rpng_string) != 4:
raise ValueError("The rpng string must be exactly 4-character long.")
r_str, p_str, n_str, g_str = tuple(rpng_string)
# Convert the characters into the enum attributes (or raise error).
r = RPNG._parse_or_raise(ExtendedBasisEnum, r_str, "R")
p = RPNG._parse_or_raise(BasisEnum, p_str, "P")
n = RPNG._parse_or_raise(int, n_str, "N")
g = RPNG._parse_or_raise(ExtendedBasisEnum, g_str, "G")
return cls(r, p, n, g)The code from tqec import RPNG
rpng = RPNG.from_string2("e---")raises and prints to the screen |
This reverts commit ca284e1.
I am not sure how you defined |
|
From my point of view, this is ready to be merged. A few things left for future PRs:
|
nelimee
left a comment
There was a problem hiding this comment.
Ok for me to merge that PR quickly and iterate on it. Thanks for the work :)
|
@giangiac do you want me to merge that PR, or are you waiting for something else to merge? |
Usually, I let someone else merge my PRs, but it seems that the consensus is to merge. |
See issue #410 in the tqec repo.
This PR includes:
Example of a RPNG string and description of the format:
(r) data qubit reset basis or h or -
(p) data basis for the controlled operation (x means CNOT controlled on the ancilla and targeting the data qubit, y means CY, z means CZ)
(n) time step (positive integers, all distinct, typically in 1-5)
(g) data qubit measure basis or h or -
Assumptions on the circuit: