-
Notifications
You must be signed in to change notification settings - Fork 523
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
Add a Constraints
helper
#414
Conversation
Codecov Report
@@ Coverage Diff @@
## main #414 +/- ##
==========================================
- Coverage 70.19% 70.09% -0.11%
==========================================
Files 42 42
Lines 5208 5216 +8
==========================================
Hits 3656 3656
- Misses 1552 1560 +8
Continue to review full report at Codecov.
|
34912cf
to
b73429a
Compare
a058ffd
to
12d729a
Compare
12d729a
to
634e1ec
Compare
634e1ec
to
82a5b61
Compare
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.
utACK
82a5b61
to
a12935b
Compare
Rebased to fix a doctest that wasn't updated for the workspace refactor, and add a changelog entry. |
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.
utACK
There are two existing patterns for constructing a gate from a set of constraints with a common selector: - Create an iterator of constraints, where each constraint includes the selector: ``` vec![ ("foo", selector.clone() * foo), ("bar", selector.clone() * bar), ("baz", selector * bar), ] ``` This requires the user to write O(n) `selector.clone()` calls. - Create an iterator of constraints, and then map the selector in: ``` vec![ ("foo", foo), ("bar", bar), ("baz", bar), ].into_iter().map(move |(name, poly)| (name, selector.clone() * poly)) ``` This looks cleaner overall, but the API is not as intuitive, and it is messier when the constraints are named. The `Constraints` struct provides a third, clearer API: ``` Constraints::with_selector( selector, vec![ ("foo", foo), ("bar", bar), ("baz", bar), ], ) ``` This focuses on the structure of the constraints, and handles the selector application for the user.
a12935b
to
d93846f
Compare
Rebased to fix a merge conflict in the |
There are two existing patterns for constructing a gate from a set of
constraints with a common selector:
Create an iterator of constraints, where each constraint includes the
selector:
This requires the user to write O(n)
selector.clone()
calls.Create an iterator of constraints, and then map the selector in:
This looks cleaner overall, but the API is not as intuitive, and it
is messier when the constraints are named.
The
Constraints
struct provides a third, clearer API:This focuses on the structure of the constraints, and handles the
selector application for the user.