From ab1dd0eb611156b13a606135a382a9be416a033c Mon Sep 17 00:00:00 2001 From: Alec Edgington Date: Tue, 15 Jul 2025 15:40:35 +0100 Subject: [PATCH] Add support for V and Vdg. --- guppylang/std/quantum/__init__.py | 10 ++++++++++ guppylang/std/quantum/functional.py | 14 ++++++++++++++ guppylang/std/quantum_functional.py | 4 ++++ tests/integration/test_quantum.py | 4 ++++ 4 files changed, 32 insertions(+) diff --git a/guppylang/std/quantum/__init__.py b/guppylang/std/quantum/__init__.py index dac0f4271..c128ab279 100644 --- a/guppylang/std/quantum/__init__.py +++ b/guppylang/std/quantum/__init__.py @@ -77,6 +77,11 @@ def t(q: qubit) -> None: ... def s(q: qubit) -> None: ... +@guppy.hugr_op(quantum_op("V")) +@no_type_check +def v(q: qubit) -> None: ... + + @guppy.hugr_op(quantum_op("X")) @no_type_check def x(q: qubit) -> None: ... @@ -102,6 +107,11 @@ def tdg(q: qubit) -> None: ... def sdg(q: qubit) -> None: ... +@guppy.hugr_op(quantum_op("Vdg")) +@no_type_check +def vdg(q: qubit) -> None: ... + + @guppy.custom(RotationCompiler("Rz")) @no_type_check def rz(q: qubit, angle: angle) -> None: ... diff --git a/guppylang/std/quantum/functional.py b/guppylang/std/quantum/functional.py index 3cea0dfc4..0a30ac911 100644 --- a/guppylang/std/quantum/functional.py +++ b/guppylang/std/quantum/functional.py @@ -53,6 +53,13 @@ def s(q: qubit @ owned) -> qubit: return q +@guppy +@no_type_check +def v(q: qubit @ owned) -> qubit: + quantum.v(q) + return q + + @guppy @no_type_check def x(q: qubit @ owned) -> qubit: @@ -88,6 +95,13 @@ def sdg(q: qubit @ owned) -> qubit: return q +@guppy +@no_type_check +def vdg(q: qubit @ owned) -> qubit: + quantum.vdg(q) + return q + + @guppy @no_type_check def rz(q: qubit @ owned, angle: angle) -> qubit: diff --git a/guppylang/std/quantum_functional.py b/guppylang/std/quantum_functional.py index c4ab644f5..331de9d61 100644 --- a/guppylang/std/quantum_functional.py +++ b/guppylang/std/quantum_functional.py @@ -17,6 +17,8 @@ t, tdg, toffoli, + v, + vdg, x, y, z, @@ -29,11 +31,13 @@ "cy", "t", "s", + "v", "x", "y", "z", "tdg", "sdg", + "vdg", "rz", "rx", "ry", diff --git a/tests/integration/test_quantum.py b/tests/integration/test_quantum.py index 21db37391..429bbdce6 100644 --- a/tests/integration/test_quantum.py +++ b/tests/integration/test_quantum.py @@ -23,11 +23,13 @@ h, t, s, + v, x, y, z, tdg, sdg, + vdg, rx, ry, rz, @@ -57,11 +59,13 @@ def test(q: qubit @ owned) -> qubit: q = h(q) q = t(q) q = s(q) + q = v(q) q = x(q) q = y(q) q = z(q) q = tdg(q) q = sdg(q) + q = vdg(q) return q validate(guppy.compile(test))