Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Track input linear units in Command #310

Merged
merged 5 commits into from
Apr 16, 2024
Merged

Conversation

aborgna-q
Copy link
Collaborator

Command only stored the linear units assigned to its output ports, so querying the input linear unit to a QFree operation panicked.

This pr tracks the input_linear_units in addition to the output ones.

Fixes #309.

@aborgna-q aborgna-q requested a review from ss2165 April 12, 2024 15:15
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

Attention: Patch coverage is 87.39496% with 15 lines in your changes are missing coverage. Please review.

Project coverage is 84.52%. Comparing base (c4f0993) to head (17fc757).
Report is 1 commits behind head on main.

Files Patch % Lines
tket2/src/circuit/command.rs 87.39% 2 Missing and 13 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #310      +/-   ##
==========================================
+ Coverage   84.48%   84.52%   +0.04%     
==========================================
  Files          35       35              
  Lines        4408     4473      +65     
  Branches     4256     4321      +65     
==========================================
+ Hits         3724     3781      +57     
  Misses        502      502              
- Partials      182      190       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@ss2165 ss2165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC, now all linear wires will be assigned a linearunit index by the commands iterator (regardless of the actual linear type?). Meaning now the indices used to build using CircuitBuilder won't necessarily match the indices coming out of the commands iterator right? Is this what we want? Seems confusing.

}
EitherOrBoth::Left((_, in_port, _)) => {
// Terminate the input linear unit.
let Some(linear_id) = self.circ.linked_outputs(node, in_port).next().and_then(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use single_linked_input given its linear?

Comment on lines 409 to 421
// Update the input linear unit using the output port.
let Some(linear_id) = self.circ.linked_outputs(node, in_port).next().and_then(
|(wire_node, wire_port)| {
self.wire_unit.remove(&Wire::new(wire_node, wire_port))
},
) else {
continue;
};
let linear_unit = LinearUnit::new(linear_id);
let new_wire = Wire::new(node, out_port);
input_linear_units.push(linear_unit);
output_linear_units.push(linear_unit);
self.wire_unit.insert(new_wire, linear_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to extract the logic in the previous cases in to functions and re-use them here

@aborgna-q
Copy link
Collaborator Author

We don't currently have a way to define matching inputs and outputs in the opdef.
The behaviour here is to list the linear inputs and the linear outputs sequentially and match them in order.

I think that should work for the majority of the cases. It's true that an opt-in high-grained configuration of it may be required in the future, but I'd leave it as a new issue.

@aborgna-q aborgna-q requested a review from ss2165 April 16, 2024 09:54
@aborgna-q aborgna-q added this pull request to the merge queue Apr 16, 2024
Merged via the queue into main with commit 956eb05 Apr 16, 2024
11 checks passed
@aborgna-q aborgna-q deleted the fix/commands-on-free branch April 16, 2024 11:29
github-merge-queue bot pushed a commit that referenced this pull request May 24, 2024
## 🤖 New release
* `tket2`: 0.1.0-alpha.1

<details><summary><i><b>Changelog</b></i></summary><p>

## `tket2`
<blockquote>

##
[0.0.0-alpha.1](https://github.com/CQCL/tket2/releases/tag/tket2-v0.0.0-alpha.1)
- 2024-05-24

### Bug Fixes
- Check for rewrite composition in badger
([#255](#255))
- induced cycles in depth optimisation
([#264](#264))
- Encode opaque symbolic constants
([#273](#273))
- Correctly detect custom ops by name
([#281](#281))
- Track input linear units in `Command`
([#310](#310))
- Don't convert tket2 measurements into tket1 ops
([#331](#331))

### Documentation
- Expand the main module and README docs
([#298](#298))

### New Features
- add angle type to tket2 extension
([#231](#231))
- bindings for circuit cost and hash
([#252](#252))
- Implement `PyErr` conversion locally in `tket2-py`
([#258](#258))
- Add a "progress timeout" to badger
([#259](#259))
- [**breaking**] Add lexicographic cost
([#270](#270))
- rewrite tracing ([#267](#267))
- Move pre/post rewrite cost to the RewriteStrategy API
([#276](#276))
- [**breaking**] Lexicographic cost fn
([#277](#277))
- Return rewrite strategies as a generator
([#275](#275))
- add qalloc, qfree, reset ops
([#284](#284))
- [**breaking**] Support any ops in portmatching
([#293](#293))
- Add `PatternMatch::nodes` and `subcircuit` + matching example
([#299](#299))
- Use `IncomingPort` and `OutgoingPort` instead of `Port` where
possible. ([#296](#296))
- expose Tk2Op name ([#307](#307))

### Refactor
- Move tket2 code to a workspace member
([#210](#210))
- Restructure the python code
([#211](#211))
- s/taso/badger/ ([#228](#228))
- Move python bindings from `tket2` to `tket2-py`
([#235](#235))
- rename t2op ([#256](#256))

### Testing
- Add small parallel badger test
([#237](#237))
- fix non-deterministic badger test
([#245](#245))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Agustin Borgna <agustin.borgna@quantinuum.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Querying the linear inputs of a QFree command throws an error.
2 participants