Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Make MaxWidthCellManager work with fixed signals - Issue #97 #135

Conversation

atsupontio
Copy link

close #97

@leolara Ready for review. I added max_width_fixed and renamed max_width to max_width_advice.

And, I fixed examples/poseidon.rs to use one CompilerConfig.

Please let me know if anything else is required!

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
Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

@atsupontio atsupontio requested a review from leolara September 20, 2023 04:11
@@ -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 {});
Copy link
Collaborator

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

Copy link
Author

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;
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Copy link
Author

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 !

@atsupontio atsupontio requested a review from leolara September 25, 2023 00:50

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 {
Copy link
Collaborator

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()

Copy link
Collaborator

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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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

Copy link
Author

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;

Copy link
Collaborator

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.

Copy link
Author

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();
Copy link
Collaborator

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

Copy link
Collaborator

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 {
Copy link
Collaborator

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.

Copy link
Collaborator

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

@leolara leolara force-pushed the main branch 4 times, most recently from 03ddbb5 to 8397503 Compare November 19, 2023 05:49
@leolara leolara closed this Jul 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make MaxWidthCellManager work with fixed signals
2 participants