-
Notifications
You must be signed in to change notification settings - Fork 116
Optimizer Documentation: Terminology #3350
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
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: Thibaut Schaeffer <[email protected]>
a superset of the set of allowed values. This means we can only use | ||
the information if the Range Constraints says that a value is not | ||
allowed. This also makes sense since we are looking at Algebraic |
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.
I find this part a bit vague.
A _Wrapping Interval_ is a pair of field elements `min` and `max`. | ||
If `min <= max` (as seen in the natural numbers), the Wrapping | ||
Interval allows a value `x` if and only if `min <= x <= max`. | ||
This is the non-wrapping case. | ||
If `min > max`, the Wrapping Interval allows a value `x` | ||
if and only if `x >= min` or `x <= max`. This is the wrapping case. | ||
|
||
The reason we allow these wrapping intervals is that we can compute | ||
the Range Constraint interval of an expression `x + k` for any constant `k` | ||
from the Range Constraint interval of `x` without losing information. |
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 wrapping and non-wrapping intervals ever interact? I see the argument that you can define addition (and multiplication?) on intervals in a unified way, but I'm not sure it's worth it given the non-intuitive aspect of min > max
being okay. Would it be possible to use an enum enum Interval { Inside { min, max }, Outside { min, max }
and define addition and multiplication on that instead?
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.
Sure, it could be done that way, but then you would need to verify in addition that min <= max
is always ensured.
Another way we could do it is just to have first
and length
, and a value x
is in range if it included in the sequence first, first + 1, first + 2, ..., first + length
(and if length = 0
, we would be able to model the empty range, which we cannot do currently).
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.
Yes, first and length sound good
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.
I just checked and I think it's at least 2-3 days work to change it, if not a week. I'll focus on documenting for now.
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.
Thanks for checking!
lookup tables are not stateful. | ||
|
||
- `handle_bus_interaction`: Takes a Bus Interaction where its items are represented | ||
by Range Constraints instead of expressions or field elements and returns |
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.
What does or
apply to here?
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.
I can remove or field elements
if it creates confusion instead of clarifying things ;)
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.
yea I guess instead of expressions
suffices
parts of the system. A simple (and also best possible) implementation of | ||
`handle_bus_interaction` would be to always return the `0xff`-mask Range Constraint | ||
for the payload and ignore the input. Even if the input Range Constraint is something | ||
like `200..=300`, the solver will combine the two Range Constraints and derive | ||
`200..=255` as the new Range Constraint for the payload. |
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.
Why is 0xff the best implementation? Isn't it the one that mixes the input constraint with the bus constraint? Seems like this part mixes the naive implementation and what we do?
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.
I don't really understand what you mean. Of course this document does not say what a "good" implementation is, so we cannot tell if it is the best possible. What implementation would you say is better and why? What do you mean by "naive implementation" and what do we do?
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.
I think he's referring to the beginning of the par which does say (and also best possible)
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.
I mean that the first part of this section talks about one strategy of always returning 0xff, while the second talks about combining range constraints.
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.
Oh maybe the word 'input' is confusing?
Since our Range Constraints do not model individual bits well enough, it is sufficient | ||
to only compute the third item if two of them are fully known. |
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.
i don't understand this
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.
I think the "it is sufficient" part here is what sounds a bit odd to me. Sufficient for what? From the text before it sounds like it's rather not sufficient for a full analysis.
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.
really good introduction
Co-authored-by: Thibaut Schaeffer <[email protected]>
Co-authored-by: Thibaut Schaeffer <[email protected]>
Co-authored-by: Thibaut Schaeffer <[email protected]>
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.
First pass, need to continue from Bus Interaction Abstraction
The task of the optimizer is hugely simplified by the concept of | ||
_Range Constraints_. In an abstract way, a _Range Constraint_ is | ||
the set of possible values for a specific algebraic expression. | ||
The solver can derive new Range Constraints from Algebraic Constraints |
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.
This is the first time solver
is used, it'd be good to refer to something or define it.
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.
Changed it to optimizer
|
||
In our concrete implementation, we do not represent the exact set | ||
of allowed values. Instead, we use an under-approximation, i.e. | ||
a superset of the set of allowed values. This means we can only use |
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.
That would be an overapproximation, no?
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.
True!
In our concrete implementation, we do not represent the exact set | ||
of allowed values. Instead, we use an under-approximation, i.e. | ||
a superset of the set of allowed values. This means we can only use | ||
the information if the Range Constraints says that a value is not |
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.
I think I do understand this part, but what's unclear here is "use for what"?
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.
Clarified
We use `RC(x)` to denote the Range Constraint of an algebraic | ||
expression `x`. | ||
|
||
TODO It is not clear if this is the currently best-known range constraint, |
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.
TODO as in for this PR or the future?
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.
Removed
semantics of a bus interaction depends on the environment, i.e. the | ||
zkVM we are operating inside and the chips it has. | ||
|
||
A _Bus Interaction_ consists of a _Bus ID_, a _Multiplicity_ and |
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.
Maybe it makes sense to introduce it as a relation or predicate here? I think that could help abstract it
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.
Can you give an example?
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.
Done now.
lookup tables are not stateful. | ||
|
||
- `handle_bus_interaction`: Takes a Bus Interaction where its items are represented | ||
by Range Constraints instead of expressions or field elements and returns |
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.
yea I guess instead of expressions
suffices
|
||
As an example, let us assume we are modeling a bus that implements a byte range | ||
constraint, i.e. a bus that takes a single payload item and enforces that it is | ||
in the range `0..=255`. The bus is not stateful since it does not depend on any |
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.
in the range `0..=255`. The bus is not stateful since it does not depend on any | |
in the range `0..=255`. The bus is not stateful since it does not depend on nor affects any |
parts of the system. A simple (and also best possible) implementation of | ||
`handle_bus_interaction` would be to always return the `0xff`-mask Range Constraint | ||
for the payload and ignore the input. Even if the input Range Constraint is something | ||
like `200..=300`, the solver will combine the two Range Constraints and derive |
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.
solver
also undefined up to here
parts of the system. A simple (and also best possible) implementation of | ||
`handle_bus_interaction` would be to always return the `0xff`-mask Range Constraint | ||
for the payload and ignore the input. Even if the input Range Constraint is something | ||
like `200..=300`, the solver will combine the two Range Constraints and derive | ||
`200..=255` as the new Range Constraint for the payload. |
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.
I think he's referring to the beginning of the par which does say (and also best possible)
Another example would be an XOR-bus that takes three payload items `a, b, c` | ||
and ensures that all of them are bytes and `a ^ b = c`. This bus is also not stateful. | ||
Here, one would implement `handle_bus_interaction` by returning the three byte constraints | ||
for the payload items if the input has no restrictiens. But if the value of the same bit |
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.
for the payload items if the input has no restrictiens. But if the value of the same bit | |
for the payload items if the input has no restrictions. But if the value of the same bit |
Since our Range Constraints do not model individual bits well enough, it is sufficient | ||
to only compute the third item if two of them are fully known. |
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.
I think the "it is sufficient" part here is what sounds a bit odd to me. Sufficient for what? From the text before it sounds like it's rather not sufficient for a full analysis.
- exhaustive search | ||
- equal zero check | ||
|
||
### Constraint System Solver |
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.
Maybe this section could be moved to the top to clarify what the instances of solver
above mean.
…/powdr into optimizer_documentation
Co-authored-by: Leo <[email protected]>
…/powdr into optimizer_documentation
No description provided.