docs: add modifier documentation#182
Conversation
…ctions, modifiers on classical functions
|
@CalMacCQ I think the page is almost ready, a part of the QFT example (and a section about |
There was a problem hiding this comment.
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@CalMacCQ, I also added a Grover example. I think it is ready now. We only miss Unitary callable but I would add them when we are sure that they are not going to be experimental anymore |
|
We have to wait for Quantinuum/guppylang#2061 to be merged |
CalMacCQ
left a comment
There was a problem hiding this comment.
This is a great start. Thanks for this.
I have yet to read this thoroughly but here are some quick comments.
I'll take another look tomorrow.
Co-authored-by: Callum Macpherson <93673602+CalMacCQ@users.noreply.github.com>
|
|
||
| ## Control flow | ||
|
|
||
| When a controlled block contains control flow, the control is pushed to every quantum operation produced by the branch or loop. Evaluating the classical condition and loop bounds is not controlled. For instance, the following two programs are equivalent: |
There was a problem hiding this comment.
the guppy logic here is so clean and demonstrative you could maybe reverse this section - 'These are equivalent.. this is because classical conditioning and loops are not part of the with control modification'
There was a problem hiding this comment.
I see, but I'm sure how to organize the session 🤔
dunc-go
left a comment
There was a problem hiding this comment.
Really appreciate the effort here.
Top level comment: I think this page should be split into 3 pages.
One is a top level explanation of the syntax and general properties of modifiers and maybe function flags. Then I think each modifier (control and syntax for now) can have their own pages with their specific properties (forbiddens etc) and then finally a 3rd page with examples such the conjugation box and the grovers.
| h(q) | ||
| with control(c): | ||
| x(q) | ||
| bit_c =measure(c) |
There was a problem hiding this comment.
Nit:
| bit_c =measure(c) | |
| bit_c = measure(c) |
| from guppylang.std.quantum import qubit, x, h, measure | ||
|
|
||
| @guppy | ||
| def controlled_x() -> None: |
There was a problem hiding this comment.
I wouldn't use CX here. In general people should be using modifiers for gates which do not exist in std.quantum
| controlled_inverse.check() | ||
| ``` | ||
|
|
||
| Here we take the S gate and modify it with control and dagger. This gate has a known form of control and daggering, and the operations are compatible. Therefore, when we check the program (compile), the code passes. When applied, this function acts as a C-S^\dag gate |
There was a problem hiding this comment.
| Here we take the S gate and modify it with control and dagger. This gate has a known form of control and daggering, and the operations are compatible. Therefore, when we check the program (compile), the code passes. When applied, this function acts as a C-S^\dag gate | |
| Here we take the $S$ gate and modify it with control and dagger. This gate has a known form of control and daggering, and the operations are compatible. Therefore, we can successfully type check the program. When applied, this function acts as a $CS^\dagger$ gate |
There was a problem hiding this comment.
I am not sure what this sentance means
"This gate has a known form of control and daggering, and the operations are compatible"
Is this just saying that the gate is unitary and therefore we can add a control to it?
|
|
||
| invert_rotations.check() | ||
| ``` | ||
|
|
There was a problem hiding this comment.
I don't think qasm should be necesary here. I think just the three backticks should be fine.
| with dagger: | ||
| output("value", True) | ||
|
|
||
| output_in_dagger.check() |
There was a problem hiding this comment.
I think in rc2 this will give an error as expected.
| C[U] = (I \otimes V)\, C[A]\, (I \otimes V^\dagger). | ||
| $$ | ||
|
|
||
| This avoids controlling every operation in `V` and can substantially reduce the number of controlled, entangling gates. |
There was a problem hiding this comment.
| This avoids controlling every operation in `V` and can substantially reduce the number of controlled, entangling gates. | |
| This avoids controlling every operation in $V$ and can substantially reduce the number of controlled, entangling gates. |
| U = V A V^\dagger. | ||
| $$ | ||
|
|
||
| The first part computes a basis change, `A` performs the action, and the final part uncomputes the basis change. This is a conjugation box. |
There was a problem hiding this comment.
| The first part computes a basis change, `A` performs the action, and the final part uncomputes the basis change. This is a conjugation box. | |
| The first part computes a basis change, `A` performs the action, and the final part uncomputes the basis change. This is a conjugation pattern. |
| controlled_conjugation.check() | ||
| ``` | ||
|
|
||
| #### Conjugation box with Pauli gadget |
There was a problem hiding this comment.
| #### Conjugation box with Pauli gadget | |
| #### Conjugation pattern with Pauli exponential |
|
|
||
| The resulting quantum operations are equivalent to: | ||
|
|
||
| ```qasm |
There was a problem hiding this comment.
Is the qasm annotation needed here?
|
|
||
| ## Syntax | ||
|
|
||
| Use modifiers in a `with` statement. |
There was a problem hiding this comment.
| Use modifiers in a `with` statement. | |
| We can make use of modifiers inside a context manager using the `with` keyword. |
|
|
||
| Use modifiers in a `with` statement. | ||
|
|
||
| Start with the simplest form: a single modifier on a single operation. |
There was a problem hiding this comment.
| Start with the simplest form: a single modifier on a single operation. | |
| Let’s start with a simple example of a controlled single-qubit operation. We will realize this with the `control` modifier. |
| from guppylang.std.quantum import rz | ||
|
|
||
| @guppy | ||
| def invert_rotations(q: qubit) -> None: |

closes #98