Skip to content

docs: add modifier documentation#182

Open
nicolaassolini-qntm wants to merge 20 commits into
mainfrom
na/modifier-documentation
Open

docs: add modifier documentation#182
nicolaassolini-qntm wants to merge 20 commits into
mainfrom
na/modifier-documentation

Conversation

@nicolaassolini-qntm

Copy link
Copy Markdown
Contributor

closes #98

@nicolaassolini-qntm nicolaassolini-qntm changed the title doc: add modifier documentation docs: add modifier documentation Jul 13, 2026
@nicolaassolini-qntm
nicolaassolini-qntm marked this pull request as ready for review July 14, 2026 09:54
@nicolaassolini-qntm

Copy link
Copy Markdown
Contributor Author

@CalMacCQ I think the page is almost ready, a part of the QFT example (and a section about @compite with flags?) If you want to take a look now before adding the final examples, I think it can be useful.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@nicolaassolini-qntm

Copy link
Copy Markdown
Contributor Author

@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

@nicolaassolini-qntm

Copy link
Copy Markdown
Contributor Author

We have to wait for Quantinuum/guppylang#2061 to be merged

@CalMacCQ CalMacCQ left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md Outdated
@CalMacCQ
CalMacCQ requested a review from dunc-go July 16, 2026 17:03
Co-authored-by: Callum Macpherson <93673602+CalMacCQ@users.noreply.github.com>
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md
Comment thread sphinx/language_guide/modifiers.md
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md
Comment thread sphinx/language_guide/modifiers.md Outdated
Comment thread sphinx/language_guide/modifiers.md Outdated

## 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:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, but I'm sure how to organize the session 🤔

@dunc-go dunc-go left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@CalMacCQ
CalMacCQ self-requested a review July 20, 2026 19:08
h(q)
with control(c):
x(q)
bit_c =measure(c)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit:

Suggested change
bit_c =measure(c)
bit_c = measure(c)

from guppylang.std.quantum import qubit, x, h, measure

@guppy
def controlled_x() -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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()
```

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#### Conjugation box with Pauli gadget
#### Conjugation pattern with Pauli exponential


The resulting quantum operations are equivalent to:

```qasm

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is the qasm annotation needed here?


## Syntax

Use modifiers in a `with` statement.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This example snippet seems to not execute without error on C.I.

Image

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.

Language guide page on modifiers (control, power, dagger)

4 participants