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

Add a Constraints helper #414

Merged
merged 2 commits into from
Apr 22, 2022
Merged

Add a Constraints helper #414

merged 2 commits into from
Apr 22, 2022

Conversation

str4d
Copy link
Contributor

@str4d str4d commented Dec 3, 2021

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.

@codecov-commenter
Copy link

codecov-commenter commented Dec 3, 2021

Codecov Report

Merging #414 (b73429a) into main (0295dc7) will decrease coverage by 0.10%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
src/plonk/circuit.rs 58.17% <0.00%> (-0.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0295dc7...b73429a. Read the comment docs.

@str4d str4d force-pushed the constraints-helper branch from 34912cf to b73429a Compare December 3, 2021 13:14
@str4d str4d force-pushed the constraints-helper branch 2 times, most recently from a058ffd to 12d729a Compare January 21, 2022 13:56
@str4d str4d force-pushed the constraints-helper branch from 12d729a to 634e1ec Compare February 1, 2022 16:22
@str4d str4d added A-dev-tooling Area: Developer tooling A-rust-api Area: Public crate API and removed A-dev-tooling Area: Developer tooling labels Mar 9, 2022
@str4d str4d force-pushed the constraints-helper branch from 634e1ec to 82a5b61 Compare March 17, 2022 19:22
Copy link
Collaborator

@therealyingtong therealyingtong left a comment

Choose a reason for hiding this comment

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

utACK

@str4d str4d force-pushed the constraints-helper branch from 82a5b61 to a12935b Compare April 18, 2022 11:13
@str4d
Copy link
Contributor Author

str4d commented Apr 18, 2022

Rebased to fix a doctest that wasn't updated for the workspace refactor, and add a changelog entry.

Copy link
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK

str4d added 2 commits April 20, 2022 10:55
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.
@str4d str4d force-pushed the constraints-helper branch from a12935b to d93846f Compare April 20, 2022 10:56
@str4d
Copy link
Contributor Author

str4d commented Apr 20, 2022

Rebased to fix a merge conflict in the halo2_proofs changelog.

@str4d str4d merged commit 66b2b3b into main Apr 22, 2022
@str4d str4d deleted the constraints-helper branch April 22, 2022 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust-api Area: Public crate API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants