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

feat: Expand the Command API with iterators and helpers. #100

Merged
merged 16 commits into from
Sep 20, 2023

Conversation

aborgna-q
Copy link
Collaborator

@aborgna-q aborgna-q commented Sep 12, 2023

Closes #85

@aborgna-q
Copy link
Collaborator Author

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.

Base automatically changed from feat/better-circuit-api to main September 19, 2023 09:29
aborgna-q added a commit that referenced this pull request Sep 19, 2023
- 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]>
@aborgna-q
Copy link
Collaborator Author

#96 is now merged, so this PR is ready for reviews.

@aborgna-q aborgna-q requested a review from croyzor September 19, 2023 09:42
/// 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)
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

// Initialize the map assigning linear units to the input's linear
// ports.
let wire_unit = circ
.units()
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

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

@aborgna-q
Copy link
Collaborator Author

I'll merge this and add an issue for better combinators to alter the Units output.

@aborgna-q aborgna-q requested a review from croyzor September 20, 2023 14:13
@aborgna-q aborgna-q merged commit a5071a7 into main Sep 20, 2023
7 checks passed
@aborgna-q aborgna-q deleted the feat/commands-api branch September 20, 2023 15:07
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.

Add the unit's ports/wires to the Command
2 participants