-
Notifications
You must be signed in to change notification settings - Fork 39
Conversation
Please constants at the bottom if python allows it, even better if the constants can be in another file. |
Putting at bottom won't work, event with |
src/frontend/python/chiquito/dsl.py
Outdated
raise ValueError( | ||
"Must set num_steps by calling pragma_num_steps() in setup before calling fixed_gen()." | ||
) | ||
self.fixed_gen_context = FixedGenContext.new(self.ast.num_steps) |
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.
@qwang98 I don't think we need the class FixedGenContext anymore, we could keep the assignations array in this class
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.
Agreed. I kept fixed_assignments in AST as we did in Rust, and added AST function that modifies it. DSL calls this AST function.
Addressed Leo's comments. Now still runs successfully on mimc7 example. Ready for review again. @leolara New Python package version published as 2023090100 |
src/ast/mod.rs
Outdated
} | ||
|
||
impl<F: Field + Hash, TraceArgs> Circuit<F, TraceArgs> { | ||
pub fn set_fixed_assignments<D>(&mut self, def: D) |
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.
The name of the function suggest that you are just setting something but it runs the lambda with a context. I think running the lambda with the context is better done in dsl and here just a setter.
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.
Resolved!
src/frontend/python/chiquito/cb.py
Outdated
return self | ||
|
||
def build(self: LookupTableBuilder, step_type: StepType) -> Lookup: | ||
table = step_type.tables.get(self.id) |
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.
Why the table has to be stored in the step?
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 Rust Chiquito, table is initially built using new_table
from DSL and stored in CircuitContext
. It's then cloned to StepTypeContext
and StepTypeSetupContext
. Because build
is called by add_lookup
, a StepTypeSetupContext
function, build
conveniently takes a ctx: StepTypeSetupContext
parameter. Therefore, table doesn't "have to be" stored in the step, but it's just the most convenient for build
to have the step_type
parameter, as add_lookup
calls build
at the step type level.
In Python, add_lookup
also calls build
at the step type level, and that's why we have the step_type
parameter here. The tables are initially created and stored at the circuit level, but step type and super circuit can also have references to the tables.
sorry, I had comments but I didn't submit them |
Ready for review again. @leolara |
src/ast/mod.rs
Outdated
pub fn get_step_type(&self, uuid: UUID) -> Rc<StepType<F>> { | ||
let step_rc = self.step_types.get(&uuid).expect("step type not found"); | ||
|
||
Rc::clone(step_rc) | ||
} | ||
} | ||
|
||
impl<F: Field + Hash, TraceArgs> Circuit<F, TraceArgs> { | ||
pub fn set_fixed_assignments(&mut self, assignments: Option<FixedAssignment<F>>) { |
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.
@qwang98 why is the parameter an option? Would you call it with None?
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.
Fixed!
src/frontend/python/chiquito/cb.py
Outdated
|
||
|
||
@dataclass | ||
class LookupTableRegistry: |
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.
@qwang98 I don't think we need a LookupTableRegistry, this was necessary in rust to have the Copy
constraint, but in python the table is a reference.
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.
Removed and fixed!
|
||
|
||
@dataclass | ||
class LookupTable: |
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.
@qwang98 when a table is created, it should be close to add more expresions to dest. So perhaps there is a method create() that returns self and sets a flag that prevents from adding more things to dest. Also, the table cannot be used if this flag has not been activated by call to create()
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.
I believe this create()
function you mentioned is actually new_table()
in dsl.py
. Rust Chiquito has the same naming.
I modified LookupTable
such that now we have a new read_only
flag, that defaults to False
when LookupTable
is just created. User can then call add()
to add more destination columns to the LookupTable
, which requires that read_only == False
.
LookupTable
will then need to be added by new_table()
in dsl.py
to the dictionary of UUID to LookupTable
. new_table()
also changes the read_only
flag to True
, so that no more calls of add()
to modify the destination column is possible after new_table()
is called.
Finally, any use of the table will be through apply()
and when()
, both of which requires that read_only == True
.
This should accomplish all the features you suggested above.
What's more? create_table()
can only be called during setup()
and there's a flag assertion for that as well.
Everything fixed and ready for review again. @leolara |
All contents will be PR'ed through #125 instead. Closing this. |
Ready for review @leolara.
Changes Related to Fixed Gen
Mimc7 example works for the mimc7_constants circuit