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

Witness generation for block machines connected via permutations #1075

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ast/src/analyzed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ impl<T> Identity<AlgebraicExpression<T>> {
}
}

#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Serialize, Deserialize, JsonSchema)]
#[derive(
Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Serialize, Deserialize, JsonSchema,
)]
pub enum IdentityKind {
Polynomial,
Plookup,
Expand Down
10 changes: 10 additions & 0 deletions executor/src/witgen/block_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> BlockProcessor<'a, 'b, 'c
}
}

pub fn from_processor(
processor: Processor<'a, 'b, 'c, T, Q>,
identities: &'c [&'a Identity<Expression<T>>],
) -> Self {
Self {
processor,
identities,
}
}

pub fn with_outer_query(
self,
outer_query: OuterQuery<'a, T>,
Expand Down
12 changes: 9 additions & 3 deletions executor/src/witgen/identity_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use powdr_ast::{
};
use powdr_number::FieldElement;

use crate::witgen::machines::Machine;
use crate::witgen::{machines::Machine, EvalError};

use super::{
affine_expression::AffineExpression, machines::KnownMachine, rows::RowPair, EvalResult,
Expand Down Expand Up @@ -205,8 +205,14 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> IdentityProcessor<'a, 'b,
let selector_value = right
.selector
.as_ref()
.map(|s| current_rows.evaluate(s).unwrap().constant_value().unwrap())
.unwrap_or(T::one());
.map(|s| {
current_rows
.evaluate(s)
.ok()
.and_then(|affine_expression| affine_expression.constant_value())
.ok_or(EvalError::Generic("Selector is not 1!".to_string()))
})
.unwrap_or(Ok(T::one()))?;
Comment on lines +208 to +215
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turns a panic into an error. This happens in the block_lookup_or_permutation test:

  • A block is computed by a permutation using selector2
  • A loop is detected
  • When checking the next identity using selector1, process_link() on the last row. But selector1 is unknown at this point.
  • The error is caught by the loop detection code and the executor reverts to the normal solving algorithm.

assert_eq!(selector_value, T::one());

let mut updates = EvalValue::complete(vec![]);
Expand Down
Loading
Loading