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

Linear constraint remover #2425

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Linear constraint remover #2425

wants to merge 14 commits into from

Conversation

Schaeff
Copy link
Collaborator

@Schaeff Schaeff commented Feb 1, 2025

what

Replace certain multilinear constraints* with intermediate polynomials in pilopt.
*with no next references, not touching public inputs

why

This comment highlights a use-case where materialising a column which is only constrained to a non-shifted multilinear polynomial is wasteful. Fixing this when we create the code is tricky, since we cannot know the degree of the constraint from pil. This is however something pilopt can do, which is what we attempt to do here

unknowns

  • Is it okay to do this? A consequence is that col witness x; col witness y; x = 2 * y gets completely optimized away. One argument for is that we already remove x = y entirely.
    - it's fine since we're doing only substitutions
  • What are the consequences on witgen? It seems ok since the colun still "exists" as intermediate, it's just not materialized
    - Witgen works!
  • We have similar optimizers for x = 42 and x = y which are both multilinear expressions. They do no yield intermediate polynomials, since in that case it is fine to "inline" them. This implementation currently makes sure all three optimizer apply to distinct cases, but maybe it would be better to have a single optimizer which handles all three cases, only introducing intermediate polynomials in the non trivial cases (42 and y)

@@ -738,6 +738,30 @@ impl<Ref> From<u32> for Expression<Ref> {
BigUint::from(value).into()
}
}

impl<T: FieldElement> From<AlgebraicExpression<T>> for Expression<Reference> {
Copy link
Member

Choose a reason for hiding this comment

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

There is pil-analyzer/src/epressionizer.rs that does this on a large scale. Maybe call that from pilopt instead of adding this here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I knew we had this somewhere! Thanks! I added this just to make it compile

github-merge-queue bot pushed a commit that referenced this pull request Feb 4, 2025
Depends on #2426.

With this PR, we use the annotations added in #2412 and #2426 to find
the columns being generated. This allows us to detect when the folded
payload is not persisted as a witness column.

The background is that @Schaeff is working on #2425, which would undo
persisting the folded payloads in some cases, allowing us to spend fewer
witness columns per bus interaction. With this PR, this should be fine:
The column type will change from witness to intermediate, which means
that the bus witgen will not output any folded columns.

It can be tested by changing the `materialize_folded` bool to `false`,
e.g.
[here](https://github.com/powdr-labs/powdr/blob/e77d3801c1decff039fd0ec6bbeb55ed734357fb/std/protocols/bus.asm#L48)
and running:
```
cargo run pil test_data/asm/block_to_block.asm \
    -o output -f --linker-mode bus --prove-with mock --field gl
```

This used to fail before this PR.
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.

2 participants