-
Notifications
You must be signed in to change notification settings - Fork 39
Make MaxWidthCellManager work with fixed signals - Issue #97 #135
Make MaxWidthCellManager work with fixed signals - Issue #97 #135
Conversation
same_height, | ||
} | ||
} | ||
} | ||
|
||
impl CellManager for MaxWidthCellManager { | ||
fn place<F>(&self, unit: &mut CompilationUnit<F>) { | ||
if (!unit.shared_signals.is_empty() || !unit.fixed_signals.is_empty()) && !self.same_height | ||
if (!unit.shared_signals.is_empty()) && !self.same_height |
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.
@atsupontio this must be kept. Fixed signals should not work when same_height is disabled
let mut fixed_signal_row: usize = 0; | ||
|
||
for fixed_signal in unit.fixed_signals.iter() { | ||
let column = if placement.columns.len() <= fixed_signal_column { |
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.
@atsupontio you should add some tests, this will not work. Because placement.columns contains both advice and fixed signals, if there are both, for example when fixed_signal_column == 0
but there are already columns that are advice the fixed column will not be created and the wrong column will be picked up
} | ||
} | ||
|
||
placement.base_height = if fixed_signal_column != 0 { |
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.
@atsupontio what if there is more rows in the advice than in the fixed?
examples/poseidon.rs
Outdated
@@ -661,25 +661,22 @@ fn poseidon_super_circuit<F: PrimeField + Eq + Hash>( | |||
lens: Lens, | |||
) -> SuperCircuit<F, ValuesAndLens<F>> { | |||
super_circuit::<F, ValuesAndLens<F>, _>("poseidon", |ctx| { | |||
let single_config = config(SingleRowCellManager {}, SimpleStepSelectorBuilder {}); | |||
let config = config(MaxWidthCellManager::new(2, 2, true), SimpleStepSelectorBuilder {}); |
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.
@atsupontio I think it would be better if run the example with both Cell Managers
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.
@leolara Thank you!
I'll fix it!
|
||
let mut fixed_signal_column: usize = 0; | ||
let mut fixed_signal_row: usize = 0; | ||
let mut column_pos = self.max_width_advice + fixed_signal_column; |
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.
@atsupontio we might not have used all the max_width_advice columns, for example max_width_advice can be 3, but there be only 2 forwards.
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.
perhaps column pos is equivalent to the (number of actual advice columns inserted (placement.columns.len() before adding fixed columns)) + fixed_signal_column; so this variable is not needed.
I think the cleaner solution is:
Be adding for advice and fixed, the columns to different arrays, and after all have been added then merge both arrays into placement.columns.
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.
@leolara Thanks for your great advice and ideas !
|
||
for forward_signal in unit.forward_signals.iter() { | ||
let column = if placement.columns.len() <= forward_signal_column { | ||
let column = if placement.forward.len() <= forward_signal_column { |
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.
@atsupontio you are comparing signals with columns here, the left side should be forward_columns.len()
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.
advice_columns.len()
|
||
|
||
for fixed_signal in unit.fixed_signals.iter() { | ||
let column = if placement.fixed.len() <= fixed_signal_column { |
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.
@atsupontio the left side should be fixed_columns.len()
} | ||
} | ||
|
||
placement.base_height = if fixed_signal_row > forward_signal_row { |
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.
@atsupontio you can assign to a new variable max of fixed_signal_row, forward_signal_row and use the result in one expression
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.
@leolara Thank you for your comment!
Is it possible to represent it concisely with the following code?
let mut max_row = std::cmp::max(fixed_signal_row, forward_signal_row);
placement.base_height = if (fixed_signal_column != 0 && forward_signal_column != 0) {
max_row as u32 + 1
} else {
max_row as u32
};
placement.base_height = max_row;
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 that code, you are setting max_row as mut, but you are not mutating it, also you are setting placement.base_height twice. Also, why are you checking both things for zero? If both are zero, max_row will be zero.
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.
@leolara Since we don't know whether fixed_signal_row
or forward_signal_row
will be assigned to max_row
, we need to check both xx_signal_column
, don't we?
The xx_signal_column
could be 0 even if the xx_signal_row
is not 0.
@@ -262,20 +264,21 @@ impl CellManager for MaxWidthCellManager { | |||
|
|||
let mut forward_signal_column: usize = 0; | |||
let mut forward_signal_row: usize = 0; | |||
let mut forward_columns: Vec<Column> = Vec::new(); |
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.
@atsupontio actually these are advice_colums, not forward_columns
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.
Advice columns, are shared by forward, shared and internal signals
|
||
// forward signals: a, b; step1 internal: c1, d, e; step2 internal c2 | ||
|
||
let cm = MaxWidthCellManager { |
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.
@atsupontio you should this test with different combinations of max_width_advice and max_width_fixed.
Including corner cases, like 0 and 1.
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.
If there are some repetation in the code use helper functions in the test module
03ddbb5
to
8397503
Compare
close #97
@leolara Ready for review. I added
max_width_fixed
and renamedmax_width
tomax_width_advice
.And, I fixed
examples/poseidon.rs
to use oneCompilerConfig
.Please let me know if anything else is required!