From 3637b1f284bed68d4714be88f3d9cfe8e9559425 Mon Sep 17 00:00:00 2001 From: Seyon Sivarajah Date: Mon, 9 Dec 2024 13:42:56 +0000 Subject: [PATCH] feat!: remove dirty_qubit `tket2.quantum.QAlloc` now guarantees 0 state BREAKING CHANGE: `dirty_qubit` function removed --- guppylang/std/quantum.py | 12 ++---------- tests/integration/test_qalloc.py | 8 ++++---- tests/integration/test_quantum.py | 8 ++++---- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/guppylang/std/quantum.py b/guppylang/std/quantum.py index 2fb03b70..c4afa97b 100644 --- a/guppylang/std/quantum.py +++ b/guppylang/std/quantum.py @@ -18,12 +18,9 @@ @guppy.type(ht.Qubit, linear=True) class qubit: - @guppy + @guppy.hugr_op(quantum_op("QAlloc")) @no_type_check - def __new__() -> "qubit": - q = dirty_qubit() - reset(q) - return q + def __new__() -> "qubit": ... @guppy @no_type_check @@ -121,11 +118,6 @@ def crz(control: qubit, target: qubit, angle: angle) -> None: ... def toffoli(control1: qubit, control2: qubit, target: qubit) -> None: ... -@guppy.hugr_op(quantum_op("QAlloc")) -@no_type_check -def dirty_qubit() -> qubit: ... - - @guppy.custom(InoutMeasureCompiler()) @no_type_check def project_z(q: qubit) -> bool: ... diff --git a/tests/integration/test_qalloc.py b/tests/integration/test_qalloc.py index 5667b74a..48112827 100644 --- a/tests/integration/test_qalloc.py +++ b/tests/integration/test_qalloc.py @@ -2,20 +2,20 @@ from guppylang.module import GuppyModule from guppylang.std.quantum import qubit -from guppylang.std.quantum import dirty_qubit, measure +from guppylang.std.quantum import measure from guppylang.std.quantum_functional import cx import guppylang.std.quantum_functional as quantum_functional -def test_dirty_qubit(validate): +def test_qalloc(validate): module = GuppyModule("test") module.load_all(quantum_functional) - module.load(qubit, dirty_qubit, measure) + module.load(qubit, measure) @guppy(module) def test() -> tuple[bool, bool]: - q1, q2 = qubit(), dirty_qubit() + q1, q2 = qubit(), qubit() q1, q2 = cx(q1, q2) return (measure(q1), measure(q2)) diff --git a/tests/integration/test_quantum.py b/tests/integration/test_quantum.py index 56d8cfa1..878328d1 100644 --- a/tests/integration/test_quantum.py +++ b/tests/integration/test_quantum.py @@ -8,7 +8,7 @@ from guppylang.std.builtins import owned -from guppylang.std.quantum import dirty_qubit, discard, measure, qubit +from guppylang.std.quantum import discard, measure, qubit from guppylang.std.quantum_functional import ( cx, cy, @@ -43,16 +43,16 @@ def compile_quantum_guppy(fn) -> ModulePointer: ), "`@compile_quantum_guppy` does not support extra arguments." module = GuppyModule("module") - module.load(angle, qubit, dirty_qubit, discard, measure) + module.load(angle, qubit, discard, measure) module.load_all(quantum_functional) guppylang.decorator.guppy(module)(fn) return module.compile() -def test_dirty_qubit(validate): +def test_alloc(validate): @compile_quantum_guppy def test() -> tuple[bool, bool]: - q1, q2 = qubit(), dirty_qubit() + q1, q2 = qubit(), qubit() q1, q2 = cx(q1, q2) return (measure(q1), measure(q2))