Skip to content

Commit

Permalink
docs: fix README.md and quickstart.md (#654)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Nov 15, 2024
1 parent 3d74156 commit abb0221
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@ It allows you to write high-level hybrid quantum programs with classical control

```python
from guppylang import guppy
from guppylang.prelude.quantum import cx, h, measure, qubit, x, z
from guppylang.std.builtins import owned
from guppylang.std.quantum import cx, h, measure, qubit, x, z


@guppy
def teleport(src: qubit, tgt: qubit) -> qubit:
def teleport(src: qubit @ owned, tgt: qubit) -> None:
"""Teleports the state in `src` to `tgt`."""
# Create ancilla and entangle it with src and tgt
tmp = qubit()
tmp, tgt = cx(h(tmp), tgt)
src, tmp = cx(src, tmp)
h(tmp)
cx(tmp, tgt)
cx(src, tmp)

# Apply classical corrections
if measure(h(src)):
tgt = z(tgt)
h(src)
if measure(src):
z(tgt)
if measure(tmp):
tgt = x(tgt)
return tgt
x(tgt)

guppy.compile_module()
```
Expand Down
20 changes: 12 additions & 8 deletions quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ flow and mid-circuit measurements using Pythonic syntax:

```python
from guppylang import guppy
from guppylang.prelude.quantum import cx, h, measure, qubit, x, z
from guppylang.std.builtins import owned
from guppylang.std.quantum import cx, h, measure, qubit, x, z


@guppy
def teleport(src: qubit, tgt: qubit) -> qubit:
def teleport(src: qubit @ owned, tgt: qubit) -> None:
"""Teleports the state in `src` to `tgt`."""
# Create ancilla and entangle it with src and tgt
tmp = qubit()
tmp, tgt = cx(h(tmp), tgt)
src, tmp = cx(src, tmp)
h(tmp)
cx(tmp, tgt)
cx(src, tmp)

# Apply classical corrections
if measure(h(src)):
tgt = z(tgt)
h(src)
if measure(src):
z(tgt)
if measure(tmp):
tgt = x(tgt)
return tgt
x(tgt)


guppy.compile_module()
```
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit abb0221

Please sign in to comment.