-
Notifications
You must be signed in to change notification settings - Fork 217
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
Finalize #334
Finalize #334
Conversation
This fmt issue may have something to do with the Rust version, aka
Because some other versions, and some nightly, have different cargo fmt preferences. |
let me cc @Pratyush and @ValarDragon here for some feedback on the API. |
@@ -149,6 +165,18 @@ impl<F: Field> ConstraintSystem<F> { | |||
self.mode == SynthesisMode::Setup | |||
} | |||
|
|||
/// Check whether this constraint system aims to optimize weight or | |||
/// number of constraints. | |||
pub fn get_optimization_goal(&self) -> OptimizationGoal { |
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.
pub fn get_optimization_goal(&self) -> OptimizationGoal { | |
pub fn optimization_goal(&self) -> OptimizationGoal { |
fn reduce_constraint_weight(&mut self) { | ||
self.outline_lcs(); | ||
} |
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.
We can remove this now, right?
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.
Wasn't the idea to add other weight-reducing optimizations, apart from just outlining? (That's what the comment here says.) In which case we'd still want this as a separate function
pub fn get_optimization_goal(&self) -> OptimizationGoal { | ||
self.inner().map_or(OptimizationGoal::Constraints, |cs| { | ||
cs.borrow().get_optimization_goal() | ||
}) | ||
} |
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.
pub fn get_optimization_goal(&self) -> OptimizationGoal { | |
self.inner().map_or(OptimizationGoal::Constraints, |cs| { | |
cs.borrow().get_optimization_goal() | |
}) | |
} | |
pub fn optimization_goal(&self) -> OptimizationGoal { | |
self.inner().map_or(OptimizationGoal::Constraints, |cs| { | |
cs.borrow().optimization_goal() | |
}) | |
} |
@@ -91,6 +95,16 @@ pub enum SynthesisMode { | |||
}, | |||
} | |||
|
|||
/// Defines the parameter to optimize for a `ConstraintSystem`. | |||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] | |||
pub enum OptimizationGoal { |
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.
Should we have a None
here, which will do no optimization passes?
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.
That makes sense. Do you think None
, or Constraints
, should be the default?
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 think constraints should be the default
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.
What are the semantics of calling finalize with None? In the end we have to get rid of all SymbolicLC before converting to matrices
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 think None
would still need to inline Symbolic LC (self.inline_all_lcs()
, without which to_matrices
would fail.
Dev, what do you think? Basically, at this moment, None
would be the same as Constraints
, and it is uncertain if in the future we will treat them differently.
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 think given that no specific use cases pop up for None
, and we currently do not have a good idea of faster inlining (without optimization to reduce constraints), maybe we can omit None
and add it later. Dev, what do you think?
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.
Sounds good to me!
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.
Actually, I do think None
is still useful, in that it could just make far fewer symbolic LC's for memory reduction. E.g. when multiplying by a constant, we don't need to make a new symbolic LC if we don't care about optimizations
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.
And we could have drop semantics to symbolic LC's to remove intermediate variables from the map as soon as they're dropped from memory. It is a significant engineering effort though, so maybe not worth having it now. (Its non breaking to add it later)
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.
That makes sense. Then let us keep None
and, for now, let None
also do inline_all_lcs
. More changes may be coming in the future.
/// (usize, Option<Vec<F>>) | ||
/// The transformer function is given a references of this constraint system | ||
/// (&self), number of times used, and a mutable reference of the linear | ||
/// combination to be transformed. (&ConstraintSystem<F>, usize, |
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.
Were these comments re-ordered by a linter? Its kinda weird imo that the tuple is split across a new line
It seems that all the comments have been resolved, with this one needing more discussion: whether or not to keep this function
Since this function is now Nick, what do you think? |
Yes, that makes sense! |
Let me cc @Pratyush and @ValarDragon for a final pass |
I left a comment about None |
Based on the discussion above, I think we will keep |
Checks pass :) Pratyush and Dev, if it looks good, feel free to merge or do some final edits. |
One more: we need to export OptimizationGoal here: https://github.com/npwardberkeley/snark/blob/finalize/relations/src/r1cs/mod.rs#L21 Otherwise, Marlin could not find it. |
add one to enforce that
(sorry to bother Nick---I could add them if you add me as a PR repo's writer) |
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 final changes have been applied. Going to merge and updating Marlin then.
Initial attempt to resolve #333