-
Notifications
You must be signed in to change notification settings - Fork 101
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
Manual Bus Witgen: Output folded columns only if they exist #2428
Conversation
.iter() | ||
.zip_eq(folded) | ||
.filter_map(|(expr, column)| match expr { | ||
AlgebraicExpression::Reference(col_reference) if col_reference.is_witness() => { |
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.
From the is_witness
function, it looks like there are Committed
, Constant
, and Intermediate
enums for PolynomialType
. If the folded column has been "optimized away" as you mentioned, will it become Intermediate
and thus filtered away?
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!
pub fn generate(&self) -> Vec<(String, Vec<T>)> { | ||
let accumulators = self | ||
let mut columns = self | ||
.bus_interactions | ||
.par_iter() | ||
.flat_map(|bus_interaction| self.interaction_columns(bus_interaction)) | ||
.collect::<Vec<_>>(); | ||
.flat_map(|bus_interaction| { | ||
let (folded, acc) = self.interaction_columns(bus_interaction); | ||
collect_folded_columns(bus_interaction, folded) | ||
.chain(collect_acc_columns(bus_interaction, acc)) | ||
.collect::<Vec<_>>() | ||
}) | ||
.collect::<BTreeMap<_, _>>(); | ||
|
||
self.pil | ||
.committed_polys_in_source_order() | ||
.filter(|(symbol, _)| symbol.stage == Some(1)) | ||
.flat_map(|(symbol, _)| symbol.array_elements().map(|(name, _)| name)) | ||
.zip_eq(accumulators) | ||
.flat_map(|(symbol, _)| symbol.array_elements()) | ||
.map(|(name, poly_id)| (name, columns.remove(&poly_id).unwrap())) | ||
.collect() | ||
} |
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.
Looks like the key of this PR is on this function. We first generate the witness values which filters out columns that are already optimized away. Then, we find the intersection between these witness columns and stage 1 columns. I just wonder why we need this "stage 1" step. Are all accumulator and folded columns "stage 1" in our protocol?
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.
Yeah, this code makes the assumption that (1) the folded and accumulator columns are in stage 1 (they couldn't be in stage 0, as they depend on a challenge, and we never use higher stages) and (2) that all stage-1 columns are either folded or acc columns (otherwise the remove(...).unwrap()
would fail). Actually, let me improve the panic messages in both cases.
I think you mentioned it in some other PR, but multiple bus interactions can use the same accumulator. Is it already supported in this PR? It looks like |
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.
Left some comments but LGTM :)
No, but that's the plan for the next step ;) The idea is that you can mention the same accumulator columns in multiple bus interactions, and they just get added. Right now, this would fail, because we're collecting all |
cb0ebfb
to
5e0443f
Compare
Depends on #2427 (because otherwise a referenced column might be removed by the optimizer). This PR is completely analogous to #2412: We add a list of expressions that evaluate to the folded payload to `PhantomBusInteraction`. This lets us easily find the referenced columns in the manual bus witgen, see #2428.
The base branch was changed.
Because I'm encountering a similar issue when testing with According to this chunk Lines 52 to 56 in e77d380
materialize_folded = false means hand written witgen isn't triggered, but here we should be testing hand-written witgen? Am I missing something?
|
559a7fb
to
c13ccbc
Compare
Rebased! |
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.
lgtm :)
After your comments to my other PR, this comment is partially stale, but there's still the question on what this comment means: Lines 52 to 56 in e77d380
Does changing |
Manual witgen (which only exists for performance reasons, BTW) currently runs on all fields except BN254 that use bus interactions: powdr/executor/src/witgen/mod.rs Lines 112 to 137 in 2215b9e
Hopefully, with automatic witgen becoming faster and the number of bus interactions becoming fewer, we can remove this path again entirely soon :) It also shouldn't be too complicated to make it work for BN254 as well if needed. But to answer your question, if I set |
) Depends on #2428 and implements the second bullet point from #2337 (comment). **Test Coverage** Not sure why CI isn't running but currently `static_bus_multi.asm` passes test with `cargo run pil test_data/asm/static_bus_multi.asm --force --linker-mode bus --prove-with mock --field bn254` but NOT if `--field gl` with all else equal. See bottom for error from `--field gl`, which are obviously field extension constraints not passing for `folded` columns. **Questions** 1. Probably the biggest problem is with the degree-3 bound of Plonky3. The non batched version already has a degree of 3 (https://github.com/powdr-labs/powdr/blob/main/std/protocols/bus.asm#L86-L89). Therefore, this batched version has a degree of 4 and therefore doesn't work with Plonky3. The degree bound issue is also mentioned in #2337. 2. This comment (https://github.com/powdr-labs/powdr/blob/main/std/protocols/bus.asm#L52-L56) seems to say that `--field bn254` uses auto witgen and therefore manual witgen (which I'm trying to test here) isn't working. 3. According to this chunk (https://github.com/powdr-labs/powdr/blob/main/std/protocols/bus.asm#L60-L69) Does `--field bn254` correspond to no constraints for line 65 or whatsoever? With `--field bn254`, it seems that the accumulator adds up the folded columns but there's no constraint that the folded columns are correctly calculated from payload, id, and challenges. Am I missing something? (I think this might also explain why my `--field bn254` test has no constraint errors for `folded` columns, because they don't exist?) 4. I checked the following constraint errors against our field extension APIs and seems that `mul_ext`, `finger_print_inter_with_id`, `add_ext`, and `constrain_eq_ext` etc. are applied correctly. Any insights on whether `mock` works with `gl` and/or field extensions to start with? I still have a last resort of simply hand computing the values from the error below to see why it's not working with field extension... ``` ➜ powdr git:(bus-multi-interaction) ✗ cargo run pil test_data/asm/static_bus_multi.asm --force --linker-mode bus --prove-with mock --field gl [00:00:05 (ETA: 00:00:00)] ████████████████████ 100% - Starting... Witness generation took 5.538085s Writing ./commits.bin. Backend setup for mock... Setup took 0.0644265s Generating later-stage witnesses took 0.00s Machine main has 64 errors Error: Identity fails on row 0: main::folded_0 = std::prelude::challenge(0, 5) - (123 + (std::prelude::challenge(0, 1) * main::intermediate_fingerprint_0_2 + 11 * std::prelude::challenge(0, 2) * main::intermediate_fingerprint_1_2)); main::intermediate_fingerprint_0_2 = 16683533738167355631 main::intermediate_fingerprint_1_2 = 8619433688316392780 main::folded_0 = 14379784368020248175 std::prelude::challenge(0, 1) = 2206609067086327257 std::prelude::challenge(0, 2) = 11876854719037224982 std::prelude::challenge(0, 5) = 15794382300316794652 Error: Identity fails on row 0: main::folded_0_1 = std::prelude::challenge(0, 6) - (std::prelude::challenge(0, 2) * main::intermediate_fingerprint_0_2 + std::prelude::challenge(0, 1) * main::intermediate_fingerprint_1_2); main::intermediate_fingerprint_0_2 = 16683533738167355631 main::intermediate_fingerprint_1_2 = 8619433688316392780 main::folded_0_1 = 3590326197943317962 std::prelude::challenge(0, 1) = 2206609067086327257 std::prelude::challenge(0, 2) = 11876854719037224982 std::prelude::challenge(0, 6) = 18147521187885925800 Error: Identity fails on row 0: main::folded_1 = std::prelude::challenge(0, 7) - (456 + (std::prelude::challenge(0, 3) * main::intermediate_fingerprint_0_5 + 11 * std::prelude::challenge(0, 4) * main::intermediate_fingerprint_1_5)); main::intermediate_fingerprint_0_5 = 9393166848595961660 main::intermediate_fingerprint_1_5 = 14353807143801496692 main::folded_1 = 4794846700896775308 std::prelude::challenge(0, 3) = 18270091135093349626 std::prelude::challenge(0, 4) = 6185506036438099345 std::prelude::challenge(0, 7) = 7364705619221056123 Error: Identity fails on row 0: main::folded_1_1 = std::prelude::challenge(0, 8) - (std::prelude::challenge(0, 4) * main::intermediate_fingerprint_0_5 + std::prelude::challenge(0, 3) * main::intermediate_fingerprint_1_5); main::intermediate_fingerprint_0_5 = 9393166848595961660 main::intermediate_fingerprint_1_5 = 14353807143801496692 main::folded_1_1 = 16858051030421639712 std::prelude::challenge(0, 3) = 18270091135093349626 std::prelude::challenge(0, 4) = 6185506036438099345 std::prelude::challenge(0, 8) = 2404222719611925354 Error: Identity fails on row 0: main::folded_0_2 = std::prelude::challenge(0, 5) - (456 + (std::prelude::challenge(0, 1) * main::intermediate_fingerprint_0_8 + 11 * std::prelude::challenge(0, 2) * main::intermediate_fingerprint_1_8)); main::intermediate_fingerprint_0_8 = 16683533738167355631 main::intermediate_fingerprint_1_8 = 8619433688316392780 main::folded_0_2 = 14379784368020247842 std::prelude::challenge(0, 1) = 2206609067086327257 std::prelude::challenge(0, 2) = 11876854719037224982 std::prelude::challenge(0, 5) = 15794382300316794652 ... and 59 more errors ```
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 tofalse
, e.g. here and running:This used to fail before this PR.