From a980ec2c89e2ebecb16b0ea12750ecf6781f3ee3 Mon Sep 17 00:00:00 2001 From: Mark Koch <48097969+mark-koch@users.noreply.github.com> Date: Tue, 17 Sep 2024 10:31:17 +0100 Subject: [PATCH] feat!: Use inout for pytket circuits (#500) BREAKING CHANGE: Pytket circuits loaded via a `py` expression no longer take ownership of the passed qubits. --------- Co-authored-by: Alan Lawrence Co-authored-by: Douglas Wilson --- guppylang/checker/expr_checker.py | 6 ++---- guppylang/compiler/expr_compiler.py | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/guppylang/checker/expr_checker.py b/guppylang/checker/expr_checker.py index 48bf01df..d3fdf3c5 100644 --- a/guppylang/checker/expr_checker.py +++ b/guppylang/checker/expr_checker.py @@ -1124,10 +1124,8 @@ def python_value_to_guppy_type(v: Any, node: ast.expr, globals: Globals) -> Type [], globals ) return FunctionType( - [FuncInput(qubit, InputFlags.NoFlags)] * v.n_qubits, - row_to_type( - [qubit] * v.n_qubits + [bool_type()] * v.n_bits - ), + [FuncInput(qubit, InputFlags.Inout)] * v.n_qubits, + row_to_type([bool_type()] * v.n_bits), ) except ImportError: raise GuppyError( diff --git a/guppylang/compiler/expr_compiler.py b/guppylang/compiler/expr_compiler.py index 382531db..adffc918 100644 --- a/guppylang/compiler/expr_compiler.py +++ b/guppylang/compiler/expr_compiler.py @@ -1,5 +1,4 @@ import ast -import json from collections.abc import Iterable, Iterator, Sequence from contextlib import contextmanager from typing import Any, TypeGuard, TypeVar @@ -8,7 +7,7 @@ import hugr.std.float import hugr.std.int import hugr.std.logic -from hugr import Wire, ops +from hugr import Hugr, Wire, ops from hugr import tys as ht from hugr import val as hv from hugr.build.cond_loop import Conditional @@ -564,7 +563,7 @@ def python_value_to_hugr(v: Any, exp_ty: Type) -> hv.Value | None: Tk2Circuit, ) - circ = json.loads(Tk2Circuit(v).to_hugr_json()) # type: ignore[attr-defined, unused-ignore] + circ = Hugr.load_json(Tk2Circuit(v).to_hugr_json()) # type: ignore[attr-defined, unused-ignore] return hv.Function(circ) except ImportError: pass