Skip to content

Commit

Permalink
feat!: Use inout for pytket circuits (#500)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Pytket circuits loaded via a `py` expression no longer
take ownership of the passed qubits.

---------

Co-authored-by: Alan Lawrence <[email protected]>
Co-authored-by: Douglas Wilson <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent cc2c8a4 commit a980ec2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 2 additions & 4 deletions guppylang/checker/expr_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions guppylang/compiler/expr_compiler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a980ec2

Please sign in to comment.