Skip to content

Commit

Permalink
restrict to only qubit create/destroy methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Oct 23, 2024
1 parent a893d16 commit 2808e60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 89 deletions.
85 changes: 2 additions & 83 deletions guppylang/prelude/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,6 @@ def __new__() -> "qubit":
reset(q)
return q

@guppy
@no_type_check
def h(self: "qubit") -> None:
h(self)

@guppy
@no_type_check
def cz(self: "qubit", target: "qubit") -> None:
cz(self, target)

@guppy
@no_type_check
def cx(self: "qubit", target: "qubit") -> None:
cx(self, target)

@guppy
@no_type_check
def measure(self: "qubit" @ owned) -> bool:
Expand All @@ -54,83 +39,17 @@ def measure_return(self: "qubit") -> bool:
@guppy
@no_type_check
def measure_reset(self: "qubit") -> bool:
"""Projective measure and reset without discarding the qubit."""
res = self.measure_return()
if res:
self.x()
x(self)
return res

@guppy
@no_type_check
def discard(self: "qubit" @ owned) -> None:
discard(self)

@guppy
@no_type_check
def x(self: "qubit") -> None:
x(self)

@guppy
@no_type_check
def y(self: "qubit") -> None:
y(self)

@guppy
@no_type_check
def z(self: "qubit") -> None:
z(self)

@guppy
@no_type_check
def t(self: "qubit") -> None:
t(self)

@guppy
@no_type_check
def s(self: "qubit") -> None:
s(self)

@guppy
@no_type_check
def tdg(self: "qubit") -> None:
tdg(self)

@guppy
@no_type_check
def sdg(self: "qubit") -> None:
sdg(self)

@guppy
@no_type_check
def rz(self: "qubit", angle: angle) -> None:
rz(self, angle)

@guppy
@no_type_check
def rx(self: "qubit", angle: angle) -> None:
rx(self, angle)

@guppy
@no_type_check
def ry(self: "qubit", angle: angle) -> None:
ry(self, angle)

@guppy
@no_type_check
def crz(self: "qubit", target: "qubit", angle: angle) -> None:
crz(self, target, angle)

# TODO toffoli doesn't make much sense with two controls

# @guppy
# @no_type_check
# def toffoli(self: "qubit", control2: "qubit", target: "qubit") -> None:
# toffoli(self, control2, target)

@guppy
@no_type_check
def zz_max(self: "qubit", q2: "qubit") -> None:
zz_max(self, q2)


@guppy.hugr_op(quantum_op("H"))
@no_type_check
Expand Down
11 changes: 5 additions & 6 deletions tests/integration/test_inout.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,12 @@ def test_self_qubit(validate):

@guppy(module)
def test() -> bool:
q0, q1 = qubit(), qubit()
q0.h()
q1.h()
q0.cx(q1)
q0 = qubit()

result = q0.measure_reset()
q0.discard()
q1.discard()
q0.measure_return()
q0.measure()
qubit().discard()
return result

validate(module.compile())

0 comments on commit 2808e60

Please sign in to comment.