-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat!: qsystem std functions with updated primitives #679
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4c57634
refactor: hseries -> qsystem rename
ss2165 1ddf4fd
refactor!: move qsystem functions to own module
ss2165 7cd36ad
refactor!: rename measure_return to project_z
ss2165 46d016d
fix: lower `measure` to MeasureFree op
ss2165 89146f9
feat: add measure_reset qsystem function
ss2165 0ceb5cd
feat!: add remaining qsystem ops
ss2165 1210ee2
released tket2-exts
ss2165 e46226f
fix!: remove measure_return and qubit.measure_reset
ss2165 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
from typing import no_type_check | ||
|
||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std import angles | ||
from guppylang.std._internal.compiler.quantum import ( | ||
QSYSTEM_EXTENSION, | ||
InoutMeasureCompiler, | ||
) | ||
from guppylang.std._internal.util import quantum_op | ||
from guppylang.std.angles import angle | ||
from guppylang.std.builtins import owned | ||
from guppylang.std.quantum import qubit | ||
|
||
qsystem = GuppyModule("qsystem") | ||
|
||
qsystem.load(qubit) | ||
qsystem.load_all(angles) | ||
|
||
|
||
@guppy(qsystem) | ||
@no_type_check | ||
def phased_x(q: qubit, angle1: angle, angle2: angle) -> None: | ||
f1 = float(angle1) | ||
f2 = float(angle2) | ||
_phased_x(q, f1, f2) | ||
|
||
|
||
@guppy.hugr_op(quantum_op("ZZMax", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def zz_max(q1: qubit, q2: qubit) -> None: ... | ||
|
||
|
||
@guppy(qsystem) | ||
@no_type_check | ||
def zz_phase(q1: qubit, q2: qubit, angle: angle) -> None: | ||
f = float(angle) | ||
_zz_phase(q1, q2, f) | ||
|
||
|
||
@guppy(qsystem) | ||
@no_type_check | ||
def rz(q: qubit, angle: angle) -> None: | ||
f1 = float(angle) | ||
_rz(q, f1) | ||
|
||
|
||
@guppy.hugr_op(quantum_op("Measure", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def measure(q: qubit @ owned) -> bool: ... | ||
|
||
|
||
@guppy.custom(InoutMeasureCompiler("MeasureReset", QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def measure_and_reset(q: qubit) -> bool: | ||
"""MeasureReset operation from the qsystem extension.""" | ||
|
||
|
||
@guppy.hugr_op(quantum_op("Reset", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def reset(q: qubit) -> None: ... | ||
|
||
|
||
# TODO | ||
# @guppy.hugr_op(quantum_op("TryQAlloc", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
# @no_type_check | ||
# def _try_qalloc() -> Option[qubit]: | ||
# .. | ||
|
||
|
||
@guppy.hugr_op(quantum_op("QFree", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def qfree(q: qubit @ owned) -> None: ... | ||
|
||
|
||
# ------------------------------------------------------ | ||
# --------- Internal definitions ----------------------- | ||
# ------------------------------------------------------ | ||
|
||
|
||
@guppy.hugr_op(quantum_op("PhasedX", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def _phased_x(q: qubit, angle1: float, angle2: float) -> None: | ||
"""PhasedX operation from the qsystem extension. | ||
|
||
See `guppylang.std.qsystem.phased_x` for a public definition that | ||
accepts angle parameters. | ||
""" | ||
|
||
|
||
@guppy.hugr_op(quantum_op("ZZPhase", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def _zz_phase(q1: qubit, q2: qubit, angle: float) -> None: | ||
"""ZZPhase operation from the qsystem extension. | ||
|
||
See `guppylang.std.qsystem.phased_x` for a public definition that | ||
accepts angle parameters. | ||
""" | ||
|
||
|
||
@guppy.hugr_op(quantum_op("Rz", ext=QSYSTEM_EXTENSION), module=qsystem) | ||
@no_type_check | ||
def _rz(q: qubit, angle: float) -> None: | ||
"""Rz operation from the qsystem extension. | ||
|
||
See `guppylang.std.qsystem.rz` for a public definition that | ||
accepts angle parameters. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import no_type_check | ||
|
||
from guppylang.decorator import guppy | ||
from guppylang.module import GuppyModule | ||
from guppylang.std import angles, qsystem | ||
from guppylang.std.angles import angle | ||
from guppylang.std.builtins import owned | ||
from guppylang.std.quantum import qubit | ||
|
||
qsystem_functional = GuppyModule("qsystem_functional") | ||
|
||
qsystem_functional.load(qubit, qsystem) | ||
qsystem_functional.load_all(angles) | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def phased_x(q: qubit @ owned, angle1: angle, angle2: angle) -> qubit: | ||
qsystem.phased_x(q, angle1, angle2) | ||
return q | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def zz_phase(q1: qubit @ owned, q2: qubit @ owned, angle: angle) -> tuple[qubit, qubit]: | ||
qsystem.zz_phase(q1, q2, angle) | ||
return q1, q2 | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def measure_and_reset(q: qubit @ owned) -> tuple[qubit, bool]: | ||
b = qsystem.measure_and_reset(q) | ||
return q, b | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def zz_max(q1: qubit @ owned, q2: qubit @ owned) -> tuple[qubit, qubit]: | ||
qsystem.zz_max(q1, q2) | ||
return q1, q2 | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def rz(q: qubit @ owned, angle: angle) -> qubit: | ||
qsystem.rz(q, angle) | ||
return q | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def measure(q: qubit @ owned) -> bool: | ||
result = qsystem.measure(q) | ||
return result | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def qfree(q: qubit @ owned) -> None: | ||
qsystem.qfree(q) | ||
|
||
|
||
@guppy(qsystem_functional) | ||
@no_type_check | ||
def reset(q: qubit @ owned) -> qubit: | ||
qsystem.reset(q) | ||
return q |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment, no change needed. From this wrapper, it looks like
project_z
is not exposed directly to the user, so I think it's a nice rename. I wouldn't want users to have to useproject_z
call for measurements.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh this has been overlooked, measure_return should be removed really.
measure_return
is a confusing name, so I wanted to replace withproject_z
.measure
is still there as the standard user facing measure function, but it consumes the qubit.