fix(pytket decoder): Panic on repeated bit registers in pytket decoded output#1445
fix(pytket decoder): Panic on repeated bit registers in pytket decoded output#1445
Conversation
| node, | ||
| hugr, | ||
| // Output bits use new registers, so don't reuse any input bits. | ||
| EmitCommandOptions::new().reuse_bits(|_| vec![]), |
There was a problem hiding this comment.
Drive-by: The classical expression emitter was re-using the input bits to the node instead of using a separate output bit register.
There was a problem hiding this comment.
Yeah this looks like it might even have been the bigger fix?? Do we have a test that covers just this?
There was a problem hiding this comment.
It's not used much, hence why we never saw the bug.
I added a test.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1445 +/- ##
==========================================
+ Coverage 79.56% 79.96% +0.40%
==========================================
Files 155 155
Lines 20245 20237 -8
Branches 19254 19246 -8
==========================================
+ Hits 16107 16182 +75
+ Misses 3186 3099 -87
- Partials 952 956 +4
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:
|
204bbf7 to
c8ea134
Compare
acl-cqc
left a comment
There was a problem hiding this comment.
Thanks, @aborgna-q - I think there are some fairly significant improvements/fixes in, so keen to get this in :). I think a couple of comments are significant (PR title/panicking) but mostly just neatness/comprehension so I'll approve rightaway :-)
| encoder.emit_node_command( | ||
| node, | ||
| hugr, | ||
| // Output bits use new registers, so don't reuse any input bits. |
There was a problem hiding this comment.
super-nit: consider assigning this to a variable first (called output_bits, thus shortening the comment?)
| for qubit in encoded_info.output_qubits.iter() { | ||
| let id = self.wire_tracker.tracked_qubit_for_register(qubit)?; | ||
| qubits.insert(id.clone()); | ||
| qubits.push(id.clone()); |
There was a problem hiding this comment.
The PR title is "Panic on repeated registers". I don't see anything that would panic if the same qubit was pushed more than once - TBH it seems to me that "repeated registers" for qubits is a fairly serious error (linearity violation), so panicking sounds like a good thing to do?
(Not sure whether "registers" means "qubits", "bits" or both - panicking on repeated bits sounds an odd thing to do if you are from any background other than pytket 😉 😁 but you might want to)
If the PR title is wrong and we don't panic, please update it ;-), maybe something about bit registers if it doesn't apply to qubits.
There was a problem hiding this comment.
Indeed, it only applies to bit registers.
Qubit outputs should never be repeated if the metadata originates from a valid hugr.
I swapped both IndexSet for Vecs for symmetry, but for qubit it doesn't really change anything.
| node, | ||
| hugr, | ||
| // Output bits use new registers, so don't reuse any input bits. | ||
| EmitCommandOptions::new().reuse_bits(|_| vec![]), |
There was a problem hiding this comment.
Yeah this looks like it might even have been the bigger fix?? Do we have a test that covers just this?
| // Convert the wire type, if needed. | ||
| let wire_data = &self.wires[&wire]; | ||
| let new_wire = config.transform_typed_value(wire, wire_data.ty(), ty, builder)?; | ||
| let found_wire_type = wire_data.ty(); |
There was a problem hiding this comment.
not clear why you've changed this, you're not using found_wire_type anywhere you weren't before AFAICS. If you're intending the name to be an improvement then you should probably rename wire_data to found_wire instead?
There was a problem hiding this comment.
There was a bug hidden in here, we were tracking the new converted wire with the type of the pre-conversion wire.
I inlined found_wire_type and changed wire_data to found_wire_data to make things clear.
|
This PR contains breaking changes to the public Rust API. cargo-semver-checks summary |
…d output (#1445) Fix an edge case where we extracted a hugr from a pytket circuit, and declared multiple output ports to have the same bit register. Also cleans up a bit of the logic that handled consumed bit wires, to avoid marking them as outdated if they can still be used by other operations.
Fix an edge case where we extracted a hugr from a pytket circuit, and declared multiple output ports to have the same bit register.
Also cleans up a bit of the logic that handled consumed bit wires, to avoid marking them as outdated if they can still be used by other operations.