-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Expand the Command
API with iterators and helpers.
#100
Conversation
- Also, optionally return the ports for each unit
It may be better if I split these changes for readability, but I'll wait for #96 to be merged before messing more with that. |
- Reworks the circuit unit iterators, with a bespoke iterator instead of Vecs. - The previous `units` is now `linear_units`. - Also adds `units`, `nonlinear_units`, `qubits`. - The `Units` iterators is more generic than needed here (it supports arbitrary nodes and directions), since it's also used on #100. - Adds `Circuit::qubit_count`, `Circuit::circuit_signature` - Reorganizes the `Circuit` trait, since the blanket impl means we can just default-implement everything. - Adds more tests Fixes #87 and implements #86 ~I plan to modify `Units` for #85, but this is enough noise for now.~ (Edit: I brought those changes here) --------- Co-authored-by: Alan Lawrence <[email protected]>
#96 is now merged, so this PR is ready for reviews. |
src/circuit/command.rs
Outdated
/// Returns the linear units of this command in a given direction. | ||
#[inline] | ||
pub fn linear_units(&self, direction: Direction) -> Units<&'_ Self> { | ||
Units::new(self.circ, self.node, direction, self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do commands not have non linear ports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, missed this too in the merge. I'll add some test to be sure we'd catch this.
src/circuit/command.rs
Outdated
// Initialize the map assigning linear units to the input's linear | ||
// ports. | ||
let wire_unit = circ | ||
.units() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this should be linear_units
in principle
|
||
use crate::utils::build_simple_circuit; | ||
use crate::T2Op; | ||
|
||
use super::*; | ||
|
||
// We use a macro instead of a function to get the failing line numbers right. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do the line numbers point otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it where a function it would report the function's line.
It's not too bad since we can use RUST_BACKTRACK, but this mimics the behaviour of the other assert_*
macros.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. I was thinking the alternative to using a macro was just writing assert_eq!(_.collect(), _.collect())
each time
I'll merge this and add an issue for better combinators to alter the |
Units
iterator from feat: Better circuit iterators and misc API #96 to provide multiple iterators over the units of a command.Command
to query thenodetype
andoptype
, unit counts, etc.Closes #85