Commit Graph

120 Commits

Author SHA1 Message Date
Georg Wiese
ff0fa46dc9 Apply In-liner to bus interactions as well (#2696)
Builds on #2695

In the in-liner, we black-listed any variables that appear in bus
interactions. I don't think this is necessary, and it prevents some
optimizations. But maybe I'm overlooking something. This has also been
[discussed in a previous
PR](https://github.com/powdr-labs/powdr/pull/2677#discussion_r2075080921).
2025-05-09 09:13:13 +00:00
Steve Wang
b6c6e54731 Apc remove all constant lookups (#2682)
Ready for a preliminary review. I'm not sure if CI will pass.

This is required for
https://github.com/powdr-labs/powdr-openvm/pull/101.

---------

Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-05-07 14:55:09 +00:00
chriseth
06b5d4f605 Restrict access to the constraint system. (#2690)
This is the first step in allowing some optimizations, for example to
store a lookup table for the occurrences of variables and only
substituting in those constraints or keeping a queue of modified
constraints.
2025-05-07 11:19:29 +00:00
chriseth
fa5566891a Autoprecompiles clean v1 (#2686)
Co-authored-by: Leo Alt <leo@powdrlabs.com>
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-05-07 07:35:02 +00:00
chriseth
eacaf82a3c Structure solver a bit. (#2687) 2025-05-06 16:18:05 +00:00
chriseth
68c7f7d125 Some small changes to "substitute_by_unknown". (#2685) 2025-05-06 15:15:49 +00:00
Gastón Zanitti
a4c500164c QSE: substitute_by_unknown (#2679)
Implementation of substitute_by_unknown & tests
2025-05-06 09:06:00 +00:00
chriseth
c5b987bcd3 Qse-based optimizer (#2643)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-04-29 14:58:57 +00:00
Georg Wiese
252c646303 BusInteractionHandler: Remove associated type (final2) (#2676)
@chriseth [was
right](https://github.com/powdr-labs/powdr/pull/2674#pullrequestreview-2802939786),
we can turn an associated type into a type parameter.

I think the reason it was an associated type was something related to
object safety in a previous version.
2025-04-29 14:57:15 +00:00
Georg Wiese
051efc87a0 BusInteractionHandler: Remove associated type (#2674)
Turns out we don't need `V`.
2025-04-29 10:50:37 +00:00
Georg Wiese
c1d772d3a7 Solver: handle bus interactions (#2663)
Adds bus interactions to the solver. See [this
test](215d04fc8b/constraint-solver/tests/solver.rs (L218-L239))
for an example!

The implementation is as follows:
- There is a new `BusInteraction` type, storing the bus ID, multiplicity
and payload. I also added a wrapper `ConstraintSystem` type, which
contains all algebraic constraints and bus interactions.
- `BusInteractions::solve()` has a similar interface to
`QuadraticSymbolicExpression::solve()`. It does the following steps:
- Converts the bus interaction's fields from expressions to range
constraints.
  - Calls a `BusInteractionHandler` to update the range constraints
- Users of `Solver` can pass a bus interaction handler that knows how to
deal with the constraint system's buses. If none is provided, bus
interactions are ignored by the solver


[This](215d04fc8b/constraint-solver/tests/solver.rs (L121-L174))
is an example of an implementation of `BusInteractionHandler`. In the
future we could:
- Implement one for Powdr VMs, by detecting machine types. This would be
similar to [an implementation of
`Machine::can_process_call_fully`](215d04fc8b/executor/src/witgen/machines/fixed_lookup_machine.rs (L311)).
- Pass a custom implementation to the solver. For example, we might be
using the solver with single chips of a third-party VM. Then, the
handler would have to know how to handle all bus interactions available
to this chip.
2025-04-28 15:26:35 +00:00
chriseth
839a0a8dce Implement substitutions. (#2667)
Replace the mechanism of "variable update" by "substitutions". This has
the benefit that we can substitute a variable also by a more complex
value.

The next step (not this PR) would be to also allow substitution by QSEs,
which we will need if we want to apply equivalences.
2025-04-28 12:26:25 +00:00
chriseth
a88133f3fc Fix udeps. (#2671) 2025-04-28 11:19:41 +00:00
chriseth
24c7e5f0ee Implement range constraints as separate struct. (#2670) 2025-04-26 06:31:24 +00:00
Georg Wiese
e9f4d89daf Solver: Swap conjunction order (#2669)
Applying [Chris'
suggestion](https://github.com/powdr-labs/powdr/pull/2664#issuecomment-2827676136)
to fix an infinite loop in the solver.

I'm not sure how to best reproduce the infinite loop, but [this
modification of a
test](https://github.com/powdr-labs/powdr/pull/2662/files#diff-bfd27fea42d3539a6d0372f55d103dbae51ac96bab39fb1b3aa4a76ef8a512d8)
does a trick. I manually checked that there is no infinite loop anymore,
but it makes the test less pure, so I don't want to commit it.

I think this change makes sense anyway.
2025-04-25 15:20:40 +00:00
Georg Wiese
984e90c38e Add simple solver for arithmetic circuits (#2651)
I tried to implement the simplest possible solver as a starting point
for a solver that we can eventually use to simplify auto-precompiles (by
(1) trying to find concrete variable assignments already and (2) figure
out if two nodes can be computed using the same symbolic expression, and
hence can be collapsed).

I created #2652 to track follow-up work.

---------

Co-authored-by: Thibaut Schaeffer <schaeffer.thibaut@gmail.com>
Co-authored-by: chriseth <chris@ethereum.org>
2025-04-25 11:30:54 +00:00
chriseth
4366ed9d7f Solve some quadratic constraints (#2659)
Co-authored-by: Georg Wiese <georgwiese@gmail.com>
2025-04-24 15:07:40 +00:00
Georg Wiese
cdb599245a QuadraticSymbolicExpression: Detect Bit constraint (#2653)
Adds a quick-and-dirty way to return bit constraints when running
`QuadraticSymbolicExpression::solve()`, by looking for a specific
expression (`X * (X - 1)`). As far as I can see, this is orthogonal to
#2619, which would return a `Branch` effect instead of a range
constraint.

With this PR, we remove the need for "global range constraints". This
will help progressing on the new solver (#2651), which tries to rely
only on `QuadraticSymbolicExpression`. Then, we can have a bit
decomposition example even before implementing machine calls.

---------

Co-authored-by: chriseth <chris@ethereum.org>
2025-04-23 15:12:09 +00:00
chriseth
06b749bd9f Remove ast dependency. (#2660)
Removes the dependency of the constraint solver on the PIL ast
2025-04-23 14:03:56 +00:00
chriseth
8a925cf204 Move constraint analysis (#2642) 2025-04-22 14:44:50 +00:00