fix: Multiple fixes to the pytket encoder#1566
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1566 +/- ##
==========================================
+ Coverage 83.81% 84.09% +0.27%
==========================================
Files 188 188
Lines 29062 29283 +221
Branches 27936 28157 +221
==========================================
+ Hits 24359 24625 +266
+ Misses 3541 3479 -62
- Partials 1162 1179 +17
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
cqc-alec
left a comment
There was a problem hiding this comment.
The changes look reasonable; however, when I tried the procedure described in #1514 with this branch I encountered some more errors.
Specifically:
-
In the
guppylangrepo (mainbranch), runjust export-integration-tests. -
On this branch of
tket2, run:
import os
from hugr import Hugr
from hugr.passes.scope import GlobalScope
from pytket.passes import FullPeepholeOptimise
from tket.passes import PytketHugrPass
p = PytketHugrPass(FullPeepholeOptimise()).with_scope(GlobalScope.PRESERVE_ENTRYPOINT)
hugr_dir = os.path.join("/home", "alec", "r", "guppylang", "guppy-exports") # edit as appropriate
for hugr_file in os.listdir(hugr_dir):
hugr_path = os.path.join(hugr_dir, hugr_file)
with open(hugr_path, "rb") as f:
h = Hugr.from_bytes(f.read())
try:
h1 = p(h)
except:
print(f"*** Failed for {hugr_file}")Running this script gives:
thread '<unnamed>' (390845) panicked at tket/src/serialize/pytket/decoder.rs:485:18:
called `Result::unwrap()` on an `Err` value: OperationWiring { op: ExtensionOp(ExtensionOp { def: OpDef { extension: IdentList("tket.quantum"), extension_ref: (Weak), name: "QFree", description: "QFree", misc: {"commutation": Array []}, signature_func: PolyFuncTypeBase { params: [], body: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }, lower_funcs: [], constant_folder: None }, args: [], signature: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }), error: NoCopyLinear { typ: TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear), src: Node(11), src_offset: Port(Outgoing, 0) } }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
*** Failed for tests.integration.test_inout-test_move_back_branch.hugr
thread '<unnamed>' (390845) panicked at tket/src/serialize/pytket/decoder.rs:485:18:
called `Result::unwrap()` on an `Err` value: OperationWiring { op: ExtensionOp(ExtensionOp { def: OpDef { extension: IdentList("tket.quantum"), extension_ref: (Weak), name: "QFree", description: "QFree", misc: {"commutation": Array []}, signature_func: PolyFuncTypeBase { params: [], body: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }, lower_funcs: [], constant_folder: None }, args: [], signature: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }), error: NoCopyLinear { typ: TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear), src: Node(18), src_offset: Port(Outgoing, 0) } }
*** Failed for tests.integration.test_linear-test_while_move_back.hugr
*** Failed for tests.integration.test_qsystem-test_measure_leaked.hugr
*** Failed for tests.integration.test_qsystem-test_lazy_measure_array.hugr
*** Failed for tests.integration.test_quantum-test_barrier.hugr
thread '<unnamed>' (390845) panicked at tket/src/serialize/pytket/decoder.rs:485:18:
called `Result::unwrap()` on an `Err` value: OperationWiring { op: ExtensionOp(ExtensionOp { def: OpDef { extension: IdentList("tket.quantum"), extension_ref: (Weak), name: "QFree", description: "QFree", misc: {"commutation": Array []}, signature_func: PolyFuncTypeBase { params: [], body: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }, lower_funcs: [], constant_folder: None }, args: [], signature: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }), error: NoCopyLinear { typ: TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear), src: Node(85), src_offset: Port(Outgoing, 0) } }
*** Failed for tests.integration.test_inout-test_move_back.hugr
thread '<unnamed>' (390845) panicked at tket/src/serialize/pytket/decoder.rs:485:18:
called `Result::unwrap()` on an `Err` value: OperationWiring { op: ExtensionOp(ExtensionOp { def: OpDef { extension: IdentList("tket.quantum"), extension_ref: (Weak), name: "QFree", description: "QFree", misc: {"commutation": Array []}, signature_func: PolyFuncTypeBase { params: [], body: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }, lower_funcs: [], constant_folder: None }, args: [], signature: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }), error: NoCopyLinear { typ: TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear), src: Node(47), src_offset: Port(Outgoing, 0) } }
*** Failed for tests.integration.test_linear-test_struct_reassign2.hugr
*** Failed for tests.integration.test_extern-test_extern_float.hugr
thread '<unnamed>' (390845) panicked at tket/src/serialize/pytket/decoder.rs:485:18:
called `Result::unwrap()` on an `Err` value: OperationWiring { op: ExtensionOp(ExtensionOp { def: OpDef { extension: IdentList("tket.quantum"), extension_ref: (Weak), name: "QFree", description: "QFree", misc: {"commutation": Array []}, signature_func: PolyFuncTypeBase { params: [], body: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }, lower_funcs: [], constant_folder: None }, args: [], signature: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }), error: NoCopyLinear { typ: TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear), src: Node(191), src_offset: Port(Outgoing, 0) } }
*** Failed for tests.integration.test_tuples-test_control_flow2.hugr
*** Failed for tests.integration.std.test_futures-test_read.hugr
*** Failed for tests.integration.test_qsystem-test_lazy_measure_conditional.hugr
thread '<unnamed>' (390845) panicked at tket/src/serialize/pytket/decoder.rs:485:18:
called `Result::unwrap()` on an `Err` value: OperationWiring { op: ExtensionOp(ExtensionOp { def: OpDef { extension: IdentList("tket.quantum"), extension_ref: (Weak), name: "QFree", description: "QFree", misc: {"commutation": Array []}, signature_func: PolyFuncTypeBase { params: [], body: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }, lower_funcs: [], constant_folder: None }, args: [], signature: FuncTypeBase { input: TypeRowBase { types: [TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear)] }, output: TypeRowBase { types: [] } } }), error: NoCopyLinear { typ: TypeBase(Extension(CustomType { extension: IdentList("prelude"), extension_ref: (Weak), id: "qubit", args: [], bound: Linear }), Linear), src: Node(51), src_offset: Port(Outgoing, 0) } }
*** Failed for tests.integration.test_comprehension-test_linear_discard_struct.hugr
Some of these decoding errors seem to be for cases that succeeded previously (though I haven't double-checked this and there may have been changes in guppylang).
…aphs near the region output
|
Ok, there were more fixes needed -.-' Fixed them all in separate per-bug commits, and made a release of I'll update the PR description |
|
Thanks! This solves almost all of the issues. I still see two errors, which look like the same thing, coming from the files Any ideas on this? Otherwise we can merge as-is and leave this for later. |
|
I haven't been able to reproduce that last issue :/ I added a small PR swapping out a I say let's merge this and fill in a new issue if we can reproduce that last error. |
Fixes all issues reported in #1514, as well as ones detected in #1558 and others seen when processing the guppy-exports test set.
(Best viewed as separate commits)
Fixes
ClExprencoding so expression inputs exclude output-only bits. 2bbe580Emits Hugr barriers as pytket
Barriers only when every barrier input/output type is pytket-encodable. 9bb239bAllows the decoder to reconstruct tuple-typed wires from individually tracked pytket values. 89e1b34
Fixes standalone decoding dropping target signature info when reconstructing parameter inputs. 40ebba9
Avoids double-freeing qubits when opaque subgraph outputs are consumed near the decoded region output. 9ac277d
Uses the patched
tket-json-rshandling for pytket commands with"args": null. 47bc7a8Treats
Future<T>as unsupported by pytket encoding, instead of unwrapping known types. 2f823ffFixes translation of
LoadConstants for values that cannot be statically loaded by the encoder (e.g. with external definitions). 958c9e3Makes the region traversal in
reassemble_inplacedeterministic. Fixes [Bug]: Invalid Hugr duringRemoveBarrierstket pass on simple guppy program #1577. d466e94Ai usage: Used codex to create repro cases and find the bug locations.