Skip to content
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: Add missing tket2 quantum gates, generalise RotationCompile #510

Merged
Merged
10 changes: 5 additions & 5 deletions guppylang/prelude/_internal/compiler/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, opname: str):
def compile_with_inouts(self, args: list[Wire]) -> CallReturnWires:
from guppylang.prelude._internal.util import quantum_op

[q, angle] = args
qs, angle = args[:-1], args[-1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
[q, angle] = args
qs, angle = args[:-1], args[-1]
[*qs, angle] = args

[halfturns] = self.builder.add_op(ops.UnpackTuple([FLOAT_T]), angle)
[mb_rotation] = self.builder.add_op(from_halfturns(), halfturns)

Expand All @@ -81,11 +81,11 @@ def compile_with_inouts(self, args: list[Wire]) -> CallReturnWires:
with conditional.add_case(1) as case:
case.set_outputs(*case.inputs())

q = self.builder.add_op(
qs = self.builder.add_op(
quantum_op(self.opname)(
ht.FunctionType([ht.Qubit, ROTATION_T], [ht.Qubit]), []
ht.FunctionType([ht.Qubit for _ in qs] + [ROTATION_T], [ht.Qubit for _ in qs]), []
),
q,
*qs,
conditional,
)
return CallReturnWires(regular_returns=[], inout_returns=[q])
return CallReturnWires(regular_returns=[], inout_returns=qs)
jake-arkinstall marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions guppylang/prelude/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from guppylang.decorator import guppy
from guppylang.prelude._internal.compiler.quantum import (
HSERIES_EXTENSION,
QUANTUM_EXTENSION,
MeasureReturnCompiler,
RotationCompiler,
)
Expand All @@ -35,6 +36,10 @@ def h(q: qubit) -> None: ...
def cz(control: qubit, target: qubit) -> None: ...


@guppy.hugr_op(quantum_op("CY"))
def cy(control: qubit, target: qubit) -> None: ...
Comment on lines +38 to +39
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you also add these functions to the quantum_functional module?



@guppy.hugr_op(quantum_op("CX"))
def cx(control: qubit, target: qubit) -> None: ...

Expand Down Expand Up @@ -79,6 +84,18 @@ def rz(q: qubit, angle: angle) -> None: ...
def rx(q: qubit, angle: angle) -> None: ...


@guppy.custom(RotationCompiler("Ry"))
def ry(q: qubit, angle: angle) -> None: ...


@guppy.custom(RotationCompiler("CRz"))
def crz(control: qubit, target: qubit, angle: angle) -> None: ...


@guppy.hugr_op(quantum_op("Toffoli"))
def toffoli(control1: qubit, control2: qubit, target: qubit) -> None: ...


@guppy.hugr_op(quantum_op("QAlloc"))
def dirty_qubit() -> qubit: ...

Expand Down
Loading